From 2b1916182d36043c2dbce7c2718e8e1d1a976429 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 7 Oct 2014 08:54:26 +0100 Subject: [PATCH] Add __repr__ to Activity and Generator class --- mediagoblin/db/mixin.py | 2 +- mediagoblin/db/models.py | 18 ++++++++++++++++++ mediagoblin/tools/federation.py | 3 +-- mediagoblin/user_pages/views.py | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index aec35fc7..39690cfc 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -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}")}, diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4d7830d2..ffd7b4f1 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -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: diff --git a/mediagoblin/tools/federation.py b/mediagoblin/tools/federation.py index 281994cc..890e8801 100644 --- a/mediagoblin/tools/federation.py +++ b/mediagoblin/tools/federation.py @@ -14,8 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -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): """ diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 0d0f3e7b..d0ebdd70 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -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) -- 2.25.1