Esempio n. 1
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
    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
Esempio n. 3
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
    def test_create_linkback2(self):
        """weblinkback - create linkback with URL title"""
        recid = 42
        argd = {'url': 'URL',
                'title': 'My title',
                'excerpt': CFG_WEBLINKBACK_SUBSCRIPTION_DEFAULT_ARGUMENT_NAME,
                'blog_name': 'Test Blog',
                'id': CFG_WEBLINKBACK_SUBSCRIPTION_DEFAULT_ARGUMENT_NAME,
                'source': CFG_WEBLINKBACK_SUBSCRIPTION_DEFAULT_ARGUMENT_NAME,
                }

        linkbackid = create_trackback(recid, argd['url'], argd['title'], argd['excerpt'], argd['blog_name'], argd['id'], argd['source'], self.user_info)
        self.assertEqual(10 + self._max_id_lnkENTRY, linkbackid)

        linkback = get_all_linkbacks(recid=recid)[5]
        self.assertEqual(linkbackid, linkback[0])
        self.assertEqual(argd['url'], linkback[1])
        self.assertEqual(recid, linkback[2])
        self.assertEqual(CFG_WEBLINKBACK_TYPE['TRACKBACK'], linkback[4])
        self.assertEqual(CFG_WEBLINKBACK_STATUS['PENDING'], linkback[5])

        url = CFG_SITE_URL + '/%s/42/linkbacks/' % CFG_SITE_RECORD
        expected_texts = ('Linkbacks to review: 6', 'Linkbacks: 0')
        for text in expected_texts:
            self.assertEqual([], test_web_page_content(url,
                                                       username='******',
                                                       expected_text=text))

        approve_linkback(linkbackid, self.user_info)

        linkback = get_all_linkbacks(recid=recid)[5]
        self.assertEqual(linkbackid, linkback[0])
        self.assertEqual(argd['url'], linkback[1])
        self.assertEqual(recid, linkback[2])
        self.assertEqual(CFG_WEBLINKBACK_TYPE['TRACKBACK'], linkback[4])
        self.assertEqual(CFG_WEBLINKBACK_STATUS['APPROVED'], linkback[5])

        url_titles = self.get_all_from_table("lnkENTRYURLTITLE")
        self.assertEqual(1, len(url_titles))
        self.assertEqual(argd['url'], url_titles[0][1])
        self.assertEqual(argd['title'], url_titles[0][2])
        self.assertEqual(1, url_titles[0][3])
        self.assertEqual(argd['title'], get_url_title(argd['url']))

        self.assertEqual(0, len(get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['OLD'])))
        self.assertEqual(0, len(get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['NEW'])))
        self.assertEqual(1, len(get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['MANUALLY_SET'])))

        url = CFG_SITE_URL + '/%s/42/linkbacks/' % CFG_SITE_RECORD
        expected_texts = ('Linkbacks to review: 5', 'Linkbacks: 1')
        for text in expected_texts:
            self.assertEqual([], test_web_page_content(url,
                                                       username='******',
                                                       expected_text=text))
Esempio n. 5
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
    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
    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
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.')
Esempio n. 9
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.')