66
77
88def model_content_type (cls ):
9- return ' %s.%s' % (cls ._meta .app_label , cls ._meta .object_name )
9+ return " %s.%s" % (cls ._meta .app_label , cls ._meta .object_name )
1010
1111
1212def create_reference (reference ):
13- if isinstance (reference , (models .Model , )):
13+ if isinstance (reference , (models .Model ,)):
1414 return create_model_reference (reference )
1515 return reference
1616
1717
1818def create_model_reference (model_instance ):
19- '''
19+ """
2020 creates a reference to a model instance that can be stored in activities
2121
2222 >>> from core.models import Like
2323 >>> like = Like.object.get(id=1)
2424 >>> create_reference(like)
2525 core.Like:1
2626
27- '''
27+ """
2828 content_type = model_content_type (model_instance .__class__ )
2929 content_id = model_instance .pk
30- return ' %s:%s' % (content_type , content_id )
30+ return " %s:%s" % (content_type , content_id )
3131
3232
3333class Activity (object ):
34-
3534 @property
3635 def activity_author_feed (self ):
37- '''
36+ """
3837 The name of the feed where the activity will be stored; this is normally
3938 used by the manager class to determine if the activity should be stored elsewhere than
4039 settings.USER_FEED
41- '''
40+ """
4241 pass
4342
4443 @classmethod
4544 def activity_related_models (cls ):
46- '''
45+ """
4746 Use this hook to setup related models to load during enrichment.
4847 It must return None or a list of relationships see Django select_related for reference
49- '''
48+ """
5049 pass
5150
5251 @property
5352 def extra_activity_data (self ):
54- '''
53+ """
5554 Use this hook to store extra data in activities.
5655 If you need to store references to model instances you should use create_model_reference
5756
5857 eg:
5958 @property
6059 def activity_extra_activity_data(self):
6160 dict('parent_user'=create_reference(self.parent_user))
62- '''
61+ """
6362 pass
6463
6564 @property
6665 def activity_actor_attr (self ):
67- '''
66+ """
6867 Returns the model instance field that references the activity actor
69- '''
68+ """
7069 return self .user
7170
7271 @property
7372 def activity_object_attr (self ):
74- '''
73+ """
7574 Returns the reference to the object of the activity
76- '''
75+ """
7776 return self
7877
7978 @property
@@ -88,7 +87,7 @@ def activity_actor(self):
8887 def activity_verb (self ):
8988 model_name = slugify (self .__class__ .__name__ )
9089 return model_name
91-
90+
9291 @property
9392 def activity_object (self ):
9493 return create_reference (self .activity_object_attr )
@@ -103,20 +102,20 @@ def activity_time(self):
103102 if is_aware (self .created_at ):
104103 atime = make_naive (atime , pytz .utc )
105104 return atime
106-
105+
107106 @property
108107 def activity_notify (self ):
109108 pass
110-
109+
111110 def create_activity (self ):
112111 extra_data = self .extra_activity_data
113112 if not extra_data :
114113 extra_data = {}
115-
114+
116115 to = self .activity_notify
117116 if to :
118- extra_data ['to' ] = [f .id for f in to ]
119-
117+ extra_data ["to" ] = [f .id for f in to ]
118+
120119 activity = dict (
121120 actor = self .activity_actor ,
122121 verb = self .activity_verb ,
0 commit comments