eventplanner_gcal: PEP coding style

This commit is contained in:
Martin Bauer
2019-01-05 13:04:20 +01:00
parent aaf1528426
commit e2c8915321
10 changed files with 243 additions and 232 deletions

View File

@@ -1,63 +1,63 @@
from django.shortcuts import redirect
from eventplanner_gcal.google_sync import syncFromGoogleToLocal, syncFromLocalToGoogle
from django.shortcuts import redirect
from eventplanner_gcal.google_sync import sync_from_google_to_local, sync_from_local_to_google
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from pprint import pformat
from eventplanner_gcal.google_sync import checkIfGoogleCallbackIsValid
from eventplanner_gcal.google_sync import check_if_google_callback_is_valid
from eventplanner_gcal.models import UserGCalCoupling
from django.shortcuts import render
import logging
logger = logging.getLogger( __name__ )
logger = logging.getLogger(__name__)
def runSync( request ):
syncFromLocalToGoogle()
def run_sync(request):
sync_from_local_to_google()
return redirect("/")
def manage( request ):
def manage(request):
if request.method == 'POST':
if request.POST['activate'] == "1":
UserGCalCoupling.objects.filter( user=request.user ).delete()
c = UserGCalCoupling( user=request.user, email = request.POST['email'] )
UserGCalCoupling.objects.filter(user=request.user).delete()
c = UserGCalCoupling(user=request.user, email=request.POST['email'])
c.save()
syncFromLocalToGoogle()
sync_from_local_to_google()
else:
UserGCalCoupling.objects.filter( user=request.user ).delete()
syncFromLocalToGoogle()
UserGCalCoupling.objects.filter(user=request.user).delete()
sync_from_local_to_google()
context = {}
userCoupling = UserGCalCoupling.objects.filter( user = request.user )
context['enabled'] = len(userCoupling)
assert( len(userCoupling) < 2 )
if len(userCoupling) == 1:
context['mail'] = userCoupling[0].email
user_coupling = UserGCalCoupling.objects.filter(user=request.user)
context['enabled'] = len(user_coupling)
assert (len(user_coupling) < 2)
if len(user_coupling) == 1:
context['mail'] = user_coupling[0].email
return render( request, 'eventplanner_gcal/management.html', context )
return render(request, 'eventplanner_gcal/management.html', context)
@csrf_exempt
def gcalApiCallback( request ):
def gcal_api_callback(request):
token = ""
if 'HTTP_X_GOOG_CHANNEL_TOKEN' in request.META: token = request.META['HTTP_X_GOOG_CHANNEL_TOKEN']
channelID = ""
if 'HTTP_X_GOOG_CHANNEL_ID' in request.META: channelID = request.META['HTTP_X_GOOG_CHANNEL_ID']
resourceID = ""
if 'HTTP_X_GOOG_RESOURCE_ID' in request.META: resourceID = request.META['HTTP_X_GOOG_RESOURCE_ID']
if 'HTTP_X_GOOG_CHANNEL_TOKEN' in request.META:
token = request.META['HTTP_X_GOOG_CHANNEL_TOKEN']
valid = checkIfGoogleCallbackIsValid( token, channelID, resourceID)
channel_id = ""
if 'HTTP_X_GOOG_CHANNEL_ID' in request.META:
channel_id = request.META['HTTP_X_GOOG_CHANNEL_ID']
resource_id = ""
if 'HTTP_X_GOOG_RESOURCE_ID' in request.META:
resource_id = request.META['HTTP_X_GOOG_RESOURCE_ID']
valid = check_if_google_callback_is_valid(token, channel_id, resource_id)
if not valid:
return HttpResponse('<h1>Old Channel - no update triggered</h1>')
logger.info( "Received Google Callback with the following headers Token: %s ID %s ResID %s " % ( token, channelID, resourceID ) )
result = syncFromGoogleToLocal()
logger.info("Finished processing callback from GCal - New Information present: %d " %(result, ) )
logger.info("Received Google Callback with the following headers Token: "
"%s ID %s ResID %s " % (token, channel_id, resource_id))
result = sync_from_google_to_local()
logger.info("Finished processing callback from GCal - New Information present: %d " % (result,))
return HttpResponse('<h1>Callback successful</h1>')