Add __repr__ to Activity and Generator class
authorJessica Tallon <jessica@megworld.co.uk>
Tue, 7 Oct 2014 07:54:26 +0000 (08:54 +0100)
committerJessica Tallon <jessica@megworld.co.uk>
Tue, 7 Oct 2014 09:00:37 +0000 (10:00 +0100)
mediagoblin/db/mixin.py
mediagoblin/db/models.py
mediagoblin/tools/federation.py
mediagoblin/user_pages/views.py

index aec35fc777de74fe0436228ff476b1572555e374..39690cfc8fafc0fe97c2ef74c1704272ac11ec9f 100644 (file)
@@ -410,7 +410,7 @@ class ActivityMixin(object):
             "like": {"simple": _("{username} liked {object}")},
             "post": {
                 "simple": _("{username} posted {object}"),
-                "targetted": _("{username} posted {object} to {targetted}"),
+                "targetted": _("{username} posted {object} to {target}"),
             },
             "share": {"simple": _("{username} shared {object}")},
             "unfavorite": {"simple": _("{username} unfavorited {object}")},
index 4d7830d2cf62645314c299fa6ca81ed216b9949a..ffd7b4f12771d5337075233120061a4670ace568 100644 (file)
@@ -1070,6 +1070,12 @@ class Generator(Base):
     updated = Column(DateTime, default=datetime.datetime.now)
     object_type = Column(Unicode, nullable=False)
 
+    def __repr__(self):
+        return "<{klass} {name}>".format(
+            klass=self.__class__.__name__,
+            name=self.name
+        )
+
     def serialize(self, request):
         return {
             "id": self.id,
@@ -1168,6 +1174,18 @@ class Activity(Base, ActivityMixin):
         foreign_keys="Activity.actor", post_update=True)
     get_generator = relationship(Generator)
 
+    def __repr__(self):
+        if self.content is None:
+            return "<{klass} verb:{verb}>".format(
+                klass=self.__class__.__name__,
+                verb=self.verb
+            )
+        else:
+            return "<{klass} {content}>".format(
+                klass=self.__class__.__name__,
+                content=self.content
+            )
+
     @property
     def get_object(self):
         if self.object is None:
index 281994cc6228a792281a9f6eb791adac267c3a56..890e88010bb1c369ac837adb61cb65bfa188a13d 100644 (file)
@@ -14,8 +14,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from mediagoblin.db.models import Activity, Generator, User, MediaEntry, \
-                                  MediaComment, Collection
+from mediagoblin.db.models import Activity, Generator, User
 
 def create_activity(verb, obj, actor, target=None):
     """
index 0d0f3e7b7dd2bd376d1d1d947a51f7fa7f1115a8..d0ebdd70649140c15fc33a31bbb903987f316f78 100644 (file)
@@ -200,7 +200,7 @@ def media_post_comment(request, media):
             _('Your comment has been posted!'))
 
         trigger_notification(comment, media, request)
-        create_activity("post", comment, comment.author)
+        create_activity("post", comment, comment.author, target=media)
         add_comment_subscription(request.user, media)
 
     return redirect_obj(request, media)