Source

openju / openju / controllers / message.py

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

from openju import bl, g, _
from openju.views import \
    render_message, render_messages_list, \
    render_message_and_replies, render_message_id, \
    render_reply

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

def read(message_id):
    message = bl.message.get_message(message_id)
    if message.is_reply():
        return render_reply(message)
    else:
        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()
    
    if len(messages):
        return render_messages_list(reversed(list(messages)))
    else:
        return _(u'There are no messages yet. Go on, post one!')

def last_messages_from_friends():
    messages = g.auth_user.last_friends_messages()
    
    if len(messages):
        return render_messages_list(reversed(list(messages)))
    else:
        return _(u'There are no messages from friends yet.')

def last_user_messages(user_nick):
    user = bl.user.get_user(user_nick)
    messages = user.last_messages()

    if len(messages):
        return render_messages_list(reversed(list(messages)))
    else:
        return _(u'This user have not posted any messages yet.')

def post_reply(message_id, body):
    message = bl.message.get_message(message_id)
    new_message = message.post_reply(g.auth_user, body)
    return u"Message %(message_id)s posted." % {
        'message_id': render_message_id(new_message),
        }