Exemplo n.º 1
0
 def get(self):
     '''List messages by decrescent time.'''
     args = api.general_parse()
     page = args['page']
     per_page_num = args['per_page_num']
     messages = (db.session.query(Pedido, Message)
                 .options(joinedload('keywords'))
                 .filter(Message.pedido_id == Pedido.id)
                 .order_by(desc(Message.date)))
     # Limit que number of results per page
     messages, total = paginate(messages, page, per_page_num)
     return {
         'messages': [
             dict(msg.as_dict, keywords=[kw.name for kw in pedido.keywords])
             for pedido, msg in messages
         ],
         'total': total,
     }
Exemplo n.º 2
0
 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,
     }