Example #1
0
def add_comment(recid):
    uid = current_user.get_id()
    in_reply = request.args.get('in_reply', type=int)
    if in_reply is not None:
        comment = CmtRECORDCOMMENT.query.get(in_reply)

        if comment.id_bibrec != recid or comment.is_deleted:
            abort(401)

        if comment is not None:
            c = CmtRECORDCOMMENT()
            c.title = _('Re: ') + comment.title
            c.body = email_quote_txt(comment.body or '')
            c.in_reply_to_id_cmtRECORDCOMMENT = in_reply
            form = AddCmtRECORDCOMMENTForm(request.form, obj=c)
            return render_template('webcomment_add.html', form=form)

    form = AddCmtRECORDCOMMENTForm(request.values)
    if form.validate_on_submit():
        c = CmtRECORDCOMMENT()
        form.populate_obj(c)
        c.id_bibrec = recid
        c.id_user = uid
        c.date_creation = datetime.now()
        c.star_score = 0
        try:
            db.session.add(c)
            db.session.commit()
            flash(_('Comment was sent'), "info")
            return redirect(url_for('webcomment.comments', recid=recid))
        except:
            db.session.rollback()

    return render_template('webcomment_add.html', form=form)
    def test_quoting_message(self):
        """webmessage - test quoting message"""
        text = """C'est un lapin, lapin de bois.
>>Quoi?
Un cadeau.
>>What?
A present.
>>Oh, un cadeau"""

        expected_text = """>>C'est un lapin, lapin de bois.
>>>>Quoi?
>>Un cadeau.
>>>>What?
>>A present.
>>>>Oh, un cadeau
"""

        res = webmessage_mailutils.email_quote_txt(text, indent_txt=">>", linebreak_input="\n", linebreak_output="\n")
        self.assertEqual(res, expected_text)
Example #3
0
    def test_quoting_message(self):
        """webmessage - test quoting message (text)"""
        text = """C'est un lapin, lapin de bois.
>>Quoi?
Un cadeau.
>>What?
A present.
>>Oh, un cadeau"""

        expected_text = """>>C'est un lapin, lapin de bois.
>>>>Quoi?
>>Un cadeau.
>>>>What?
>>A present.
>>>>Oh, un cadeau
"""

        res = webmessage_mailutils.email_quote_txt(text,
                                                   indent_txt='>>',
                                                   linebreak_input="\n",
                                                   linebreak_output="\n")
        self.assertEqual(res, expected_text)
    def tmpl_write(self,
                   msg_to="", msg_to_group="",
                   msg_id=0,
                   msg_subject="", msg_body="",
                   msg_send_year=0, msg_send_month=0, msg_send_day=0,
                   warnings=[],
                   search_results_list=[],
                   search_pattern="",
                   results_field=CFG_WEBMESSAGE_RESULTS_FIELD['NONE'],
                   ln=CFG_SITE_LANG):
        """
        Displays a writing message form with optional prefilled fields
        @param msg_to: nick of the user (prefills the To: field)
        @param msg_subject: subject of the message (prefills the Subject: field)
        @param msg_body: body of the message (prefills the Message: field)
        @param msg_send_year: prefills to year field
        @param msg_send_month: prefills the month field
        @param msg_send_day: prefills the day field
        @param warnings: display warnings on top of page
        @param search_results_list: list of tuples. (user/groupname, is_selected)
        @param search_pattern: pattern used for searching
        @param results_field: 'none', 'user' or 'group', see CFG_WEBMESSAGE_RESULTS_FIELD
        @param ln: language of the form
        @return: the form in HTML format
        """
        _ = gettext_set_language(ln)
        write_box = self.tmpl_warning(warnings)

        # escape forbidden character
        msg_to = escape_html(msg_to)
        msg_to_group = escape_html(msg_to_group)
        msg_subject = escape_html(msg_subject)
        search_pattern = escape_html(search_pattern)

        to_select = self.tmpl_user_or_group_search(search_results_list,
                                                   search_pattern,
                                                   results_field,
                                                   ln)
        if msg_id:
            msg_subject = _("Re:") + " " + msg_subject
            msg_body = email_quote_txt(msg_body)
        write_box += """
<form name="write_message" action="%(url_form)s" method="post">
  <div style="float: left; vertical-align:text-top; margin-right: 10px;">
    <table class="mailbox">
      <thead class="mailboxheader">
        <tr>
          <td class="inboxheader" colspan="2">
            <table class="messageheader">
              <tr>
                <td class="mailboxlabel">%(to_label)s</td>
                <td class="mailboxlabel">%(users_label)s</td>
                <td style="width:100%%;">
                  <input class="mailboxinput" type="text" name="msg_to_user" value="%(to_users)s" />
                </td>
              </tr>
              <tr>
                <td class="mailboxlabel">&nbsp;</td>
                <td class="mailboxlabel">%(groups_label)s</td>
                <td style="width:100%%;">
                  <input class="mailboxinput" type="text" name="msg_to_group" value="%(to_groups)s" />
                </td>
              </tr>
              <tr>
                <td class="mailboxlabel">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td class="mailboxlabel">%(subject_label)s</td>
                <td colspan="2">
                  <input class="mailboxinput" type="text" name="msg_subject" value="%(subject)s" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <td style="height:0px" colspan="2"></td>
        </tr>
      </tfoot>
      <tbody class="mailboxbody">
        <tr>
          <td class="mailboxlabel">%(message_label)s</td>
          <td>
            <textarea name="msg_body" rows="10" cols="50">"""
        write_box_part2 = """
          </td>
        </tr>
        <tr>
          <td class="mailboxlabel">%(send_later_label)s</td>
          <td>
            %(day_field)s
            %(month_field)s
            %(year_field)s
          </td>
        </tr>
        <tr class="mailboxfooter">
          <td colspan="2" class="mailboxfoot">
            <input type="submit" name="send_button" value="%(send_label)s" class="formbutton"/>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div style="vertical-align:top; margin-left: 5px; float: left;">
    %(to_select)s
  </div>
</form>
"""
        write_box += "%(body)s</textarea>" + write_box_part2
        day_field = create_day_selectbox('msg_send_day',
                                          msg_send_day, ln)
        month_field = create_month_selectbox('msg_send_month',
                                              msg_send_month, ln)
        year_field = create_year_selectbox('msg_send_year', -1, 10,
                                            msg_send_year, ln)
        write_box = write_box % {'url_form': create_url(
                                                CFG_SITE_URL + '/yourmessages/send',
                                                {'ln': ln}),
                                 'to_users' : msg_to,
                                 'to_groups': msg_to_group,
                                 'subject' : msg_subject,
                                 'body' : msg_body,
                                 'ln': ln,
                                 'day_field': day_field,
                                 'month_field': month_field,
                                 'year_field': year_field,
                                 'to_select': to_select,
                                 'send_later_label': _("Send later?"),
                                 'to_label': _("To:"),
                                 'users_label': _("Users"),
                                 'groups_label': _("Groups"),
                                 'subject_label': _("Subject:"),
                                 'message_label': _("Message:"),
                                 'send_label': _("SEND")}
        return write_box
Example #5
0
    def tmpl_write(self,
                   msg_to="",
                   msg_to_group="",
                   msg_id=0,
                   msg_subject="",
                   msg_body="",
                   msg_send_year=0,
                   msg_send_month=0,
                   msg_send_day=0,
                   warnings=[],
                   search_results_list=[],
                   search_pattern="",
                   results_field=CFG_WEBMESSAGE_RESULTS_FIELD['NONE'],
                   ln=CFG_SITE_LANG):
        """
        Displays a writing message form with optional prefilled fields
        @param msg_to: nick of the user (prefills the To: field)
        @param msg_subject: subject of the message (prefills the Subject: field)
        @param msg_body: body of the message (prefills the Message: field)
        @param msg_send_year: prefills to year field
        @param msg_send_month: prefills the month field
        @param msg_send_day: prefills the day field
        @param warnings: display warnings on top of page
        @param search_results_list: list of tuples. (user/groupname, is_selected)
        @param search_pattern: pattern used for searching
        @param results_field: 'none', 'user' or 'group', see CFG_WEBMESSAGE_RESULTS_FIELD
        @param ln: language of the form
        @return: the form in HTML format
        """
        _ = gettext_set_language(ln)
        write_box = self.tmpl_warning(warnings)

        # escape forbidden character
        msg_to = escape_html(msg_to)
        msg_to_group = escape_html(msg_to_group)
        msg_subject = escape_html(msg_subject)
        search_pattern = escape_html(search_pattern)

        to_select = self.tmpl_user_or_group_search(search_results_list,
                                                   search_pattern,
                                                   results_field, ln)
        if msg_id:
            msg_subject = _("Re:") + " " + msg_subject
            msg_body = email_quote_txt(msg_body)
        write_box += """
<form name="write_message" action="%(url_form)s" method="post">
  <div style="float: left; vertical-align:text-top; margin-right: 10px;">
    <table class="mailbox">
      <thead class="mailboxheader">
        <tr>
          <td class="inboxheader" colspan="2">
            <table class="messageheader">
              <tr>
                <td class="mailboxlabel">%(to_label)s</td>
                <td class="mailboxlabel">%(users_label)s</td>
                <td style="width:100%%;">
                  <input class="mailboxinput" type="text" name="msg_to_user" value="%(to_users)s" />
                </td>
              </tr>
              <tr>
                <td class="mailboxlabel">&nbsp;</td>
                <td class="mailboxlabel">%(groups_label)s</td>
                <td style="width:100%%;">
                  <input class="mailboxinput" type="text" name="msg_to_group" value="%(to_groups)s" />
                </td>
              </tr>
              <tr>
                <td class="mailboxlabel">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td class="mailboxlabel">%(subject_label)s</td>
                <td colspan="2">
                  <input class="mailboxinput" type="text" name="msg_subject" value="%(subject)s" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <td style="height:0px" colspan="2"></td>
        </tr>
      </tfoot>
      <tbody class="mailboxbody">
        <tr>
          <td class="mailboxlabel">%(message_label)s</td>
          <td>
            <textarea name="msg_body" rows="10" cols="50">"""
        write_box_part2 = """
          </td>
        </tr>
        <tr>
          <td class="mailboxlabel">%(send_later_label)s</td>
          <td>
            %(day_field)s
            %(month_field)s
            %(year_field)s
          </td>
        </tr>
        <tr class="mailboxfooter">
          <td colspan="2" class="mailboxfoot">
            <input type="submit" name="send_button" value="%(send_label)s" class="formbutton"/>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div style="vertical-align:top; margin-left: 5px; float: left;">
    %(to_select)s
  </div>
</form>
"""
        write_box += "%(body)s</textarea>" + write_box_part2
        day_field = create_day_selectbox('msg_send_day', msg_send_day, ln)
        month_field = create_month_selectbox('msg_send_month', msg_send_month,
                                             ln)
        year_field = create_year_selectbox('msg_send_year', -1, 10,
                                           msg_send_year, ln)
        write_box = write_box % {
            'url_form': create_url(CFG_SITE_URL + '/yourmessages/send',
                                   {'ln': ln}),
            'to_users': msg_to,
            'to_groups': msg_to_group,
            'subject': msg_subject,
            'body': msg_body,
            'ln': ln,
            'day_field': day_field,
            'month_field': month_field,
            'year_field': year_field,
            'to_select': to_select,
            'send_later_label': _("Send later?"),
            'to_label': _("To:"),
            'users_label': _("Users"),
            'groups_label': _("Groups"),
            'subject_label': _("Subject:"),
            'message_label': _("Message:"),
            'send_label': _("SEND")
        }
        return write_box
Example #6
0
def add(msg_reply_id):
    uid = current_user.get_id()
    if msg_reply_id:
        if (dbplayer.check_user_owns_message(uid, msg_reply_id) == 0):
            flash(_('Sorry, this message in not in your mailbox.'), "error")
            return redirect(url_for('.index'))
        else:
            try:
                m = dbquery.get_message(uid, msg_reply_id)
                message = MsgMESSAGE()
                message.sent_to_user_nicks = m.message.user_from.nickname \
                    or str(m.message.id_user_from)
                message.subject = _("Re:") + " " + m.message.subject
                message.body = email_quote_txt(m.message.body)
                form = AddMsgMESSAGEForm(request.form, obj=message)
                return render_template('webmessage_add.html', form=form)
            except db.sqlalchemy.orm.exc.NoResultFound:
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                flash(_('This message does not exist.'), "error")
            except:
                flash(_('Problem with loading message.'), "error")

            return redirect(url_for('.index'))

    form = AddMsgMESSAGEForm(request.values)
    if form.validate_on_submit():
        m = MsgMESSAGE()
        form.populate_obj(m)
        m.id_user_from = uid
        m.sent_date = datetime.now()
        quotas = dbplayer.check_quota(CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES - 1)
        users = filter(lambda x: quotas.has_key(x.id), m.recipients)
        #m.recipients = m.recipients.difference(users))
        for u in users:
            m.recipients.remove(u)
        if len(users) > 0:
            flash(_('Following users reached their quota %d messages: %s') % \
                  (CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES, ', '.join(
                  [u.nickname for u in users]),), "error")
        flash(_('Message has %d valid recipients.') %
              (len(m.recipients),), "info")
        if len(m.recipients) == 0:
            flash(_('Message was not sent'), "info")
        else:
            if m.received_date is not None \
                and m.received_date > datetime.now():

                for um in m.sent_to_users:
                    um.status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
            else:
                m.received_date = datetime.now()
            try:
                db.session.add(m)
                db.session.commit()
                flash(_('Message was sent'), "info")
                return redirect(url_for('.index'))
            except:
                db.session.rollback()

    return render_template('webmessage_add.html', form=form)