def format_element(bfo):
    """
    List the 'featured' records
    """
    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    featured_records = get_featured_records(journal_name)
    lines = []
    for (recid, img_url) in featured_records:
        featured_record = BibFormatObject(recid)
        if bfo.lang == 'fr':
            title = featured_record.field('246_1a')
            if title == '':
                # No French translation, get it in English
                title = featured_record.field('245__a')
        else:
            title = featured_record.field('245__a')

        lines.append('''
        <a href="%s/record/%s?ln=%s" style="display:block">
            <img src="%s" alt="" width="100" class="phr" />
            %s
        </a>
        ''' % (CFG_SITE_URL, recid, bfo.lang, img_url, title))

    return  '<br/><br/>'.join(lines)
def format(bfo):
    """
    List the 'featured' records
    """
    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    featured_records = get_featured_records(journal_name)
    lines = []
    for (recid, img_url) in featured_records:
        featured_record = BibFormatObject(recid)
        if bfo.lang == 'fr':
            title = featured_record.field('246_1a')
            if title == '':
                # No French translation, get it in English
                title = featured_record.field('245__a')
        else:
            title = featured_record.field('245__a')

        lines.append('''
        <a href="%s/record/%s?ln=%s" style="display:block">
            <img src="%s" alt="" width="100" class="phr" />
            %s
        </a>
        ''' % (CFG_SITE_URL, recid, bfo.lang, img_url, title))

    return  '<br/><br/>'.join(lines)
def perform_feature_record(journal_name, recid, img_url="", action="", ln=CFG_SITE_LANG):
    """
    Interface to feature a record

    Used to list, add and remove featured records of the journal.

    Parameters:
        journal_name  -  the journal for which the article is featured
               recid  -  the record affected by 'action'
             img_url  -  the URL to image displayed with given record
                         (only when action == 'add')
              action  -  One of ['', 'add', 'askremove', _('Remove'), _('Cancel')]
                  ln  -  language
    """
    _ = gettext_set_language(ln)

    if action == "add":
        result = add_featured_record(journal_name, recid, img_url)
        if result == 0:
            msg = """<span style="color:#0f0">Successfully featured
            <a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a>.
        Go to the <a href="%(CFG_SITE_URL)s/journal/%(name)s">%(name)s journal</a> to
        see the result.</span>""" % {
                "CFG_SITE_URL": CFG_SITE_URL,
                "CFG_SITE_RECORD": CFG_SITE_RECORD,
                "name": journal_name,
                "recid": recid,
            }
        elif result == 1:
            msg = (
                """<span style="color:#f00"><a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a> is already featured. Choose another one or remove it first.</span>"""
                % {"CFG_SITE_URL": CFG_SITE_URL, "CFG_SITE_RECORD": CFG_SITE_RECORD, "recid": recid}
            )
        else:
            msg = """<span style="color:#f00">Record could not be featured. Check file permission.</span>"""

        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(
            ln=ln, journal_name=journal_name, featured_records=featured_records, msg=msg
        )
    elif action == "askremove":
        msg = """<fieldset style="display:inline;margin-left:auto;margin-right:auto;">
        <legend>Remove featured record</legend><span style="color:#f00">Are you sure you want to remove <a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a> from the list of featured record?
        <form action="%(CFG_SITE_URL)s/admin/webjournal/webjournaladmin.py/feature_record">
        <input type="hidden" name="journal_name" value="%(name)s" />
        <input type="hidden" name="recid" value="%(recid)s" />
        <input class="formbutton" type="submit" name="action" value="%(remove)s" />
        <input class="formbutton" type="submit" name="action" value="%(cancel)s" />
        </form></span></fieldset>""" % {
            "CFG_SITE_URL": CFG_SITE_URL,
            "CFG_SITE_RECORD": CFG_SITE_RECORD,
            "name": journal_name,
            "recid": recid,
            "cancel": _("Cancel"),
            "remove": _("Remove"),
        }
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(
            ln=ln, journal_name=journal_name, featured_records=featured_records, msg=msg
        )
    elif action == _("Remove"):
        result = remove_featured_record(journal_name, recid)
        msg = """<span style="color:#f00"><a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">Record %(recid)s</a>
        has been removed.</span>""" % {
            "CFG_SITE_URL": CFG_SITE_URL,
            "CFG_SITE_RECORD": CFG_SITE_RECORD,
            "recid": recid,
        }
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(
            ln=ln, journal_name=journal_name, featured_records=featured_records, msg=msg
        )
    else:
        msg = (
            """Here you can choose which records from the %s should
        be featured on the journal webpage."""
            % CFG_SITE_NAME
        )
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(
            ln=ln, journal_name=journal_name, featured_records=featured_records, msg=msg
        )
Example #4
0
def perform_feature_record(journal_name,
                           recid,
                           img_url='',
                           action='',
                           ln=CFG_SITE_LANG):
    """
    Interface to feature a record

    Used to list, add and remove featured records of the journal.

    Parameters:
        journal_name  -  the journal for which the article is featured
               recid  -  the record affected by 'action'
             img_url  -  the URL to image displayed with given record
                         (only when action == 'add')
              action  -  One of ['', 'add', 'askremove', _('Remove'), _('Cancel')]
                  ln  -  language
    """
    _ = gettext_set_language(ln)

    if action == 'add':
        result = add_featured_record(journal_name, recid, img_url)
        if result == 0:
            msg = '''<span style="color:#0f0">Successfully featured
            <a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a>.
        Go to the <a href="%(CFG_SITE_URL)s/journal/%(name)s">%(name)s journal</a> to
        see the result.</span>''' % {
                'CFG_SITE_URL': CFG_SITE_URL,
                'CFG_SITE_RECORD': CFG_SITE_RECORD,
                'name': journal_name,
                'recid': recid
            }
        elif result == 1:
            msg = '''<span style="color:#f00"><a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a> is already featured. Choose another one or remove it first.</span>''' % \
                  {'CFG_SITE_URL': CFG_SITE_URL,
                   'CFG_SITE_RECORD': CFG_SITE_RECORD,
                   'recid': recid}
        else:
            msg = '''<span style="color:#f00">Record could not be featured. Check file permission.</span>'''

        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(ln=ln,
                                             journal_name=journal_name,
                                             featured_records=featured_records,
                                             msg=msg)
    elif action == 'askremove':
        msg = '''<fieldset style="display:inline;margin-left:auto;margin-right:auto;">
        <legend>Remove featured record</legend><span style="color:#f00">Are you sure you want to remove <a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a> from the list of featured record?
        <form action="%(CFG_SITE_URL)s/admin/webjournal/webjournaladmin.py/feature_record">
        <input type="hidden" name="journal_name" value="%(name)s" />
        <input type="hidden" name="recid" value="%(recid)s" />
        <input class="formbutton" type="submit" name="action" value="%(remove)s" />
        <input class="formbutton" type="submit" name="action" value="%(cancel)s" />
        </form></span></fieldset>''' % \
            {'CFG_SITE_URL': CFG_SITE_URL,
             'CFG_SITE_RECORD': CFG_SITE_RECORD,
             'name': journal_name,
             'recid': recid,
             'cancel': _("Cancel"),
             'remove': _("Remove")}
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(ln=ln,
                                             journal_name=journal_name,
                                             featured_records=featured_records,
                                             msg=msg)
    elif action == _("Remove"):
        result = remove_featured_record(journal_name, recid)
        msg = '''<span style="color:#f00"><a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">Record %(recid)s</a>
        has been removed.</span>''' % \
            {'CFG_SITE_URL': CFG_SITE_URL,
             'CFG_SITE_RECORD': CFG_SITE_RECORD,
             'recid': recid}
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(ln=ln,
                                             journal_name=journal_name,
                                             featured_records=featured_records,
                                             msg=msg)
    else:
        msg = '''Here you can choose which records from the %s should
        be featured on the journal webpage.''' % CFG_SITE_NAME
        featured_records = get_featured_records(journal_name)
        return wjt.tmpl_admin_feature_record(ln=ln,
                                             journal_name=journal_name,
                                             featured_records=featured_records,
                                             msg=msg)