def tmpl_display_menu(self, ln=CFG_SITE_LANG, ref=""):
     """ Displays menu with all upload options """
     _ = gettext_set_language(ln)
     body_content = """
     <table>
         <td>0.&nbsp;<small>%(upload_open_link)s%(text1)s%(upload_close_link)s</small></td>
         <td>1.&nbsp;<small>%(docupload_open_link)s%(text2)s%(docupload_close_link)s</small></td>
         <td>2.&nbsp;<small>%(history_open_link)s%(text3)s%(history_close_link)s</small></td>
         <td>3.&nbsp;<small>%(daemon_open_link)s%(text4)s%(daemon_close_link)s</small></td>
         </tr>
     </table>
     """ % { 'upload_open_link': not ref == "metadata" and "<a href=\"%s/batchuploader/metadata?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'upload_close_link': not ref == "metadata" and "</a>" or "",
             'text1': _("Metadata batch upload"),
             'docupload_open_link': not ref == "documents" and "<a href=\"%s/batchuploader/documents?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'docupload_close_link': not ref == "documents" and "</a>" or "",
             'text2': _("Document batch upload"),
             'history_open_link': not ref == "history" and "<a href=\"%s/batchuploader/history?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'history_close_link': not ref == "history" and "</a>" or "",
             'text3': _("Upload history"),
             'daemon_open_link': not ref == "daemon" and "<a href=\"%s/batchuploader/daemon?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'daemon_close_link': not ref == "daemon" and "</a>" or "",
             'text4': _("Daemon monitor")
            }
     return addadminbox("<b>Menu</b>", [body_content])
示例#2
0
 def tmpl_display_menu(self, ln=CFG_SITE_LANG, ref=""):
     """ Displays menu with all upload options """
     _ = gettext_set_language(ln)
     body_content = """
     <table>
         <td>0.&nbsp;<small>%(upload_open_link)s%(text1)s%(upload_close_link)s</small></td>
         <td>1.&nbsp;<small>%(docupload_open_link)s%(text2)s%(docupload_close_link)s</small></td>
         <td>2.&nbsp;<small>%(history_open_link)s%(text3)s%(history_close_link)s</small></td>
         <td>3.&nbsp;<small>%(daemon_open_link)s%(text4)s%(daemon_close_link)s</small></td>
         </tr>
     </table>
     """ % { 'upload_open_link': not ref == "metadata" and "<a href=\"%s/batchuploader/metadata?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'upload_close_link': not ref == "metadata" and "</a>" or "",
             'text1': _("Metadata batch upload"),
             'docupload_open_link': not ref == "documents" and "<a href=\"%s/batchuploader/documents?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'docupload_close_link': not ref == "documents" and "</a>" or "",
             'text2': _("Document batch upload"),
             'history_open_link': not ref == "history" and "<a href=\"%s/batchuploader/history?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'history_close_link': not ref == "history" and "</a>" or "",
             'text3': _("Upload history"),
             'daemon_open_link': not ref == "daemon" and "<a href=\"%s/batchuploader/daemon?ln=%s\">" % (CFG_SITE_URL, ln) or "",
             'daemon_close_link': not ref == "daemon" and "</a>" or "",
             'text4': _("Daemon monitor")
            }
     return addadminbox("<b>Menu</b>", [body_content])
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.')
    def tmpl_admin_index(self, ln):
        """
        Index page of admin interface
        """
        _ = gettext_set_language(ln)

        out = '<ol>'

        pending_linkback_count = len(get_all_linkbacks(status=CFG_WEBLINKBACK_STATUS['PENDING']))
        stat_pending_text = ""
        if pending_linkback_count > 0:
            stat_pending_text = ' <span class="moreinfo"> ('
            if pending_linkback_count == 1:
                stat_pending_text += "%s pending linkback request" % pending_linkback_count
            elif pending_linkback_count > 1:
                stat_pending_text += "%s pending linkback requests"% pending_linkback_count
            stat_pending_text += ')</span>'
        out += '<li><a href="%(siteURL)s/admin/weblinkback/weblinkbackadmin.py/linkbacks?ln=%(ln)s&amp;status=%(status)s">%(label)s</a>%(stat)s</li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'status': CFG_WEBLINKBACK_STATUS['PENDING'],
                 'label': _("Pending Linkbacks"),
                 'stat': stat_pending_text}

        out += '<li><a href="%(siteURL)s/linkbacks?ln=%(ln)s">%(label)s</a></li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'label': _("Recent Linkbacks")}

        out += '<li><a href="%(siteURL)s/admin/weblinkback/weblinkbackadmin.py/lists?ln=%(ln)s&amp;returncode=%(returnCode)s">%(label)s</a></li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'returnCode': CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK'],
                 'label': _("Linkback Whitelist/Blacklist Manager")}


        out += '</ol>'
        from invenio.bibrankadminlib import addadminbox
        return addadminbox('<b>%s</b>'% _("Menu"), [out])
    def tmpl_admin_index(self, ln):
        """
        Index page of admin interface
        """
        _ = gettext_set_language(ln)

        out = '<ol>'

        pending_linkback_count = len(
            get_all_linkbacks(status=CFG_WEBLINKBACK_STATUS['PENDING']))
        stat_pending_text = ""
        if pending_linkback_count > 0:
            stat_pending_text = ' <span class="moreinfo"> ('
            if pending_linkback_count == 1:
                stat_pending_text += "%s pending linkback request" % pending_linkback_count
            elif pending_linkback_count > 1:
                stat_pending_text += "%s pending linkback requests" % pending_linkback_count
            stat_pending_text += ')</span>'
        out += '<li><a href="%(siteURL)s/admin/weblinkback/weblinkbackadmin.py/linkbacks?ln=%(ln)s&amp;status=%(status)s">%(label)s</a>%(stat)s</li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'status': CFG_WEBLINKBACK_STATUS['PENDING'],
                 'label': _("Pending Linkbacks"),
                 'stat': stat_pending_text}

        out += '<li><a href="%(siteURL)s/linkbacks?ln=%(ln)s">%(label)s</a></li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'label': _("Recent Linkbacks")}

        out += '<li><a href="%(siteURL)s/admin/weblinkback/weblinkbackadmin.py/lists?ln=%(ln)s&amp;returncode=%(returnCode)s">%(label)s</a></li>' % \
                {'siteURL': CFG_SITE_URL,
                 'ln': ln,
                 'returnCode': CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK'],
                 'label': _("Linkback Whitelist/Blacklist Manager")}

        out += '</ol>'
        from invenio.bibrankadminlib import addadminbox
        return addadminbox('<b>%s</b>' % _("Menu"), [out])
def perform_request_display_list(return_code,
                                 url_field_value,
                                 ln=CFG_SITE_LANG):
    """
    Display a list
    @param return_code: might indicate errors from a previous action, of CFG_WEBLINKBACK_ACTION_RETURN_CODE
    @param url_field_value: value of the url text field
    """
    _ = gettext_set_language(ln)
    urls = get_urls()
    entries = []
    for url in urls:
        entries.append(
            ('<a href="%s">%s</a>' % (cgi.escape(url[0]), cgi.escape(url[0])),
             url[1].lower(),
             '<a href="moderatelist?url=%s&action=%s&ln=%s">%s</a>' %
             (urllib.quote(
                 url[0]), CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'],
              ln, CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'].lower())))

    header = ['URL', 'List', '']

    error_message = ""
    if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']:
        error_message = _("Unknown error")
        if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE']:
            error_message = _("The URL already exists in one of the lists")
        elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE[
                'INVALID_ACTION']:
            error_message = _("Invalid action")
        elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT']:
            error_message = _("Invalid URL, might contain spaces")

    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>%(whitelist)s</dt>
    <dd>%(whitelistText)s</dd>
    <dt>%(blacklist)s</dt>
    <dd>%(blacklistText)s</dd>
    <dt>%(explanation)s</dt>

    </dl>
    <table class="admin_wvar" cellspacing="0">
    <tr><td>
    <form action='moderatelist'>
    URL:
    <input type="text" name="url" value="%(url)s" />
    <input type="hidden" name="action" value="%(action)s" />
    <select name="listtype" size="1">
    <option value=whitelist>whitelist</option>
    <option value=blacklist>blacklist</option>
    </select>
    <input type="submit" class="adminbutton" value="%(buttonText)s">
    </form>
    </td></tr></table>
    """ % {
        'whitelist':
        _('Whitelist'),
        'whitelistText':
        _('linkback requests from these URLs will be approved automatically.'),
        'blacklist':
        _('Blacklist'),
        'blacklistText':
        _('linkback requests from these URLs will be refused automatically, no data will be saved.'
          ),
        'explanation':
        _('All URLs in these lists are checked for containment (infix) in any linkback request URL. A whitelist match has precedence over a blacklist match.'
          ),
        'url':
        cgi.escape(url_field_value),
        'action':
        CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'],
        'buttonText':
        _('Add URL'),
        '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>%s</i>" % _('There are no URLs in both lists.')

    return addadminbox(
        '<b>%s</b>' %
        _("Reduce the amount of future pending linkback requests"), [out])
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.')
def perform_request_display_list(return_code, url_field_value, ln=CFG_SITE_LANG):
    """
    Display a list
    @param return_code: might indicate errors from a previous action, of CFG_WEBLINKBACK_ACTION_RETURN_CODE
    @param url_field_value: value of the url text field
    """
    _ = gettext_set_language(ln)
    urls = get_urls()
    entries = []
    for url in urls:
        entries.append(('<a href="%s">%s</a>' % (cgi.escape(url[0]), cgi.escape(url[0])),
                        url[1].lower(),
                        '<a href="moderatelist?url=%s&action=%s&ln=%s">%s</a>' % (urllib.quote(url[0]), CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'], ln, CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'].lower())))

    header = ['URL', 'List', '']

    error_message = ""
    if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']:
        error_message = _("Unknown error")
        if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE']:
            error_message = _("The URL already exists in one of the lists")
        elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION']:
            error_message = _("Invalid action")
        elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT']:
            error_message = _("Invalid URL, might contain spaces")

    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>%(whitelist)s</dt>
    <dd>%(whitelistText)s</dd>
    <dt>%(blacklist)s</dt>
    <dd>%(blacklistText)s</dd>
    <dt>%(explanation)s</dt>

    </dl>
    <table class="admin_wvar" cellspacing="0">
    <tr><td>
    <form action='moderatelist'>
    URL:
    <input type="text" name="url" value="%(url)s" />
    <input type="hidden" name="action" value="%(action)s" />
    <select name="listtype" size="1">
    <option value=whitelist>whitelist</option>
    <option value=blacklist>blacklist</option>
    </select>
    <input type="submit" class="adminbutton" value="%(buttonText)s">
    </form>
    </td></tr></table>
    """ % {'whitelist': _('Whitelist'),
           'whitelistText': _('linkback requests from these URLs will be approved automatically.'),
           'blacklist': _('Blacklist'),
           'blacklistText': _('linkback requests from these URLs will be refused automatically, no data will be saved.'),
           'explanation': _('All URLs in these lists are checked for containment (infix) in any linkback request URL. A whitelist match has precedence over a blacklist match.'),
           'url': cgi.escape(url_field_value),
           'action': CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'],
           'buttonText': _('Add URL'),
           '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>%s</i>" % _('There are no URLs in both lists.')

    return addadminbox('<b>%s</b>'% _("Reduce the amount of future pending linkback requests"), [out])