コード例 #1
0
ファイル: api.py プロジェクト: mhellmic/b2share
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: body
    """
    _ = gettext_set_language(ln)

    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(_('Sorry, this message in not in your mailbox.'))
        except InvenioWebMessageError as exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
    else:
        (msg_id,
         msg_from_id, msg_from_nickname,
         msg_sent_to, msg_sent_to_group,
         msg_subject, msg_body,
         msg_sent_date, msg_received_date,
         msg_status) = db.get_message(uid, msgid)

        if (msg_id == ""):
            # The message exists in table user_msgMESSAGE
            # but not in table msgMESSAGE => table inconsistency
            try:
                raise InvenioWebMessageError(_('This message does not exist.'))
            except InvenioWebMessageError as exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            if (msg_status == CFG_WEBMESSAGE_STATUS_CODE['NEW']):
                db.set_message_status(uid, msgid,
                                      CFG_WEBMESSAGE_STATUS_CODE['READ'])
            body = webmessage_templates.tmpl_display_msg(
                                                msg_id,
                                                msg_from_id,
                                                msg_from_nickname,
                                                msg_sent_to,
                                                msg_sent_to_group,
                                                msg_subject,
                                                msg_body,
                                                msg_sent_date,
                                                msg_received_date,
                                                ln)
    return body
コード例 #2
0
ファイル: api.py プロジェクト: chokribr/invenio-1
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: body
    """
    _ = gettext_set_language(ln)

    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(
                _('Sorry, this message is not in your mailbox.'))
        except InvenioWebMessageError as exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
    else:
        (msg_id, msg_from_id, msg_from_nickname, msg_sent_to,
         msg_sent_to_group, msg_subject, msg_body, msg_sent_date,
         msg_received_date, msg_status) = db.get_message(uid, msgid)

        if (msg_id == ""):
            # The message exists in table user_msgMESSAGE
            # but not in table msgMESSAGE => table inconsistency
            try:
                raise InvenioWebMessageError(_('This message does not exist.'))
            except InvenioWebMessageError as exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            if (msg_status == CFG_WEBMESSAGE_STATUS_CODE['NEW']):
                db.set_message_status(uid, msgid,
                                      CFG_WEBMESSAGE_STATUS_CODE['READ'])
            body = webmessage_templates.tmpl_display_msg(
                msg_id, msg_from_id, msg_from_nickname, msg_sent_to,
                msg_sent_to_group, msg_subject, msg_body, msg_sent_date,
                msg_received_date, ln)
    return body
コード例 #3
0
ファイル: api.py プロジェクト: mhellmic/b2share
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: body with warnings.
    """
    warnings = []
    body = ""
    _ = gettext_set_language(ln)
    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            try:
                raise InvenioWebMessageError(_('Sorry, this message in not in your mailbox.'))
            except InvenioWebMessageError as exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id,
             msg_from_id, msg_from_nickname,
             dummy, dummy,
             msg_subject, msg_body,
             dummy, dummy, dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                try:
                    raise InvenioWebMessageError(_('This message does not exist.'))
                except InvenioWebMessageError as exc:
                    register_exception()
                    body = webmessage_templates.tmpl_error(exc.message, ln)
                    return body
            else:
                msg_to = msg_from_nickname or str(msg_from_id)

    body = webmessage_templates.tmpl_write(msg_to=msg_to,
                                           msg_to_group=msg_to_group,
                                           msg_id=msg_id,
                                           msg_subject=msg_subject,
                                           msg_body=msg_body,
                                           warnings=[],
                                           ln=ln)
    return body
コード例 #4
0
ファイル: api.py プロジェクト: chokribr/invenio-1
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: body with warnings.
    """
    warnings = []
    body = ""
    _ = gettext_set_language(ln)
    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            try:
                raise InvenioWebMessageError(
                    _('Sorry, this message is not in your mailbox.'))
            except InvenioWebMessageError as exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id, msg_from_id, msg_from_nickname, dummy, dummy, msg_subject,
             msg_body, dummy, dummy,
             dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                try:
                    raise InvenioWebMessageError(
                        _('This message does not exist.'))
                except InvenioWebMessageError as exc:
                    register_exception()
                    body = webmessage_templates.tmpl_error(exc.message, ln)
                    return body
            else:
                msg_to = msg_from_nickname or str(msg_from_id)

    body = webmessage_templates.tmpl_write(msg_to=msg_to,
                                           msg_to_group=msg_to_group,
                                           msg_id=msg_id,
                                           msg_subject=msg_subject,
                                           msg_body=msg_body,
                                           warnings=[],
                                           ln=ln)
    return body