diff --git a/blechreiz/calendarCredentials.dat b/blechreiz/calendarCredentials.dat index 4e71385..1ae3261 100644 --- a/blechreiz/calendarCredentials.dat +++ b/blechreiz/calendarCredentials.dat @@ -1 +1 @@ -{"_module": "oauth2client.client", "token_expiry": "2014-04-19T18:37:13Z", "access_token": "ya29.1.AADtN_UNi3N8wJ5AiTZ3ced1ho7-ZOhe9cV0TqJ7lByEy_h5SHGm0EuZBSWVOQ3q3g", "token_uri": "https://accounts.google.com/o/oauth2/token", "invalid": false, "token_response": {"access_token": "ya29.1.AADtN_UNi3N8wJ5AiTZ3ced1ho7-ZOhe9cV0TqJ7lByEy_h5SHGm0EuZBSWVOQ3q3g", "token_type": "Bearer", "expires_in": 3600}, "client_id": "34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com", "id_token": null, "client_secret": "y4t9XBrJdCODPTO5UvtONWWn", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "1/7-6-m_lLAKX8IeD7OuGtkcIiprty_nZUSxhMunSC5b0", "user_agent": null} \ No newline at end of file +{"_module": "oauth2client.client", "token_expiry": "2014-04-20T19:09:26Z", "access_token": "ya29.1.AADtN_VE0fTw3cu2E9SR0XoblR3gXjnON1u2Qy__EB7E6HyEpaDky0LA-SmZVyok6A", "token_uri": "https://accounts.google.com/o/oauth2/token", "invalid": false, "token_response": {"access_token": "ya29.1.AADtN_VE0fTw3cu2E9SR0XoblR3gXjnON1u2Qy__EB7E6HyEpaDky0LA-SmZVyok6A", "token_type": "Bearer", "expires_in": 3600}, "client_id": "34462582242-4kpdvvbi27ajt4u22uitqurpve9o8ipj.apps.googleusercontent.com", "id_token": null, "client_secret": "y4t9XBrJdCODPTO5UvtONWWn", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "1/7-6-m_lLAKX8IeD7OuGtkcIiprty_nZUSxhMunSC5b0", "user_agent": null} \ No newline at end of file diff --git a/blechreiz/settings.py b/blechreiz/settings.py index 137fdd7..5b3f0fd 100644 --- a/blechreiz/settings.py +++ b/blechreiz/settings.py @@ -79,7 +79,7 @@ STATIC_ROOT = PROJECT_PATH + '/static_collection' STATIC_URL = '/static/' LOGIN_URL="/musicians/login" -PUBLIC_URLS=( "^musicians/login/?$", "^musicians/login/usernames/?$") +PUBLIC_URLS=( "^musicians/login/?$", "^musicians/login/usernames/?$", "^eventplanner_gcal/gcalApiCallback*") # Additional locations of static files STATICFILES_DIRS = ( @@ -195,49 +195,29 @@ CRISPY_TEMPLATE_PACK = 'bootstrap' # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. + LOGGING = { 'version': 1, - 'disable_existing_loggers': True, - 'formatters': { - 'standard': { - 'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s", - 'datefmt' : "%d/%b/%Y %H:%M:%S" - }, - }, + 'disable_existing_loggers': False, 'handlers': { - 'null': { - 'level':'DEBUG', - 'class':'django.utils.log.NullHandler', - }, - 'logfile': { - 'level':'DEBUG', - 'class':'logging.handlers.RotatingFileHandler', - 'filename': PROJECT_PATH + "/logfile", - 'maxBytes': 50000, - 'backupCount': 2, - 'formatter': 'standard', - }, - 'console':{ - 'level':'INFO', - 'class':'logging.StreamHandler', - 'formatter': 'standard' + 'file': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + 'filename': '/srv/test/eventplanner.log', }, }, 'loggers': { - 'django': { - 'handlers':['console'], + 'eventplanner_gcal': { + 'handlers': ['file'], + 'level': 'DEBUG', 'propagate': True, - 'level':'WARN', }, - 'django.db.backends': { - 'handlers': ['console'], + 'eventplanner': { + 'handler': ['file'], 'level': 'DEBUG', - 'propagate': False, - }, - 'musicians': { - 'handlers': ['console', 'logfile'], - 'level': 'DEBUG', - }, - } + 'propagate': True, + } + }, + } diff --git a/blechreiz/wsgi.py b/blechreiz/wsgi.py index 7a60579..aa70e7b 100644 --- a/blechreiz/wsgi.py +++ b/blechreiz/wsgi.py @@ -15,6 +15,13 @@ framework. """ import os +import site +import sys +site.addsitedir('/srv/test/env/lib/python2.7/site-packages') +sys.path.append('/srv/test') + + + # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # if running multiple sites in the same mod_wsgi process. To fix this, use # mod_wsgi daemon mode with each site in its own daemon process, or use diff --git a/eventplanner/models.py b/eventplanner/models.py index 91bbe01..7e52c0c 100644 --- a/eventplanner/models.py +++ b/eventplanner/models.py @@ -132,6 +132,12 @@ class EventParticipation( models.Model ): def get_username(self): return self.user.username + def save( self, *args, **kwargs ): + prev = EventParticipation.objects.get( event = self.event, user = self.user ) + if prev.status != self.status or prev.comment != self.comment: + super(EventParticipation,self).save( *args,**kwargs) + + @staticmethod def hasUserSetParticipationForAllEvents( user ): if not EventParticipation.isMember(user): @@ -177,4 +183,4 @@ class EventParticipation( models.Model ): ) - \ No newline at end of file + diff --git a/eventplanner_gcal/models.py b/eventplanner_gcal/models.py index 3e5676e..29e12c2 100644 --- a/eventplanner_gcal/models.py +++ b/eventplanner_gcal/models.py @@ -282,10 +282,10 @@ def checkGCalSubscription(): global service callbackUrl = settings.GCAL_COUPLING['push_url'] - #timeToLive = 14*24*3600 # how long the channel should be active - #renewBeforeExpiry = 2*24*3600 # duration before expiry when channel is renewed - timeToLive = 60*5 - renewBeforeExpiry = 60*3 + timeToLive = 14*24*3600 # how long the channel should be active + renewBeforeExpiry = 2*24*3600 # duration before expiry when channel is renewed + #timeToLive = 60*5 + #renewBeforeExpiry = 60*3 # Test if a channel already exists for this callbackURL try: @@ -318,4 +318,4 @@ def checkGCalSubscription(): def stopAllGCalSubscriptions(): for dbChannel in GCalPushChannel.objects.all(): print("Stopping %s expiry at %d " % ( dbChannel.id, dbChannel.expiration ) ) - GCalPushChannel.stop( service, dbChannel.toGChannel() ) \ No newline at end of file + GCalPushChannel.stop( service, dbChannel.toGChannel() ) diff --git a/eventplanner_gcal/signals.py b/eventplanner_gcal/signals.py index 1ab599e..5059ebb 100644 --- a/eventplanner_gcal/signals.py +++ b/eventplanner_gcal/signals.py @@ -2,9 +2,11 @@ from django.db.models.signals import post_save,pre_delete from django.dispatch import receiver from eventplanner.models import Event, EventParticipation from django.contrib.auth.models import User - - import eventplanner_gcal.models +import logging + +logger = logging.getLogger( __name__ ) + class SignalLock: def __init__(self): @@ -25,10 +27,21 @@ class SignalLock: signalLock = SignalLock() -@receiver( post_save, sender=User ) -def user_changed( **kwargs ): + +def onGoogleCallback(): if not signalLock.isLocked(): with signalLock: + logger.info( "Sync back from google" ) + eventplanner_gcal.models.syncParticipationFromGoogleToLocal() + + +@receiver( post_save, sender=User ) +def user_changed( **kwargs ): + logger.info("User info changed") + if not signalLock.isLocked(): + with signalLock: + logger.info("Synchronizing with google - user information changed") + eventplanner_gcal.models.deleteAllGCalEvents() eventplanner_gcal.models.syncGCalEvents() @@ -39,10 +52,10 @@ def event_post_save_handler( **kwargs): event = kwargs['instance'] created = kwargs['created'] if created: - print("Creating Gcal event") + logger.info("Creating Gcal event") eventplanner_gcal.models.createGCalEvent( event ).execute() else: - print( "Updating Gcal event") + logger.info( "Updating Gcal event") eventplanner_gcal.models.updateGCalEvent( event ).execute() @@ -52,7 +65,7 @@ def event_pre_delete_handler( **kwargs): if not signalLock.isLocked(): with signalLock: event = kwargs['instance'] - print ("Deleting GCAL event") + logger.info ("Deleting GCAL event") eventplanner_gcal.models.deleteGCalEvent( event ).execute() @@ -61,7 +74,7 @@ def participation_post_save_handler( **kwargs): if not signalLock.isLocked(): with signalLock: participation = kwargs['instance'] - print("Participation post save -> update gcal") + logger.info("Participation post save -> update gcal") eventplanner_gcal.models.updateGCalEvent( participation.event ).execute() diff --git a/eventplanner_gcal/views.py b/eventplanner_gcal/views.py index 4a63dce..3dbe326 100644 --- a/eventplanner_gcal/views.py +++ b/eventplanner_gcal/views.py @@ -1,16 +1,24 @@ from django.shortcuts import redirect from eventplanner_gcal.models import syncGCalEvents, syncParticipationFromGoogleToLocal +from eventplanner_gcal.signals import onGoogleCallback +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt + +import logging + +logger = logging.getLogger( __name__ ) def runSync( request ): syncGCalEvents() + return redirect("/") - +@csrf_exempt def gcalApiCallback( request ): - syncParticipationFromGoogleToLocal() - print ( "gcalApiCallback called" ) - return redirect("/") + onGoogleCallback() + logger.info("Received callback from GCal - updating event participations... ") + return HttpResponse('