Source

openju / openju / controllers / message.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

from openju import bl, g, _
from openju.util import pretty_date
from openju.views import render_message, render_messages_list, render_message_and_replies

def post(text):
    message = bl.message.post_message(g.auth_user, text)
    return _(u'Message #%s posted') % message.id

# def post_reply(hrid, message, r_no=None):
#     r_no = bl.message.post_reply(
#         g.user_jid,
#         hrid,
#         message,
#         r_no=r_no)
#     return u'Reply posted. #%s/%s' % (hrid, r_no)

def read(message_id):
    message = bl.message.get_message(message_id)
    
    return render_message(message)

def read_more(message_id):
    message = bl.message.get_message(message_id)
    replies = message.get_replies()
    
    return render_message_and_replies(message, replies)

def last_messages():
    messages = bl.message.get_last_messages()
    
    # render part
    ret_val = u''
    if len(messages):
        ret_val += render_messages_list(reversed(list(messages)))
    else:
        ret_val = u'There are no messages yet. Go on, post one!'
    return ret_val