From 7dbc9d08cd7249b9fa06e00133001f5f2417b84e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 18 2015 11:04:26 +0000 Subject: Move the JSON representation of comments on issue into their own function --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index d98cc81..f827292 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -510,14 +510,7 @@ class Issue(BASE): comments = [] for comment in self.comments: - cmt = { - 'id': comment.id, - 'comment': comment.comment, - 'parent': comment.parent_id, - 'date_created': comment.date_created.strftime('%s'), - 'user': comment.user.to_json(public=public), - } - comments.append(cmt) + comments.append(comment.to_json(public=public)) output['comments'] = comments @@ -597,6 +590,19 @@ class IssueComment(BASE): ''' Return the parent, in this case the issue object. ''' return self.issue + def to_json(self, public=False): + ''' Returns a dictionary representation of the issue. + + ''' + output = { + 'id': self.id, + 'comment': self.comment, + 'parent': self.parent_id, + 'date_created': self.date_created.strftime('%s'), + 'user': self.user.to_json(public=public), + } + return output + class Tag(BASE): """ Stores the tags.