コード例 #1
0
ファイル: views.py プロジェクト: okfn-brasil/tagarela
def comment_to_dict(c):
    '''Return a comment as a dict (recursively including children).'''
    return {
        'id': c.id,
        'text': c.text,
        'author': c.author.name,
        'created': date_to_json(c.created),
        'modified': date_to_json(c.modified),
        'upvotes': c.likes,
        'downvotes': c.dislikes,
        'hidden': c.hidden,
        'url': api.url_for(CommentAPI, comment_id=c.id),
        'vote_url': api.url_for(VoteAPI, comment_id=c.id),
        'report_url': api.url_for(ReportAPI, comment_id=c.id),
        'replies': [] if c.children is None else [
            comment_to_dict(child)
            for child in c.children
        ]
    }
コード例 #2
0
ファイル: views.py プロジェクト: okfn-brasil/tagarela
 def get(self):
     '''List comments by decrescent creation time.'''
     args = api.general_parse()
     page = args['page']
     per_page_num = args['per_page_num']
     comments = (db.session.query(Comment, Thread.name)
                 .filter(Comment.thread_id == Thread.id)
                 .order_by(desc(Comment.created))
                 .filter_by(hidden=False))
     # Limit que number of results per page
     comments, total = paginate(comments, page, per_page_num)
     return {
         'comments': [
             {
                 'thread_name': thread_name,
                 'id': c.id,
                 'text': c.text,
                 'author': c.author.name,
                 'created': date_to_json(c.created),
                 'modified': date_to_json(c.modified),
                 # 'url': api.url_for(CommentAPI, comment_id=c.id),
             } for c, thread_name in comments],
         'total': total,
     }