Fixed double sending of notifications on creating a new invite.
authorLennard de Rijk <ljvderijk@gmail.com>
Fri, 20 Mar 2009 14:04:57 +0000
changeset 1948 25cd704fdfdf
parent 1947 af360d1017df
child 1949 bcc52df68367
Fixed double sending of notifications on creating a new invite. Request logic now handles sending of the notification instead of the view. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/models/request.py
app/soc/views/models/role.py
--- a/app/soc/logic/models/request.py	Fri Mar 20 11:49:12 2009 +0000
+++ b/app/soc/logic/models/request.py	Fri Mar 20 14:04:57 2009 +0000
@@ -58,7 +58,7 @@
     """
 
     return ['scope_path', 'role', 'link_id']
-  
+
   def _onCreate(self, entity):
     """Sends out a message notifying users about the new invite/request.
     """
@@ -73,5 +73,24 @@
 
     super(Logic, self)._onCreate(entity)
 
+  def _updateField(self, entity, entity_properties, name):
+    """Called when the fields of the request are updated.
+
+      - Sends out a message depending on the change of status
+    """
+
+    value = entity_properties[name]
+
+    if name == 'status' and entity.status != value:
+      if value == 'group_accepted':
+       # this is an invite
+        notifications.sendInviteNotification(entity)
+      elif value == 'new':
+        # this is a request
+        # TODO(Lennard) Create a new request message
+        pass
+
+    return super(Logic, self)._updateField(entity, entity_properties, name)
+
 
 logic = Logic()
--- a/app/soc/views/models/role.py	Fri Mar 20 11:49:12 2009 +0000
+++ b/app/soc/views/models/role.py	Fri Mar 20 14:04:57 2009 +0000
@@ -269,9 +269,6 @@
     entity = request_logic.logic.updateOrCreateFromKeyName(request_fields,
                                                            key_name)
 
-    # send out an invite notification
-    notifications_helper.sendInviteNotification(entity)
-
     group_view = params.get('group_view')
     if not group_view:
       return http.HttpResponseRedirect('/')
@@ -618,9 +615,6 @@
           request_logic.logic.updateEntityProperties(request_entity, {
               'status': get_dict['status']})
 
-          if request_status == 'group_accepted':
-            notifications_helper.sendInviteNotification(request_entity)
-
         group_view = params.get('group_view')
         if not group_view:
           return http.HttpResponseRedirect('/')