Beispiel #1
0
 def tmpl_page_xml_output(self, keywords, xml=None,
                          req=None,
                          ln=None,
                          generate=None,
                          sorting=None,
                          type=None,
                          numbering=None,
                          showall=None):
     kw = '<pre class="bibclassify-marcxml"><code>%s</code></pre>' % escape_html(xml)
     return self.tmpl_page(keywords, middle=kw,
                           ln=ln,
                           generate=generate,
                           sorting=sorting,
                           type=type,
                           numbering=numbering,
                           showall=showall)
Beispiel #2
0
 def tmpl_page_xml_output(self, keywords, xml=None,
                          req=None,
                          ln=None,
                          generate=None,
                          sorting=None,
                          type=None,
                          numbering=None,
                          showall=None):
     kw = '<pre class="bibclassify-marcxml"><code>%s</code></pre>' % escape_html(xml)
     return self.tmpl_page(keywords, middle=kw,
                           ln=ln,
                           generate=generate,
                           sorting=sorting,
                           type=type,
                           numbering=numbering,
                           showall=showall)
Beispiel #3
0
    def tmpl_display_inbox(self, messages, infos=[], warnings=[], nb_messages=0, no_quota=0, ln=CFG_SITE_LANG):
        """
        Displays a list of messages, with the appropriate links and buttons
        @param messages: a list of tuples:
                         [(message_id,
                           user_from_id,
                           user_from_nickname,
                           subject,
                           sent_date,
                           status=]
        @param infos: a list of informations to print on top of page
        @param warnings: a list of warnings to display
        @param nb_messages: number of messages user has
        @param no_quota: 1 if user has no quota (admin) or 0 else.
        @param ln: language of the page.
        @return: the list in HTML format
        """
        _ = gettext_set_language(ln)
        dummy = 0
        inbox = self.tmpl_warning(warnings, ln)
        inbox += self.tmpl_infobox(infos, ln)
        if not(no_quota):
            inbox += self.tmpl_quota(nb_messages, ln)
        inbox += """
<table class="mailbox">
  <thead class="mailboxheader">
    <tr class="inboxheader">
      <td>%s</td>
      <td>%s</td>
      <td>%s</td>
      <td>%s</td>
    </tr>
  </thead>
  <tfoot>
    <tr style="height:0px;">
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </tfoot>
  <tbody class="mailboxbody">""" % (_("Subject"),
                                    _("Sender"),
                                    _("Date"),
                                    _("Action"))
        if len(messages) == 0:
            inbox += """
    <tr class="mailboxrecord" style="height: 100px;">
      <td colspan="4" style="text-align: center;">
        <b>%s</b>
      </td>
    </tr>""" %(_("No messages"),)
        for (msgid, id_user_from, user_from_nick,
             subject, sent_date, status) in messages:
            if not(subject):
                subject = _("No subject")
            subject_link = create_html_link(
                                CFG_SITE_URL + '/yourmessages/display_msg',
                                {'msgid': msgid, 'ln': ln},
                                escape_html(subject))
            if user_from_nick:
                from_link = '%s'% (user_from_nick)
            else:
                from_link = get_user_info(id_user_from, ln)[2]
            action_link = create_html_link(CFG_SITE_URL + '/yourmessages/write',
                                           {'msg_reply_id': msgid, 'ln': ln},
                                           _("Reply"))
            action_link += ' '
            action_link += create_html_link(CFG_SITE_URL + '/yourmessages/delete',
                                            {'msgid': msgid, 'ln': ln},
                                            _("Delete"))
            s_date = convert_datetext_to_dategui(sent_date, ln)
            stat_style = ''
            if (status == CFG_WEBMESSAGE_STATUS_CODE['NEW']):
                stat_style = ' style="font-weight:bold"'
            inbox += """
    <tr class="mailboxrecord">
      <td%s>%s</td>
      <td>%s</td>
      <td>%s</td>
      <td>%s</td>
    </tr>""" %(stat_style, subject_link, from_link, s_date, action_link)
        inbox += """
    <tr class="mailboxfooter">
      <td colspan="2">
        <form name="newMessage" action="%(url_new)s" method="post">
          <input type="submit" name="del_all" value="%(write_label)s" class="formbutton" />
        </form>
      </td>
      <td>&nbsp;</td>
      <td>
        <form name="deleteAll" action="%(url_delete_all)s" method="post">
          <input type="submit" name="del_all" value="%(delete_all_label)s" class="formbutton" />
        </form>
      </td>
    </tr>
  </tbody>
</table>""" % {'url_new': create_url(CFG_SITE_URL + '/yourmessages/write',
                                     {'ln': ln}),
               'url_delete_all': create_url(CFG_SITE_URL + '/yourmessages/delete_all',
                                            {'ln': ln}),
               'write_label': _("Write new message"),
               'delete_all_label': _("Delete All")}
        return inbox
Beispiel #4
0
    def tmpl_display_msg(self,
                         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=datetext_default,
                         ln=CFG_SITE_LANG):
        """
        Displays a given message
        @param msg_id: id of the message
        @param msg_from_id: id of user who sent the message
        @param msg_from_nickname: nickname of the user who sent the message
        @param msg_sent_to: list of users who received the message
                            (comma separated string)
        @param msg_sent_to_group: list of groups who received the message
                                  (comma separated string)
        @param msg_subject: subject of the message
        @param msg_body: body of the message
        @param msg_sent_date: date at which the message was sent
        @param msg_received_date: date at which the message had to be received
                                  (if this argument != 0000-00-00 => reminder
        @param ln: language of the page
        @return: the message in HTML format
        """

        # load the right message language
        _ = gettext_set_language(ln)

        sent_to_link = ''
        tos = msg_sent_to.split(CFG_WEBMESSAGE_SEPARATOR)
        if (tos):
            for to in tos[0:-1]:
                to_display = to
                if to.isdigit():
                    (dummy, to, to_display) = get_user_info(int(to), ln)
                sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write',
                                                 {'msg_to': to, 'ln': ln},
                                                 escape_html(to_display))
                sent_to_link += CFG_WEBMESSAGE_SEPARATOR
            to_display = tos[-1]
            to = tos[-1]
            if to.isdigit():
                (dummy, to, to_display) = get_user_info(int(to), ln)
            sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write',
                                             {'msg_to': to, 'ln': ln},
                                             escape_html(to_display))
        group_to_link = ""
        groups = msg_sent_to_group.split(CFG_WEBMESSAGE_SEPARATOR)
        if (groups):
            for group in groups[0:-1]:
                group_to_link += create_html_link(
                                    CFG_SITE_URL + '/yourmessages/write',
                                    {'msg_to_group': group, 'ln': ln},
                                    escape_html(group))
                group_to_link += CFG_WEBMESSAGE_SEPARATOR
            group_to_link += create_html_link(
                                CFG_SITE_URL + '/yourmessages/write',
                                {'msg_to_group': groups[-1], 'ln': ln},
                                escape_html(groups[-1]))
        # format the msg so that the '>>' chars give vertical lines
        final_body = email_quoted_txt2html(msg_body)

        out = """
<table class="mailbox" style="width: 70%%;">
  <thead class="mailboxheader">
    <tr>
      <td class="inboxheader" colspan="2">
        <table class="messageheader">
          <tr>
            <td class="mailboxlabel">%(from_label)s</td>
            <td>%(from_link)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(subject_label)s</td>
            <td style="width: 100%%;">%(subject)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(sent_label)s</td>
            <td>%(sent_date)s</td>
          </tr>"""
        if (msg_received_date != datetext_default):
            out += """
          <tr>
            <td class="mailboxlabel">%(received_label)s</td>
            <td>%(received_date)s</td>
          </tr>"""
        out += """
          <tr>
            <td class="mailboxlabel">%(sent_to_label)s</td>
            <td>%(sent_to)s</td>
          </tr>"""
        if (msg_sent_to_group != ""):
            out += """
          <tr>
            <td class="mailboxlabel">%(groups_label)s</td>
            <td>%(sent_to_group)s</td>
          </tr>"""
        out += """
        </table>
      </td>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </tfoot>
  <tbody class="mailboxbody">
    <tr class="mailboxrecord">
      <td colspan="2">%(body)s</td>
    </tr>
    <tr class="mailboxfooter">
      <td>
        <form name="reply" action="%(reply_url)s" method="post">
          <input class="formbutton" name="reply" value="%(reply_but_label)s" type="submit" />
        </form>
      </td>
      <td>
        <form name="deletemsg" action="%(delete_url)s" method="post">
          <input class="formbutton" name="delete" value="%(delete_but_label)s" type="submit" />
        </form>
      </td>
    </tr>
  </tbody>
</table>
        """
        if msg_from_nickname:
            msg_from_display = msg_from_nickname
        else:
            msg_from_display = get_user_info(msg_from_id, ln)[2]
            msg_from_nickname = msg_from_id

        return out % {'from_link': create_html_link(
                                        CFG_SITE_URL + '/yourmessages/write',
                                        {'msg_to': msg_from_nickname,
                                         'ln': ln},
                                        msg_from_display),
                     'reply_url': create_url(CFG_SITE_URL + '/yourmessages/write',
                                             {'msg_reply_id': msg_id,
                                             'ln':  ln}),
                     'delete_url': create_url(CFG_SITE_URL + '/yourmessages/delete',
                                             {'msgid': msg_id,
                                             'ln':  ln}),
                     'sent_date' : convert_datetext_to_dategui(msg_sent_date, ln),
                     'received_date': convert_datetext_to_dategui(msg_received_date, ln),
                     'sent_to': sent_to_link,
                     'sent_to_group': group_to_link,
                     'subject' : msg_subject,
                     'body' : final_body,
                     'reply_to': msg_from_id,
                     'ln': ln,
                     'from_label':_("From:"),
                     'subject_label':_("Subject:"),
                     'sent_label': _("Sent on:"),
                     'received_label':_("Received on:"),
                     'sent_to_label': _("Sent to:"),
                     'groups_label': _("Sent to groups:"),
                     'reply_but_label':_("REPLY"),
                     'delete_but_label': _("DELETE")}
Beispiel #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
Beispiel #6
0
    def tmpl_display_confirm_page(self, ln=CFG_SITE_LANG,
                metafile=None, filetype=None, mode=None, submit_date=None,
                submit_time=None, file_name=None, priority=None,
                                  errors_upload='', skip_simulation=False, email_logs_to=None):
        """ Display a confirmation page before uploading metadata
        """
        _ = gettext_set_language(ln)

        priority_map = {'1' : 'Normal', '5': 'High'}
        display_schedule = (submit_date != '')
        schedule_msg = """%(text_confirm6)s <strong>%(submit_date)s</strong> at <strong>%(submit_time)s</strong>
                            <br/><br/>""" % {'text_confirm6': _('The job is scheduled to run on'),
                                             'submit_date': submit_date,
                                             'submit_time': submit_time}

        error_msgs = ['<ol id="batchuploader_error_list">']
        for error in errors_upload.splitlines():
            error_msgs.append("<li>%s</li>" % error)
        error_msgs.append("</ol>")

        errors_textarea = ""
        if not skip_simulation:
            errors_textarea = """%(text_error1)s
                                  <div class="batchuploader_error"> %(error_msgs)s </div>
                                  <br />
                               """ % {'text_error1': '<div class="clean_error">Some errors have been found during the upload simulation</div>',
                                      'error_msgs': '\n'.join(error_msgs)}
            if not errors_upload:
                errors_textarea = '<div class="clean_ok">No errors were found during the upload simulation</div><br/>'

        marcxml_textarea = """<textarea style="background-color: lightyellow" name="metafile" rows="20" cols="80">%(filecontent)s</textarea> """ % {'filecontent': escape_html(metafile.value)}

        body_content = """<form class="uploadform" method="post" action="%(site_url)s/batchuploader/metasubmit">""" \
                                       % {'site_url': CFG_SITE_URL}
        body_content += """
                        <div id="content">
                        <input type="hidden" name="filetype" value=%(filetype)s>
                        <input type="hidden" name="mode" value=%(mode)s>
                        <input type="hidden" name="submit_date" value=%(submit_date)s>
                        <input type="hidden" name="submit_time" value=%(submit_time)s>
                        <input type="hidden" name="filename" value=%(filename)s>
                        <input type="hidden" name="priority" value=%(priority_num)s>
                        <input type="hidden" name="email_logs_to" value=%(email_logs_to)s>
                        <div> %(errors_textarea)s %(text_confirm1)s <strong>%(filetype)s</strong> %(text_confirm2)s <strong>%(filename)s</strong> %(text_confirm3)s: <br /><br />
                            %(marcxml_textarea)s
                            <br /><br />
                            %(text_confirm4)s <strong>%(priority_txt)s</strong> %(text_confirm5)s <strong>%(mode)s</strong>.
                            <br/><br/>
                            %(schedule_msg)s
                            %(text_confirm7)s (<strong>%(num_rec)s</strong> %(text_confirm8)s)
                            <table>
                            <tr>
                                <td><input type="submit" value="Confirm" class="adminbutton" %(confirm_disabled)s></td>
                                <td><input type="button" value="Cancel" class="adminbutton" onclick="window.location.href = './'"></td>
                            </tr>
                            </table>
                        </div>
                        """ % {'text_confirm1': _('You are about to submit a'),
                               'text_confirm2': _('file with name'),
                               'text_confirm3': _('and content'),
                               'text_confirm4': _('This file will be uploaded with priority'),
                               'text_confirm5': _('and in mode'),
                               'text_confirm7': _('Do you want to submit the changes?'),
                               'text_confirm8': _('record(s) will be affected'),
                               'schedule_msg' : display_schedule and schedule_msg or '',
                               'filetype': filetype,
                               'filename': file_name,
                               'marcxml_textarea': marcxml_textarea,
                               'filecontent': metafile.value,
                               'priority_num': priority,
                               'email_logs_to': email_logs_to,
                               'priority_txt': priority_map[priority],
                               'mode': mode,
                               'num_rec': metafile.value.count('<record>'),
                               'submit_date': submit_date,
                               'submit_time': submit_time,
                               'errors_textarea': errors_textarea,
                               'confirm_disabled': errors_upload and 'DISABLED style="background:grey;"' or ''}
        body_content += """</div></form> """
        return body_content
Beispiel #7
0
def perform_request_send(uid,
                         msg_to_user="",
                         msg_to_group="",
                         msg_subject="",
                         msg_body="",
                         msg_send_year=0,
                         msg_send_month=0,
                         msg_send_day=0,
                         ln=CFG_SITE_LANG,
                         use_email_address = 0):
    """
    send a message. if unable return warnings to write page
    @param uid: id of user from (int)
    @param msg_to_user: comma separated usernames (recipients) (str)
    @param msg_to_group: comma separated groupnames (recipeints) (str)
    @param msg_subject: subject of message (str)
    @param msg_body: body of message (str)
    @param msg_send_year: send this message on year x (int)
    @param msg_send_month: send this message on month y (int)
    @param msg_send_day: send this message on day z (int)
    @param ln: language
    @return: (body with warnings, title, navtrail)
    """
    _ = gettext_set_language(ln)

    def strip_spaces(text):
        """suppress spaces before and after x (str)"""
        return text.strip()
    # wash user input
    users_to = map(strip_spaces, msg_to_user.split(CFG_WEBMESSAGE_SEPARATOR))
    groups_to = map(strip_spaces, msg_to_group.split(CFG_WEBMESSAGE_SEPARATOR))

    if users_to == ['']:
        users_to = []
    if groups_to == ['']:
        groups_to = []

    warnings = []
    infos = []
    problem = None

    users_to_str = CFG_WEBMESSAGE_SEPARATOR.join(users_to)
    groups_to_str = CFG_WEBMESSAGE_SEPARATOR.join(groups_to)

    send_on_date = get_datetext(msg_send_year, msg_send_month, msg_send_day)
    if (msg_send_year == msg_send_month == msg_send_day == 0):
        status = CFG_WEBMESSAGE_STATUS_CODE['NEW']
    else:
        status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
        if send_on_date == datetext_default:
            warning = \
            _("The chosen date (%(x_year)i/%(x_month)i/%(x_day)i) is invalid.")
            warning = warning % {'x_year': msg_send_year,
                                 'x_month': msg_send_month,
                                 'x_day': msg_send_day}
            warnings.append(warning)
            problem = True

    if not(users_to_str or groups_to_str):
        # <=> not(users_to_str) AND not(groups_to_str)
        warnings.append(_("Please enter a user name or a group name."))
        problem = True

    if len(msg_body) > CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE:
        warnings.append(_("Your message is too long, please edit it. Maximum size allowed is %(x_size)i characters.",
                    x_size=(CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE,)))
        problem = True

    if use_email_address == 0:
        users_dict = db.get_uids_from_nicks(users_to)
        users_to = users_dict.items() # users_to=[(nick, uid),(nick2, uid2)]
    elif use_email_address == 1:
        users_dict = db.get_uids_from_emails(users_to)
        users_to = users_dict.items() # users_to=[(email, uid),(email2, uid2)]
    groups_dict = db.get_gids_from_groupnames(groups_to)
    groups_to = groups_dict.items()
    gids_to = []
    for (group_name, group_id) in groups_to:
        if not(group_id):
            warnings.append(_("Group %(x_name)s does not exist.", x_name=(escape_html(group_name))))
            problem = 1
        else:
            gids_to.append(group_id)

    # Get uids from gids
    uids_from_group = db.get_uids_members_of_groups(gids_to)
    # Add the original uids, and make sure  there is no double values.
    tmp_dict = {}
    for uid_receiver in uids_from_group:
        tmp_dict[uid_receiver] = None
    for (user_nick, user_id) in users_to:
        if user_id:
            if user_id not in tmp_dict:
                uids_from_group.append(user_id)
                tmp_dict[user_id] = None
        else:
            if type(user_nick) == int or \
               type(user_nick) == str and user_nick.isdigit():
                user_nick = int(user_nick)
                if db.user_exists(user_nick) and user_nick not in tmp_dict:
                    uids_from_group.append(user_nick)
                    tmp_dict[user_nick] = None
            else:
                warnings.append(_("User %(x_name)s does not exist.", x_name=(escape_html(user_nick))))
                problem = True
    if problem:
        body = webmessage_templates.tmpl_write(msg_to=users_to_str,
                                               msg_to_group=groups_to_str,
                                               msg_subject=msg_subject,
                                               msg_body=msg_body,
                                               msg_send_year=msg_send_year,
                                               msg_send_month=msg_send_month,
                                               msg_send_day=msg_send_day,
                                               warnings=warnings,
                                               ln=ln)
        title =  _("Write a message")
        navtrail = get_navtrail(ln, title)
        return (body, title, navtrail)
    else:
        msg_id = db.create_message(uid,
                                   users_to_str, groups_to_str,
                                   msg_subject, msg_body,
                                   send_on_date)
        uid_problem = db.send_message(uids_from_group, msg_id, status)
        if len(uid_problem) > 0:
            usernames_problem_dict = db.get_nicks_from_uids(uid_problem)
            usernames_problem = usernames_problem_dict.values()
            def listing(name1, name2):
                """ name1, name2 => 'name1, name2' """
                return str(name1) + ", " + str(name2)
            warning = _("Your message could not be sent to the following recipients due to their quota:") + " "
            warnings.append(warning + reduce(listing, usernames_problem))

        if len(uids_from_group) != len(uid_problem):
            infos.append(_("Your message has been sent."))
        else:
            db.check_if_need_to_delete_message_permanently([msg_id])
        body = perform_request_display(uid, warnings,
                                       infos, ln)
        title = _("Your Messages")
        return (body, title, get_navtrail(ln))
Beispiel #8
0
def perform_request_send(uid,
                         msg_to_user="",
                         msg_to_group="",
                         msg_subject="",
                         msg_body="",
                         msg_send_year=0,
                         msg_send_month=0,
                         msg_send_day=0,
                         ln=CFG_SITE_LANG,
                         use_email_address=0):
    """
    send a message. if unable return warnings to write page
    @param uid: id of user from (int)
    @param msg_to_user: comma separated usernames (recipients) (str)
    @param msg_to_group: comma separated groupnames (recipeints) (str)
    @param msg_subject: subject of message (str)
    @param msg_body: body of message (str)
    @param msg_send_year: send this message on year x (int)
    @param msg_send_month: send this message on month y (int)
    @param msg_send_day: send this message on day z (int)
    @param ln: language
    @return: (body with warnings, title, navtrail)
    """
    _ = gettext_set_language(ln)

    def strip_spaces(text):
        """suppress spaces before and after x (str)"""
        return text.strip()

    # wash user input
    users_to = map(strip_spaces, msg_to_user.split(CFG_WEBMESSAGE_SEPARATOR))
    groups_to = map(strip_spaces, msg_to_group.split(CFG_WEBMESSAGE_SEPARATOR))

    if users_to == ['']:
        users_to = []
    if groups_to == ['']:
        groups_to = []

    warnings = []
    infos = []
    problem = None

    users_to_str = CFG_WEBMESSAGE_SEPARATOR.join(users_to)
    groups_to_str = CFG_WEBMESSAGE_SEPARATOR.join(groups_to)

    send_on_date = get_datetext(msg_send_year, msg_send_month, msg_send_day)
    if (msg_send_year == msg_send_month == msg_send_day == 0):
        status = CFG_WEBMESSAGE_STATUS_CODE['NEW']
    else:
        status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
        if send_on_date == datetext_default:
            warning = \
            _("The chosen date (%(x_year)i/%(x_month)i/%(x_day)i) is invalid.")
            warning = warning % {
                'x_year': msg_send_year,
                'x_month': msg_send_month,
                'x_day': msg_send_day
            }
            warnings.append(warning)
            problem = True

    if not (users_to_str or groups_to_str):
        # <=> not(users_to_str) AND not(groups_to_str)
        warnings.append(_("Please enter a user name or a group name."))
        problem = True

    if len(msg_body) > CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE:
        warnings.append(
            _(
                "Your message is too long, please shorten it. "
                "Maximum size allowed is %(x_size)i characters.",
                x_size=(CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE, )))
        problem = True

    if use_email_address == 0:
        users_dict = db.get_uids_from_nicks(users_to)
        users_to = users_dict.items()  # users_to=[(nick, uid),(nick2, uid2)]
    elif use_email_address == 1:
        users_dict = db.get_uids_from_emails(users_to)
        users_to = users_dict.items()  # users_to=[(email, uid),(email2, uid2)]
    groups_dict = db.get_gids_from_groupnames(groups_to)
    groups_to = groups_dict.items()
    gids_to = []
    for (group_name, group_id) in groups_to:
        if not (group_id):
            warnings.append(
                _("Group %(x_name)s does not exist.",
                  x_name=(escape_html(group_name))))
            problem = 1
        else:
            gids_to.append(group_id)

    # Get uids from gids
    uids_from_group = db.get_uids_members_of_groups(gids_to)
    # Add the original uids, and make sure  there is no double values.
    tmp_dict = {}
    for uid_receiver in uids_from_group:
        tmp_dict[uid_receiver] = None
    for (user_nick, user_id) in users_to:
        if user_id:
            if user_id not in tmp_dict:
                uids_from_group.append(user_id)
                tmp_dict[user_id] = None
        else:
            if type(user_nick) == int or \
               type(user_nick) == str and user_nick.isdigit():
                user_nick = int(user_nick)
                if db.user_exists(user_nick) and user_nick not in tmp_dict:
                    uids_from_group.append(user_nick)
                    tmp_dict[user_nick] = None
            else:
                warnings.append(
                    _("User %(x_name)s does not exist.",
                      x_name=(escape_html(user_nick))))
                problem = True
    if problem:
        body = webmessage_templates.tmpl_write(msg_to=users_to_str,
                                               msg_to_group=groups_to_str,
                                               msg_subject=msg_subject,
                                               msg_body=msg_body,
                                               msg_send_year=msg_send_year,
                                               msg_send_month=msg_send_month,
                                               msg_send_day=msg_send_day,
                                               warnings=warnings,
                                               ln=ln)
        title = _("Write a message")
        navtrail = get_navtrail(ln, title)
        return (body, title, navtrail)
    else:
        msg_id = db.create_message(uid, users_to_str, groups_to_str,
                                   msg_subject, msg_body, send_on_date)
        uid_problem = db.send_message(uids_from_group, msg_id, status)
        if len(uid_problem) > 0:
            usernames_problem_dict = db.get_nicks_from_uids(uid_problem)
            usernames_problem = usernames_problem_dict.values()

            def listing(name1, name2):
                """ name1, name2 => 'name1, name2' """
                return str(name1) + ", " + str(name2)

            warning = _(
                "Your message could not be sent to the following recipients as it would exceed their quotas:"
            ) + " "
            warnings.append(warning + reduce(listing, usernames_problem))

        if len(uids_from_group) != len(uid_problem):
            infos.append(_("Your message has been sent."))
        else:
            db.check_if_need_to_delete_message_permanently([msg_id])
        body = perform_request_display(uid, warnings, infos, ln)
        title = _("Your Messages")
        return (body, title, get_navtrail(ln))
Beispiel #9
0
    def tmpl_display_confirm_page(self, ln=CFG_SITE_LANG,
                metafile=None, filetype=None, mode=None, submit_date=None,
                submit_time=None, file_name=None, priority=None,
                                  errors_upload='', skip_simulation=False, email_logs_to=None):
        """ Display a confirmation page before uploading metadata
        """
        _ = gettext_set_language(ln)

        priority_map = {'1' : 'Normal', '5': 'High'}
        display_schedule = (submit_date != '')
        schedule_msg = """%(text_confirm6)s <strong>%(submit_date)s</strong> at <strong>%(submit_time)s</strong>
                            <br/><br/>""" % {'text_confirm6': _('The job is scheduled to run on'),
                                             'submit_date': submit_date,
                                             'submit_time': submit_time}

        error_msgs = ['<ol id="batchuploader_error_list">']
        for error in errors_upload.splitlines():
            error_msgs.append("<li>%s</li>" % error)
        error_msgs.append("</ol>")

        errors_textarea = ""
        if not skip_simulation:
            errors_textarea = """%(text_error1)s
                                  <div class="batchuploader_error"> %(error_msgs)s </div>
                                  <br />
                               """ % {'text_error1': '<div class="clean_error">Some errors have been found during the upload simulation</div>',
                                      'error_msgs': '\n'.join(error_msgs)}
            if not errors_upload:
                errors_textarea = '<div class="clean_ok">No errors were found during the upload simulation</div><br/>'

        marcxml_textarea = """<textarea style="background-color: lightyellow" name="metafile" rows="20" cols="80">%(filecontent)s</textarea> """ % {'filecontent': escape_html(metafile)}

        body_content = """<form class="uploadform" method="post" action="%(site_url)s/batchuploader/metasubmit">""" \
                                       % {'site_url': CFG_SITE_URL}
        body_content += """
                        <div id="content">
                        <input type="hidden" name="filetype" value=%(filetype)s>
                        <input type="hidden" name="mode" value=%(mode)s>
                        <input type="hidden" name="submit_date" value=%(submit_date)s>
                        <input type="hidden" name="submit_time" value=%(submit_time)s>
                        <input type="hidden" name="filename" value=%(filename)s>
                        <input type="hidden" name="priority" value=%(priority_num)s>
                        <input type="hidden" name="email_logs_to" value=%(email_logs_to)s>
                        <div> %(errors_textarea)s %(text_confirm1)s <strong>%(filetype)s</strong> %(text_confirm2)s <strong>%(filename)s</strong> %(text_confirm3)s: <br /><br />
                            %(marcxml_textarea)s
                            <br /><br />
                            %(text_confirm4)s <strong>%(priority_txt)s</strong> %(text_confirm5)s <strong>%(mode)s</strong>.
                            <br/><br/>
                            %(schedule_msg)s
                            %(text_confirm7)s (<strong>%(num_rec)s</strong> %(text_confirm8)s)
                            <table>
                            <tr>
                                <td><input type="submit" value="Confirm" class="adminbutton" %(confirm_disabled)s></td>
                                <td><input type="button" value="Cancel" class="adminbutton" onclick="window.location.href = './'"></td>
                            </tr>
                            </table>
                        </div>
                        """ % {'text_confirm1': _('You are about to submit a'),
                               'text_confirm2': _('file with name'),
                               'text_confirm3': _('and content'),
                               'text_confirm4': _('This file will be uploaded with priority'),
                               'text_confirm5': _('and in mode'),
                               'text_confirm7': _('Do you want to submit the changes?'),
                               'text_confirm8': _('record(s) will be affected'),
                               'schedule_msg' : display_schedule and schedule_msg or '',
                               'filetype': filetype,
                               'filename': file_name,
                               'marcxml_textarea': marcxml_textarea,
                               'filecontent': metafile,
                               'priority_num': priority,
                               'email_logs_to': email_logs_to,
                               'priority_txt': priority_map[priority],
                               'mode': mode,
                               'num_rec': metafile.count('<record>'),
                               'submit_date': submit_date,
                               'submit_time': submit_time,
                               'errors_textarea': errors_textarea,
                               'confirm_disabled': errors_upload and 'DISABLED style="background:grey;"' or ''}
        body_content += """</div></form> """
        return body_content
Beispiel #10
0
    def send(self, req, form):
        """
        Sends the message.

        Possible form keys:
        @param msg_to_user: comma separated usernames.
        @type msg_to_user: 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 msg_send_year: year to send this message on.
        @type msg_send_year: int
        @param_msg_send_month: month to send this message on
        @type msg_send_month: year
        @param_msg_send_day: day to send this message on
        @type msg_send_day: int
        @param results_field: value determining which results field to display.
                              See CFG_WEBMESSAGE_RESULTS_FIELD in
                              webmessage_config.py.
        @param names_to_add: list of usernames to add to
                             msg_to_user / group.
        @type names_to_add: list of strings
        @param search_pattern: will search for users/groups with this pattern.
        @type search_pattern: string
        @param add_values: if 1 users_to_add will be added to msg_to_user
                           field.
        @type add_values: int
        @param *button: which button was pressed.
        @param ln: language.
        @type ln: string
        @return: body.
        """
        argd = wash_urlargd(
            form, {
                'msg_to_user': (str, ""),
                'msg_to_group': (str, ""),
                'msg_subject': (str, ""),
                'msg_body': (str, ""),
                'msg_send_year': (int, 0),
                'msg_send_month': (int, 0),
                'msg_send_day': (int, 0),
                'results_field': (str, CFG_WEBMESSAGE_RESULTS_FIELD['NONE']),
                'names_selected': (list, []),
                'search_pattern': (str, ""),
                'send_button': (str, ""),
                'search_user': (str, ""),
                'search_group': (str, ""),
                'add_user': (str, ""),
                'add_group': (str, ""),
            })
        # Check if user is logged
        uid = getUid(req)
        _ = gettext_set_language(argd['ln'])
        if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
            return page_not_authorized(req, "%s/yourmessages/send" % \
                                             (CFG_SITE_URL,),
                                       navmenuid="yourmessages")
        elif uid == -1 or isGuestUser(uid):
            return redirect_to_url(
                req, "%s/youraccount/login%s" %
                (CFG_SITE_SECURE_URL,
                 make_canonical_urlargd(
                     {
                         'referer':
                         "%s/yourmessages/send%s" %
                         (CFG_SITE_SECURE_URL, make_canonical_urlargd(
                             argd, {})),
                         "ln":
                         argd['ln']
                     }, {})))

        user_info = collect_user_info(req)
        if not user_info['precached_usemessages']:
            return page_not_authorized(req, "../", \
                                       text = _("You are not authorized to use messages."))

        if argd['send_button']:
            (body, title, navtrail) = perform_request_send(
                uid=uid,
                msg_to_user=argd['msg_to_user'],
                msg_to_group=argd['msg_to_group'],
                msg_subject=escape_html(argd['msg_subject']),
                msg_body=escape_email_quoted_text(argd['msg_body']),
                msg_send_year=argd['msg_send_year'],
                msg_send_month=argd['msg_send_month'],
                msg_send_day=argd['msg_send_day'],
                ln=argd['ln'])
        else:
            title = _('Write a message')
            navtrail = get_navtrail(argd['ln'], title)
            if argd['search_user']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['USER']
            elif argd['search_group']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']
            add_values = 0
            if argd['add_group'] or argd['add_user']:
                add_values = 1
            body = perform_request_write_with_search(
                uid=uid,
                msg_to_user=argd['msg_to_user'],
                msg_to_group=argd['msg_to_group'],
                msg_subject=escape_html(argd['msg_subject']),
                msg_body=escape_email_quoted_text(argd['msg_body']),
                msg_send_year=argd['msg_send_year'],
                msg_send_month=argd['msg_send_month'],
                msg_send_day=argd['msg_send_day'],
                names_selected=argd['names_selected'],
                search_pattern=argd['search_pattern'],
                results_field=argd['results_field'],
                add_values=add_values,
                ln=argd['ln'])
        return page(title=title,
                    body=body,
                    navtrail=navtrail,
                    uid=uid,
                    lastupdated=__lastupdated__,
                    req=req,
                    language=argd['ln'],
                    navmenuid="yourmessages",
                    secure_page_p=1)
Beispiel #11
0
    def send(self, req, form):
        """
        Sends the message.

        Possible form keys:
        @param msg_to_user: comma separated usernames.
        @type msg_to_user: 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 msg_send_year: year to send this message on.
        @type msg_send_year: int
        @param_msg_send_month: month to send this message on
        @type msg_send_month: year
        @param_msg_send_day: day to send this message on
        @type msg_send_day: int
        @param results_field: value determining which results field to display.
                              See CFG_WEBMESSAGE_RESULTS_FIELD in
                              webmessage_config.py.
        @param names_to_add: list of usernames to add to
                             msg_to_user / group.
        @type names_to_add: list of strings
        @param search_pattern: will search for users/groups with this pattern.
        @type search_pattern: string
        @param add_values: if 1 users_to_add will be added to msg_to_user
                           field.
        @type add_values: int
        @param *button: which button was pressed.
        @param ln: language.
        @type ln: string
        @return: body.
        """
        argd = wash_urlargd(form, {'msg_to_user': (str, ""),
                                   'msg_to_group': (str, ""),
                                   'msg_subject': (str, ""),
                                   'msg_body': (str, ""),
                                   'msg_send_year': (int, 0),
                                   'msg_send_month': (int, 0),
                                   'msg_send_day': (int, 0),
                                   'results_field': (str,
                                        CFG_WEBMESSAGE_RESULTS_FIELD['NONE']),
                                   'names_selected': (list, []),
                                   'search_pattern': (str, ""),
                                   'send_button': (str, ""),
                                   'search_user': (str, ""),
                                   'search_group': (str, ""),
                                   'add_user': (str, ""),
                                   'add_group': (str, ""),
                                   })
        # Check if user is logged
        uid = getUid(req)
        _ = gettext_set_language(argd['ln'])
        if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
            return page_not_authorized(req, "%s/yourmessages/send" % \
                                             (CFG_SITE_URL,),
                                       navmenuid="yourmessages")
        elif uid == -1 or isGuestUser(uid):
            return redirect_to_url(req, "%s/youraccount/login%s" % (
                CFG_SITE_SECURE_URL,
                make_canonical_urlargd({
                    'referer' : "%s/yourmessages/send%s" % (
                        CFG_SITE_SECURE_URL,
                        make_canonical_urlargd(argd, {})),
                    "ln" : argd['ln']}, {})))

        user_info = collect_user_info(req)
        if not user_info['precached_usemessages']:
            return page_not_authorized(req, "../", \
                                       text = _("You are not authorized to use messages."))

        if argd['send_button']:
            (body, title, navtrail) = perform_request_send(
                            uid=uid,
                            msg_to_user=argd['msg_to_user'],
                            msg_to_group=argd['msg_to_group'],
                            msg_subject=escape_html(argd['msg_subject']),
                            msg_body=escape_email_quoted_text(argd['msg_body']),
                            msg_send_year=argd['msg_send_year'],
                            msg_send_month=argd['msg_send_month'],
                            msg_send_day=argd['msg_send_day'],
                            ln=argd['ln'])
        else:
            title = _('Write a message')
            navtrail = get_navtrail(argd['ln'], title)
            if argd['search_user']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['USER']
            elif argd['search_group']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']
            add_values = 0
            if argd['add_group'] or argd['add_user']:
                add_values = 1
            body = perform_request_write_with_search(
                            uid=uid,
                            msg_to_user=argd['msg_to_user'],
                            msg_to_group=argd['msg_to_group'],
                            msg_subject=escape_html(argd['msg_subject']),
                            msg_body=escape_email_quoted_text(argd['msg_body']),
                            msg_send_year=argd['msg_send_year'],
                            msg_send_month=argd['msg_send_month'],
                            msg_send_day=argd['msg_send_day'],
                            names_selected=argd['names_selected'],
                            search_pattern=argd['search_pattern'],
                            results_field=argd['results_field'],
                            add_values=add_values,
                            ln=argd['ln'])
        return page(title       = title,
                    body        = body,
                    navtrail    = navtrail,
                    uid         = uid,
                    lastupdated = __lastupdated__,
                    req         = req,
                    language    = argd['ln'],
                    navmenuid   = "yourmessages",
                    secure_page_p=1)