Ejemplo n.º 1
0
def perform_list_alerts(uid, ln=CFG_SITE_LANG):
    """perform_list_alerts display the list of alerts for the connected user"""
    # set variables
    out = ""

    # query the database
    query = """ SELECT q.id, q.urlargs,
                       a.id_basket, b.name,
                       a.alert_name, a.frequency,a.notification,
                       DATE_FORMAT(a.date_creation,'%%Y-%%m-%%d %%H:%%i:%%s'),
                       DATE_FORMAT(a.date_lastrun,'%%Y-%%m-%%d %%H:%%i:%%s')
                FROM user_query_basket a LEFT JOIN query q ON a.id_query=q.id
                                         LEFT JOIN bskBASKET b ON a.id_basket=b.id
                WHERE a.id_user=%s
                ORDER BY a.alert_name ASC """
    res = run_sql(query, (uid,))
    alerts = []
    for (qry_id, qry_args,
         bsk_id, bsk_name,
         alrt_name, alrt_frequency, alrt_notification, alrt_creation, alrt_last_run) in res:
        try:
            if not qry_id:
                raise StandardError("""\
Warning: I have detected a bad alert for user id %d.
It seems one of his/her alert queries was deleted from the 'query' table.
Please check this and delete it if needed.
Otherwise no problem, I'm continuing with the other alerts now.
Here are all the alerts defined by this user: %s""" % (uid, repr(res)))
            alerts.append({
                 'queryid' : qry_id,
                 'queryargs' : qry_args,
                 'textargs' : get_textual_query_info_from_urlargs(qry_args, ln=ln),
                 'userid' : uid,
                 'basketid' : bsk_id,
                 'basketname' : bsk_name,
                 'alertname' : alrt_name,
                 'frequency' : alrt_frequency,
                 'notification' : alrt_notification,
                 'created' : convert_datetext_to_dategui(alrt_creation),
                 'lastrun' : convert_datetext_to_dategui(alrt_last_run)
                 })
        except StandardError:
            register_exception(alert_admin=True)

    # link to the "add new alert" form
    out = webalert_templates.tmpl_list_alerts(ln=ln, alerts=alerts,
                                              guest=isGuestUser(uid),
                                              guesttxt=warning_guest_user(type="alerts", ln=ln))
    return out
Ejemplo n.º 2
0
    def tmpl_get_latest_linkbacks(self, latest_linkbacks, ln):
        """
        Display approved latest added linkbacks to display
        @param latest_linkbacks: a list of lists of linkbacks
        """
        result = ''

        for i in range(len(latest_linkbacks)):
            day_group = latest_linkbacks[i]

            date = day_group[0][6]
            date_day_month = convert_datetext_to_dategui(str(date))[:6]

            result += self.tmpl_heading(date_day_month)
            for j in range(len(day_group)):
                current_linkback = day_group[j]
                link_type = current_linkback[4]
                url = str(current_linkback[1])
                recordid = current_linkback[2]
                result += '<font class="rankscoreinfo"><a>(%s)&nbsp;</a></font>' % link_type
                result += '<small>'
                result += '<a href="%s">%s</a> links to ' % (cgi.escape(url), cgi.escape(get_url_title(url)))
                result += format_record(recID=recordid, of='hs', ln=ln)
                result += '</small>'
                result += '<br>'
            result += '<br>'
        return result
Ejemplo n.º 3
0
 def test_convert_bad_to_dategui_sk(self):
     """dateutils - conversion of bad text date into Slovak GUI date"""
     datetext = "2006-02-AA 18:36:01"
     dategui_sk_expected = "nepríst."
     dategui_sk = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='sk')
     self.assertEqual(dategui_sk, dategui_sk_expected)
Ejemplo n.º 4
0
 def test_convert_good_to_dategui_sk(self):
     """dateutils - conversion of good text date into Slovak GUI date"""
     datetext = "2006-07-16 18:36:01"
     dategui_sk_expected = "16 júl 2006, 18:36"
     dategui_sk = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='sk')
     self.assertEqual(dategui_sk, dategui_sk_expected)
Ejemplo n.º 5
0
 def test_convert_bad_to_dategui_en(self):
     """dateutils - conversion of bad text date into English GUI date"""
     datetext = "2006-02-AA 18:36:01"
     dategui_sk_expected = "N/A"
     dategui_sk = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='en')
     self.assertEqual(dategui_sk, dategui_sk_expected)
Ejemplo n.º 6
0
    def tmpl_linkback_tuple(self, linkbacks, ln):
        """
        Display a linkback
        @param linkbacks: collection of linkbacks: [(linkback_id,
                                                     origin_url,
                                                     recid,
                                                     additional_properties,
                                                     type,
                                                     status,
                                                     insert_time)]
        """
        _ = gettext_set_language(ln)

        out = '<table width="95%" style="display: inline";>'

        for current_linkback in linkbacks:
            url = current_linkback[1]
            out += '''<tr><td><font class="rankscoreinfo"><a>(%(type)s)&nbsp;</a></font><small>&nbsp;<a href="%(origin_url)s" target="_blank">%(page_title)s</a>&nbsp;%(submit_date)s</small></td></tr>''' % {
                       'type': current_linkback[4],
                       'origin_url': cgi.escape(url),
                       'page_title': cgi.escape(get_url_title(url)),
                       'submit_date': '(submitted on <i>' + convert_datetext_to_dategui(str(current_linkback[6])) + '</i>)'}

        out += '</table>'
        return out
Ejemplo n.º 7
0
 def test_convert_bad_to_dategui_en(self):
     """dateutils - conversion of bad text date into English GUI date"""
     datetext = "2006-02-AA 18:36:01"
     dategui_en_expected = "N/A"
     dategui_en = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='en')
     self.assertEqual(dategui_en, dategui_en_expected)
Ejemplo n.º 8
0
 def test_convert_good_to_dategui_sk(self):
     """dateutils - conversion of good text date into Slovak GUI date"""
     datetext = "2006-07-16 18:36:01"
     dategui_sk_expected = "16 júl 2006, 18:36"
     dategui_sk = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='sk')
     self.assertEqual(dategui_sk, dategui_sk_expected)
Ejemplo n.º 9
0
 def test_convert_good_to_dategui_en(self):
     """dateutils - conversion of good text date into English GUI date
     """
     datetext = "2006-07-16 18:36:01"
     dategui_en_expected = "16 Jul 2006, 18:36"
     dategui_en = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='en')
     self.assertEqual(dategui_en, dategui_en_expected)
Ejemplo n.º 10
0
 def test_convert_good_to_dategui_en(self):
     """dateutils - conversion of good text date into English GUI date
     """
     datetext = "2006-07-16 18:36:01"
     dategui_en_expected = "16 Jul 2006, 18:36"
     dategui_en = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln='en')
     self.assertEqual(dategui_en, dategui_en_expected)
Ejemplo n.º 11
0
 def test_convert_bad_to_dategui_sk(self):
     """dateutils - conversion of bad text date into Slovak GUI date"""
     from invenio.base.i18n import gettext_set_language
     ln = 'sk'
     _ = gettext_set_language(ln)
     datetext = "2006-02-AA 18:36:01"
     dategui_sk_expected = _('N/A')
     dategui_sk = dateutils.convert_datetext_to_dategui(datetext,
                                                        ln=ln)
     self.assertEqual(dategui_sk, dategui_sk_expected)
Ejemplo n.º 12
0
 def _format_date(date):
     """
     This is a special Jinja2 filter that will call
     convert_datetext_to_dategui to print a human friendly date.
     """
     if isinstance(date, datetime):
         return convert_datestruct_to_dategui(
             date.timetuple(),
             getattr(g, 'ln', app.config['CFG_SITE_LANG'])).decode('utf-8')
     return convert_datetext_to_dategui(
         date, getattr(g, 'ln', app.config['CFG_SITE_LANG'])).decode('utf-8')
Ejemplo n.º 13
0
    def _format_date(date):
        """
        Format a date into a human friendly format.

        It uses :py:func:`invenio.utils.date.convert_datetext_to_dategui`
        """
        if isinstance(date, datetime):
            return convert_datestruct_to_dategui(
                date.timetuple(),
                getattr(g, 'ln', app.config['CFG_SITE_LANG'])).decode('utf-8')
        return convert_datetext_to_dategui(
            date, getattr(g, 'ln', app.config['CFG_SITE_LANG'])
        ).decode('utf-8')
Ejemplo n.º 14
0
    def _format_date(date):
        """
        Format a date into a human friendly format.

        It uses :py:func:`invenio.utils.date.convert_datetext_to_dategui`
        """
        if isinstance(date, datetime):
            return convert_datestruct_to_dategui(
                date.timetuple(),
                getattr(g, 'ln', app.config['CFG_SITE_LANG'])).decode('utf-8')
        return convert_datetext_to_dategui(
            date, getattr(g, 'ln',
                          app.config['CFG_SITE_LANG'])).decode('utf-8')
Ejemplo n.º 15
0
def split_revid(revid, dateformat=""):
    """Split revid and return tuple (recid, revdate).
    Optional dateformat can be datetext or dategui.

    """
    recid, revdate = re_revid_split.search(revid).groups()
    if dateformat:
        datetext = "%s-%s-%s %s:%s:%s" % re_revdate_split.search(revdate).groups()
        if dateformat == "datetext":
            revdate = datetext
        elif dateformat == "dategui":
            revdate = convert_datetext_to_dategui(datetext, secs=True)
    return recid, revdate
Ejemplo n.º 16
0
def split_revid(revid, dateformat=''):
    """Split revid and return tuple (recid, revdate).
    Optional dateformat can be datetext or dategui.

    """
    recid, revdate = re_revid_split.search(revid).groups()
    if dateformat:
        datetext = '%s-%s-%s %s:%s:%s' % re_revdate_split.search(
            revdate).groups()
        if dateformat == 'datetext':
            revdate = datetext
        elif dateformat == 'dategui':
            revdate = convert_datetext_to_dategui(datetext, secs=True)
    return recid, revdate
Ejemplo n.º 17
0
def perform_request_display_linkbacks(status, return_code, ln=CFG_SITE_LANG):
    """
    Display linkbacks
    @param status: of CFG_WEBLINKBACK_STATUS, currently only CFG_WEBLINKBACK_STATUS['PENDING'] is supported
    """
    _ = gettext_set_language(ln)
    if status == CFG_WEBLINKBACK_STATUS['PENDING']:
        linkbacks = get_all_linkbacks(status=status, order=CFG_WEBLINKBACK_ORDER_BY_INSERTION_TIME['DESC'])
        entries = []

        for (linkbackid, origin_url, recid, additional_properties, linkback_type, linkback_status, insert_time) in linkbacks: # pylint: disable=W0612
            moderation_prefix = '<a href="moderatelinkback?action=%%s&linkbackid=%s&ln=%s">%%s</a>' % (linkbackid, ln)
            entries.append((linkback_type,
                            format_record(recID=recid, of='hs', ln=ln),
                            '<a href="%s">%s</a>' % (cgi.escape(origin_url), cgi.escape(get_url_title(origin_url))),
                            convert_datetext_to_dategui(str(insert_time)),
                            moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['APPROVE'], 'Approve') + " / " + moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['REJECT'], 'Reject')))

        header = ['Linkback type', 'Record', 'Origin', 'Submitted on', '']

        error_message = ""
        if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']:
            error_message = _("Unknown error")
            if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION']:
                error_message = _("Invalid action")

        error_message_html = ""
        if error_message != "":
            error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>"

        out = """
        <dl>
        %(error_message)s
        <dt>%(heading)s</dt>
        <dd>%(description)s</dd>
        </dl>
        """ % {'heading': _("Pending linkbacks"),
               'description': _("these linkbacks are not visible to users, they must be approved or rejected."),
               'error_message': error_message_html}

        if entries:
            out += tupletotable(header=header, tuple=entries, highlight_rows_p=True,
                                alternate_row_colors_p=True)
        else:
            out += "<i>There are no %s linkbacks.</i>" % status.lower()

        return addadminbox('<b>%s</b>'% _("Reduce the amount of currently pending linkback requests"), [out])
    else:
        return "<i>%s</i>" % _('Currently only pending linkbacks are supported.')
Ejemplo n.º 18
0
    def tmpl_display_jobs(self, jobs, language=CFG_SITE_LANG):
        """
        Creates page for displaying of all the jobs.

        @param jobs: list of the jobs that have to be displayed
        @param language: language of the page
        """

        _ = gettext_set_language(language)

        table_rows = ""
        for current_job in jobs:
            # convert last run date into text proper to be shown to the user
            datetext = convert_datestruct_to_datetext(
                current_job.get_last_run())
            last_run = convert_datetext_to_dategui(datetext, language)
            # obtain text corresponding to the frequency of execution
            frequency = current_job.get_frequency()
            frequency_text = self._get_frequency_text(frequency)

            row = """<tr>
            <td><input type="checkbox" name="selected_jobs" value="%(job_id)s"></input></td>
            <td><a href="%(edit_job_url)s?id=%(job_id)s&ln=%(language)s">%(name)s</a></td>
            <td>%(frequency)s</td>
            <td>%(last_run)s</td>
            </tr>""" % self._html_escape_dictionary(
                {
                    "edit_job_url": self._EDIT_JOB_URL,
                    "job_id": current_job.get_id(),
                    "name": current_job.get_name(),
                    "frequency": frequency_text,
                    "language": language,
                    "last_run": last_run
                })
            table_rows += row

        select_all_none_row = """
            <tr><td colspan="4">
                <small>%s</small><br><br>
            </td></tr>""" \
            %(self._get_select_all_none_html("jobsForm",
                                               "selected_jobs",
                                               language))
        table_rows += select_all_none_row

        buttons_row = """<tr>
            <td colspan="3">
                <input type="Submit" name="run_button" value="%(label_run)s" class="formbutton">
                <input type="Submit" name="delete_button" value="%(label_delete)s" class="formbutton">
            </td>
            <td align="right">
                <input type="Submit" name="new_button" value="%(label_new)s" class="formbutton">
            </td>
        </tr>""" % {
            "label_run": _("Run"),
            "label_delete": _("Delete"),
            "label_new": _("New")
        }
        table_rows += buttons_row

        body = """
<form method="post" name="jobsForm">

<table class="spacedcells">
    <th></th>
    <th>%(label_name)s</th>
    <th>%(label_frequency)s</th>
    <th>%(label_last_run)s</th>
    %(table_rows)s
</table>

</form>
        """ % {
            "table_rows": table_rows,
            "label_name": _("Name"),
            "label_frequency": _("Run"),
            "label_last_run": _("Last run")
        }

        return body
Ejemplo n.º 19
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
Ejemplo n.º 20
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")}
Ejemplo n.º 21
0
    def tmpl_linkback_tuple_admin(self, url_approve_prefix, url_reject_prefix, linkbacks, ln):
        """
        Display linkbacks with admin approve/reject features
        @param linkbacks: collection of linkbacks: [(linkback_id,
                                                     origin_url,
                                                     recid,
                                                     additional_properties,
                                                     type,
                                                     status,
                                                     insert_time)]
        """
        _ = gettext_set_language(ln)
        out = ''

        for current_linkback in linkbacks:
            linkbackid = current_linkback[0]
            url = current_linkback[1]

            out += '<div style="margin-bottom:20px;background:#F9F9F9;border:1px solid #DDD">'
            out += '<div style="background-color:#EEE;padding:2px;font-size:small">&nbsp;%s</div>' % (_('Submitted on') + ' <i>' + convert_datetext_to_dategui(str(current_linkback[6])) + '</i>:')
            out += '<br />'
            out += '<blockquote>'
            out += '''<font class="rankscoreinfo"><a>(%(type)s)&nbsp;</a></font><small>&nbsp;<a href="%(origin_url)s" target="_blank">%(page_title)s</a></small>''' % {
                       'type': current_linkback[4],
                       'origin_url': cgi.escape(url),
                       'page_title': cgi.escape(get_url_title(url))}
            out += '</blockquote>'
            out += '<br />'
            out += '<div style="float:right">'
            out += '<small>'
            out += '''<a style="color:#8B0000;" href="%s&linkbackid=%s">%s</a>''' % (url_approve_prefix, linkbackid, _("Approve"))
            out += '&nbsp;|&nbsp;'
            out += '''<a style="color:#8B0000;" href="%s&linkbackid=%s">%s</a>''' % (url_reject_prefix, linkbackid, _("Reject"))
            out += '</small>'
            out += '</div>'
            out += '</div>'

        return out
Ejemplo n.º 22
0
def perform_list_alerts(uid, ln=CFG_SITE_LANG):
    """perform_list_alerts display the list of alerts for the connected user"""
    # set variables
    out = ""

    # query the database
    query = """ SELECT q.id, q.urlargs,
                       a.id_basket, b.name,
                       a.alert_name, a.frequency,a.notification,
                       DATE_FORMAT(a.date_creation,'%%Y-%%m-%%d %%H:%%i:%%s'),
                       DATE_FORMAT(a.date_lastrun,'%%Y-%%m-%%d %%H:%%i:%%s')
                FROM user_query_basket a LEFT JOIN query q ON a.id_query=q.id
                                         LEFT JOIN bskBASKET b ON a.id_basket=b.id
                WHERE a.id_user=%s
                ORDER BY a.alert_name ASC """
    res = run_sql(query, (uid, ))
    alerts = []
    for (qry_id, qry_args, bsk_id, bsk_name, alrt_name, alrt_frequency,
         alrt_notification, alrt_creation, alrt_last_run) in res:
        try:
            if not qry_id:
                raise StandardError("""\
Warning: I have detected a bad alert for user id %d.
It seems one of his/her alert queries was deleted from the 'query' table.
Please check this and delete it if needed.
Otherwise no problem, I'm continuing with the other alerts now.
Here are all the alerts defined by this user: %s""" % (uid, repr(res)))
            alerts.append({
                'queryid':
                qry_id,
                'queryargs':
                qry_args,
                'textargs':
                get_textual_query_info_from_urlargs(qry_args, ln=ln),
                'userid':
                uid,
                'basketid':
                bsk_id,
                'basketname':
                bsk_name,
                'alertname':
                alrt_name,
                'frequency':
                alrt_frequency,
                'notification':
                alrt_notification,
                'created':
                convert_datetext_to_dategui(alrt_creation),
                'lastrun':
                convert_datetext_to_dategui(alrt_last_run)
            })
        except StandardError:
            register_exception(alert_admin=True)

    # link to the "add new alert" form
    out = webalert_templates.tmpl_list_alerts(ln=ln,
                                              alerts=alerts,
                                              guest=isGuestUser(uid),
                                              guesttxt=warning_guest_user(
                                                  type="alerts", ln=ln))
    return out
Ejemplo n.º 23
0
    def tmpl_display_jobs(self, jobs, language = CFG_SITE_LANG):
        """
        Creates page for displaying of all the jobs.

        @param jobs: list of the jobs that have to be displayed
        @param language: language of the page
        """

        _ = gettext_set_language(language)

        table_rows = ""
        for current_job in jobs:
            # convert last run date into text proper to be shown to the user
            datetext = convert_datestruct_to_datetext(current_job.get_last_run())
            last_run = convert_datetext_to_dategui(datetext, language)
            # obtain text corresponding to the frequency of execution
            frequency = current_job.get_frequency()
            frequency_text = self._get_frequency_text(frequency)

            row = """<tr>
            <td><input type="checkbox" name="selected_jobs" value="%(job_id)s"></input></td>
            <td><a href="%(edit_job_url)s?id=%(job_id)s&ln=%(language)s">%(name)s</a></td>
            <td>%(frequency)s</td>
            <td>%(last_run)s</td>
            </tr>""" %  self._html_escape_dictionary({
                        "edit_job_url" : self._EDIT_JOB_URL,
                        "job_id" : current_job.get_id(),
                        "name" : current_job.get_name(),
                        "frequency" : frequency_text,
                        "language" : language,
                        "last_run" : last_run
                        })
            table_rows += row

        select_all_none_row = """
            <tr><td colspan="4">
                <small>%s</small><br><br>
            </td></tr>""" \
            %(self._get_select_all_none_html("jobsForm",
                                               "selected_jobs",
                                               language))
        table_rows += select_all_none_row

        buttons_row = """<tr>
            <td colspan="3">
                <input type="Submit" name="run_button" value="%(label_run)s" class="formbutton">
                <input type="Submit" name="delete_button" value="%(label_delete)s" class="formbutton">
            </td>
            <td align="right">
                <input type="Submit" name="new_button" value="%(label_new)s" class="formbutton">
            </td>
        </tr>""" % {
                        "label_run" : _("Run"),
                        "label_delete" : _("Delete"),
                        "label_new" : _("New")
                        }
        table_rows += buttons_row

        body = """
<form method="post" name="jobsForm">

<table class="spacedcells">
    <th></th>
    <th>%(label_name)s</th>
    <th>%(label_frequency)s</th>
    <th>%(label_last_run)s</th>
    %(table_rows)s
</table>

</form>
        """ % {
            "table_rows" : table_rows,
            "label_name" : _("Name"),
            "label_frequency" : _("Run"),
            "label_last_run" : _("Last run")
            }

        return body
Ejemplo n.º 24
0
def perform_request_display_linkbacks(status, return_code, ln=CFG_SITE_LANG):
    """
    Display linkbacks
    @param status: of CFG_WEBLINKBACK_STATUS, currently only CFG_WEBLINKBACK_STATUS['PENDING'] is supported
    """
    _ = gettext_set_language(ln)
    if status == CFG_WEBLINKBACK_STATUS['PENDING']:
        linkbacks = get_all_linkbacks(
            status=status,
            order=CFG_WEBLINKBACK_ORDER_BY_INSERTION_TIME['DESC'])
        entries = []

        for (linkbackid, origin_url, recid, additional_properties,
             linkback_type, linkback_status, insert_time) in linkbacks:  # pylint: disable=W0612
            moderation_prefix = '<a href="moderatelinkback?action=%%s&linkbackid=%s&ln=%s">%%s</a>' % (
                linkbackid, ln)
            entries.append((
                linkback_type, format_record(recID=recid, of='hs',
                                             ln=ln), '<a href="%s">%s</a>' %
                (cgi.escape(origin_url), cgi.escape(
                    get_url_title(origin_url))),
                convert_datetext_to_dategui(str(insert_time)),
                moderation_prefix %
                (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['APPROVE'], 'Approve')
                + " / " + moderation_prefix %
                (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['REJECT'], 'Reject')))

        header = ['Linkback type', 'Record', 'Origin', 'Submitted on', '']

        error_message = ""
        if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']:
            error_message = _("Unknown error")
            if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE[
                    'INVALID_ACTION']:
                error_message = _("Invalid action")

        error_message_html = ""
        if error_message != "":
            error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>"

        out = """
        <dl>
        %(error_message)s
        <dt>%(heading)s</dt>
        <dd>%(description)s</dd>
        </dl>
        """ % {
            'heading':
            _("Pending linkbacks"),
            'description':
            _("these linkbacks are not visible to users, they must be approved or rejected."
              ),
            'error_message':
            error_message_html
        }

        if entries:
            out += tupletotable(header=header,
                                tuple=entries,
                                highlight_rows_p=True,
                                alternate_row_colors_p=True)
        else:
            out += "<i>There are no %s linkbacks.</i>" % status.lower()

        return addadminbox(
            '<b>%s</b>' %
            _("Reduce the amount of currently pending linkback requests"),
            [out])
    else:
        return "<i>%s</i>" % _(
            'Currently only pending linkbacks are supported.')