Commits

Peter Sanchez  committed 5dbd7eb

Updated views.py to save() subscription updates

  • Participants
  • Parent commits fb67565

Comments (0)

Files changed (1)

File djpubsubhubbub/views.py

 
 @csrf_exempt
 def callback(request, pk):
+    def subscription_update(subscription, is_subscribed=False):
+        subscription.verified = True
+        subscription.is_subscribed = is_subscribed
+        subscription.set_expiration(int(lease_seconds))
+        subscription.save()
+        verified.send(sender=subscription)
+
     if request.method == 'GET':
         try:
             mode = request.GET['hub.mode']
         if mode == 'subscribe':
             if not verify_token.startswith('subscribe'):
                 raise Http404
-            
-            subscription.verified = True
-            subscription.is_subscribed = True
-            subscription.set_expiration(int(lease_seconds))
-            verified.send(sender=subscription)
-        
+
+            subscription_update(subscription, True)
         elif mode == 'unsubscribe':
             if not verify_token.startswith('unsubscribe'):
                 raise Http404
 
-            subscription.verified = True
-            subscription.is_subscribed = False
-            subscription.set_expiration(int(lease_seconds))
-            verified.send(sender=subscription)
+            subscription_update(subscription)
 
         return HttpResponse(challenge, content_type='text/plain')
     elif request.method == 'POST':