Commits

Matthew Schinckel  committed 27da761

Make actor a User. Simpler relation.
Make object optional in signal send.

  • Participants
  • Parent commits 136f50d

Comments (0)

Files changed (2)

File notifications/__init__.py

     """
     Return the formatted version information
     """
-    return "0.6.0"
+    return "0.6.1"
 
 __version__ = get_version()

File notifications/models.py

 class NotificationQuerySet(models.query.QuerySet):
     
     def unread(self):
-        "Return only unread items in the current queryset"
+        """
+        Return only unread items in the current queryset, that
+        have not been marked as superseded.
+        """
         return self.filter(marked_read_at=None, superseded_at=None)
     
     def read(self):
-        "Return only read items in the current queryset"
+        """
+        Return only read items in the current queryset.
+        """
         return self.exclude(marked_read_at=None)
     
     def superseded(self):
+        """
+        Return only superseded objects in the queryset.
+        """
         return self.exclude(superseded_at=None)
     
     
     def mark_all_as_read(self, recipient=None):
-        """Mark as read any unread messages in the current queryset.
+        """
+        Mark as read any unread messages in the current queryset.
         
         Optionally, filter these by recipient first.
         """
         qs.update(marked_read_at=now())
     
     def mark_all_as_unread(self, recipient=None):
-        """Mark as unread any read messages in the current queryset.
+        """
+        Mark as unread any read messages in the current queryset.
         
         Optionally, filter these by recipient first.
         """
         qs.update(marked_read_at=None)
     
     def supersede(self, message):
+        """
+        Mark all objects in the queryset as superseded, with the
+        provided message.
+        """
         self.update(superseded_at=now(), superseded_message=message)
 
 class Notification(models.Model):
     """
     Action model describing the actor acting out a verb (on an optional
-    target).
+    target). Also contains some extensions, allowing for per-user
+    notifications.
+    
     Nomenclature based on http://activitystrea.ms/specs/atom/1.0/
 
     Generalized Format::
     
     ## These fields are part of the activitystrea.ms spec.
     timestamp = models.DateTimeField(default=now)
-
-    actor_content_type = models.ForeignKey(ContentType, related_name='notify_actor')
-    actor_object_id = models.CharField(max_length=255)
-    actor = generic.GenericForeignKey('actor_content_type', 'actor_object_id')
+    
+    actor = models.ForeignKey(User, blank=False, related_name='generated_notifications')
 
     verb = models.CharField(max_length=255)
 
 def notify_handler(signal, sender, **kwargs):
     """
     Handler function to create Notification instance upon action signal call.
+    
+    Required args are:
+    
+        * sender : must be a User object.
+        * verb
+        * object
+    
+        * recipients [iterable of User]
+    
+    Optional arguments are:
+        
+        * title
+        * summary
+        * target
+    
     """
     activity_stream_data = {
         'timestamp': datetime.datetime.utcnow().replace(tzinfo=utc),
         'actor': sender,
         'verb': kwargs.pop('verb'),
-        'object': kwargs.pop('object'),
         # target: need to add later, only if present, GFK limitations
         'title': kwargs.pop('title', None),
         'summary': kwargs.pop('summary', None),
     }
+    if 'object' in kwargs:
+        activity_stream_data['object'] = kwargs.pop('object')
     if 'target' in kwargs:
         activity_stream_data['target'] = kwargs.pop('target')