Пример #1
0
def perform_index(ln=CFG_SITE_LANG, journal_name=None, action=None, uid=None):
    """
    Index page

    Lists the journals, and offers options to edit them, delete them
    or add new journal.

    Parameters:
        journal_name  -  the journal affected by action, if any
              action  -  one of ['', 'askDelete', _('Delete'), _('Cancel')]
                  ln  -  language
                 uid  -  user id
    """
    _ = gettext_set_language(ln)

    msg = None
    if action == "askDelete" and journal_name is not None:
        msg = """<fieldset style="display:inline;margin-left:auto;margin-right:auto;">
        <legend>Delete Journal Configuration</legend><span style="color:#f00">Are you sure you want to delete the configuration of %(journal_name)s?
        <form action="%(CFG_SITE_URL)s/admin/webjournal/webjournaladmin.py">
        <input type="hidden" name="journal_name" value="%(journal_name)s" />
        <input class="formbutton" type="submit" name="action" value="%(delete)s" />
        <input class="formbutton" type="submit" name="action" value="%(cancel)s" />
        </form></span></fieldset>""" % {
            "CFG_SITE_URL": CFG_SITE_URL,
            "journal_name": journal_name,
            "delete": _("Delete"),
            "cancel": _("Cancel"),
        }

    if action == _("Delete") and journal_name is not None:
        # User confirmed and clicked on "Delete" button
        remove_journal(journal_name)

    journals = get_journals_ids_and_names()
    # Only keep journal that user can view or edit
    journals = [
        (
            journal_info,
            acc_authorize_action(uid, "cfgwebjournal", name=journal_info["journal_name"], with_editor_rights="yes")[0]
            == 0,
        )
        for journal_info in journals
        if acc_authorize_action(uid, "cfgwebjournal", name=journal_info["journal_name"])[0] == 0
    ]
    return wjt.tmpl_admin_index(ln=ln, journals=journals, msg=msg)
Пример #2
0
def perform_index(ln=CFG_SITE_LANG, journal_name=None, action=None, uid=None):
    """
    Index page

    Lists the journals, and offers options to edit them, delete them
    or add new journal.

    Parameters:
        journal_name  -  the journal affected by action, if any
              action  -  one of ['', 'askDelete', _('Delete'), _('Cancel')]
                  ln  -  language
                 uid  -  user id
    """
    _ = gettext_set_language(ln)

    msg = None
    if action == 'askDelete' and journal_name is not None:
        msg = '''<fieldset style="display:inline;margin-left:auto;margin-right:auto;">
        <legend>Delete Journal Configuration</legend><span style="color:#f00">Are you sure you want to delete the configuration of %(journal_name)s?
        <form action="%(CFG_SITE_URL)s/admin/webjournal/webjournaladmin.py">
        <input type="hidden" name="journal_name" value="%(journal_name)s" />
        <input class="formbutton" type="submit" name="action" value="%(delete)s" />
        <input class="formbutton" type="submit" name="action" value="%(cancel)s" />
        </form></span></fieldset>''' % {
            'CFG_SITE_URL': CFG_SITE_URL,
            'journal_name': journal_name,
            'delete': _("Delete"),
            'cancel': _("Cancel")
        }

    if action == _("Delete") and journal_name is not None:
        # User confirmed and clicked on "Delete" button
        remove_journal(journal_name)

    journals = get_journals_ids_and_names()
    # Only keep journal that user can view or edit
    journals = [(journal_info, acc_authorize_action(uid,
                                                    'cfgwebjournal',
                                                    name=journal_info['journal_name'],
                                                    with_editor_rights='yes')[0] == 0) \
                 for journal_info in journals \
                 if acc_authorize_action(uid,
                                         'cfgwebjournal',
                                         name=journal_info['journal_name'])[0] == 0]
    return wjt.tmpl_admin_index(ln=ln, journals=journals, msg=msg)
 def test_get_journals_ids_and_names(self):
     """webjournal - returns the list of existing journals IDs and names"""
     ids_names = wju.get_journals_ids_and_names()
     self.assertEqual(ids_names[0].values(), [1, 'AtlantisTimes'])
     self.assertEqual(ids_names[0].keys(), ['journal_id', 'journal_name'])
Пример #4
0
def format_element(bfo, only_public_records=1, sites="linkedin,twitter,facebook,google,delicious,sciencewise"):
    """
    Return a snippet of JavaScript needed for displaying a bookmark toolbar

    @param only_public_records: if set to 1 (the default), prints the box only
        if the record is public (i.e. if it belongs to the root colletion and is
        accessible to the world).

    @param sites: which sites to enable (default is 'linkedin,twitter,facebook,google,delicious,sciencewise'). This should be a
        comma separated list of strings.
        Valid values are available on:
            <http://keith-wood.name/bookmark.html#sites>
        Note that 'sciencewise' is an ad-hoc service that will be displayed
        only in case the record has an arXiv reportnumber and will always
        be displayed last.
    """
    if int(only_public_records) and not record_public_p(bfo.recID):
        return ""

    sitelist = sites.split(',')
    sitelist = [site.strip().lower() for site in sitelist]

    sciencewise = False
    if 'sciencewise' in sitelist:
        sciencewise = True
        sitelist.remove('sciencewise')

    sites_js = ", ".join("'%s'" % site for site in sitelist)

    title = bfo.field('245__a')
    description = bfo.field('520__a')

    sciencewise_script = ""
    if sciencewise:
        reportnumber = get_arxiv_reportnumber(bfo)
        sciencewise_url = ""
        if reportnumber:
            sciencewise_url = create_sciencewise_url(reportnumber)
        if not sciencewise_url and CFG_CERN_SITE:
            sciencewise_url = create_sciencewise_url(bfo.recID, cds=True)
        if sciencewise_url:
            sciencewise_script = """\
$.bookmark.addSite('sciencewise', 'ScienceWise.info', '%(siteurl)s/img/sciencewise.png', 'en', 'bookmark', '%(url)s');
$('#bookmark_sciencewise').bookmark({sites: ['sciencewise']});
""" % {
                'siteurl': CFG_SITE_URL,
                'url': sciencewise_url.replace("'", r"\'"),
            }

    url = '%(siteurl)s/%(record)s/%(recid)s' % \
          {'recid': bfo.recID,
           'record': CFG_SITE_RECORD,
           'siteurl': CFG_SITE_URL}

    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    if journal_name and \
       (journal_name in [info.get('journal_name', '') for info in get_journals_ids_and_names()]):
        # We are displaying a WebJournal article: URL is slightly different
        url = make_journal_url(bfo.user_info['uri'])

    return """\
<!-- JQuery Bookmark Button BEGIN -->
<div id="bookmark"></div><div id="bookmark_sciencewise"></div>
<style type="text/css">
    #bookmark_sciencewise, #bookmark { float: left; }
    #bookmark_sciencewise li { padding: 2px; width: 25px}
    #bookmark_sciencewise ul, #bookmark ul { list-style-image: none; }
</style>
<script type="text/javascript" src="%(siteurl)s/js/jquery.bookmark.min.js"></script>
<style type="text/css">@import "%(siteurl)s/css/jquery.bookmark.css";</style>
<script type="text/javascript">// <![CDATA[
    %(sciencewise)s
    $('#bookmark').bookmark({
        sites: [%(sites_js)s],
        icons: '%(siteurl)s/img/bookmarks.png',
        url: '%(url)s',
        addEmail: true,
        title: "%(title)s",
        description: "%(description)s"
    });
// ]]>
</script>
<!-- JQuery Bookmark Button END -->
""" % {
        'siteurl': CFG_SITE_URL,
        'sciencewise': sciencewise_script,
        'title': escape_javascript_string(title,
                                          escape_for_html=False,
                                          escape_CDATA=True),
        'description': escape_javascript_string(description,
                                                escape_for_html=False,
                                                escape_CDATA=True),
        'sites_js': sites_js,
        'url': url,
    }
 def test_get_journals_ids_and_names(self):
     """webjournal - returns the list of existing journals IDs and names"""
     ids_names = wju.get_journals_ids_and_names()
     self.assertEqual(ids_names[0].values(), [1, 'AtlantisTimes'])
     self.assertEqual(ids_names[0].keys(), ['journal_id', 'journal_name'])