Esempio n. 1
0
def format_element(bfo, us="yes"):
    """
    returns dategui for the best available date, looking in several
    locations for it (date, eprint, journal, date added)

    @param bfo: BibFormatObject for current record
    @type nfo: object

    @param us: us style date Mon dd, yyyy (default), otherwise dd mon yyyy
    @type us: str

    @return: string of formatted date, or None of no date is found.
    """
    datestruct = get_date(bfo)
    if datestruct:
        dummy_time = (0, 0, 44, 2, 320, 0)
        # if we have all 3 use dategui:
        if len(datestruct) == 3:
            datestruct = tuple(datestruct[0:3]) + dummy_time
            date = re.sub(",\s00:00$", "", convert_datestruct_to_dategui(datestruct))
            if us == "yes":
                return re.sub(r" 0(\d),", r" \1,", (re.sub(r"(\d{2})\s(\w{3})", r"\2 \1,", date)))
            else:
                return date
        elif len(datestruct) == 2:
            # if we have only the month, pass the converter a dummy day and
            # then strip it
            datestruct = tuple(datestruct[0:2]) + (1,) + dummy_time
            date = re.sub(r",\s00:00$", "", convert_datestruct_to_dategui(datestruct))
            return re.sub(r"\d+\s+(\w+)", r"\1", date)
        elif len(datestruct) == 1:
            # only the year
            return datestruct[0]
    return None
Esempio n. 2
0
def format(bfo, us="yes"):
    """
    returns dategui for the best available date, looking in several
    locations for it (date, eprint, journal, date added)
    @params us us style date Mon dd, yyyy (default)  otherwise dd mon yyyy
    """
    datestruct = get_date(bfo)

    dummy_time = (0, 0, 44, 2, 320, 0)
    # if we have all 3 use dategui:
    if len(datestruct) == 3:
        datestruct = tuple(datestruct[0:3]) + dummy_time
        date = re.sub(",\s00:00$", "", convert_datestruct_to_dategui(datestruct))
        if us == "yes":
            return re.sub(r" 0(\d),", r" \1,", (re.sub(r"(\d{2})\s(\w{3})", r"\2 \1,", date)))
        else:
            return date
    elif len(datestruct) == 2:
        # if we have only the month, pass the converter a dummy day and
        # the strip it
        datestruct = tuple(datestruct[0:2]) + (1,) + dummy_time
        print datestruct
        date = re.sub(r",\s00:00$", "", convert_datestruct_to_dategui(datestruct))
        return re.sub(r"\d+\s+(\w+)", r"\1", date)
    elif len(datestruct) == 1:
        # only the year
        return datestruct[0]
    return None
def format_element(bfo, us="yes"):
    """
    returns dategui for the best available date, looking in several
    locations for it (date, eprint, journal, date added)
    @params us us style date Mon dd, yyyy (default)  otherwise dd mon yyyy
    """
    datestruct = get_date(bfo)

    dummy_time = (0, 0, 44, 2, 320, 0)
    #if we have all 3 use dategui:
    if len(datestruct) == 3:
        datestruct = tuple(datestruct[0:3]) + dummy_time
        date = re.sub(',\s00:00$', '',
                      convert_datestruct_to_dategui(datestruct))
        if us == "yes":
            return (re.sub(r' 0(\d),', r' \1,',
                           (re.sub(r'(\d{2})\s(\w{3})', r'\2 \1,', date))))
        else:
            return (date)
    elif len(datestruct) == 2:
        # if we have only the month, pass the converter a dummy day and
        # the strip it
        datestruct = tuple(datestruct[0:2]) + (1, ) + dummy_time
        print datestruct
        date = re.sub(r',\s00:00$', '',
                      convert_datestruct_to_dategui(datestruct))
        return re.sub(r'\d+\s+(\w+)', r'\1', date)
    elif len(datestruct) == 1:
        #only the year
        return datestruct[0]
    return None
Esempio n. 4
0
    def tmpl_bibdocfile_filelist(self, ln, recid, name, version, md,
                                 superformat, subformat, nice_size_f,
                                 description):
        """
        Displays a file in the file list.

        Parameters:

          - 'ln' *string* - The language to display the interface in

          - 'recid' *int* - The id of the record

          - 'name' *string* - The name of the file

          - 'version' *string* - The version

          - 'md' *datetime* - the modification date

          - 'superformat' *string* - The display superformat

          - 'subformat' *string* - The display subformat

          - 'nice_size_f' *string* - The nice_size of the file

          - 'description' *string* - The description that might have been associated
          to the particular file
        """

        # load the right message language
        _ = gettext_set_language(ln)

        urlbase = '%s/%s/%s/files/%s' % (CFG_SITE_URL, CFG_SITE_RECORD, recid,
                                         '%s%s' %
                                         (cgi.escape(name, True), superformat))

        urlargd = {'version': version}
        if subformat:
            urlargd['subformat'] = subformat

        link_label = '%s%s' % (name, superformat)
        if subformat:
            link_label += ' (%s)' % subformat

        link = create_html_link(urlbase, urlargd, cgi.escape(link_label))

        return """<tr>
                    <td valign="top">
                      <small>%(link)s</small>
                    </td>
                    <td valign="top">
                      <font size="-2" color="green">[%(nice_size)s]</font>
                      <font size="-2"><em>%(md)s</em>
                    </td>
                    <td valign="top"><em>%(description)s</em></td>
                    </tr>""" % {
            'link': link,
            'nice_size': nice_size_f,
            'md': convert_datestruct_to_dategui(md.timetuple(), ln),
            'description': cgi.escape(description),
        }
    def tmpl_bibdocfile_filelist(self, ln, recid, name, version, md, superformat, subformat, nice_size_f, description):
        """
        Displays a file in the file list.

        Parameters:

          - 'ln' *string* - The language to display the interface in

          - 'recid' *int* - The id of the record

          - 'name' *string* - The name of the file

          - 'version' *string* - The version

          - 'md' *datetime* - the modification date

          - 'superformat' *string* - The display superformat

          - 'subformat' *string* - The display subformat

          - 'nice_size_f' *string* - The nice_size of the file

          - 'description' *string* - The description that might have been associated
          to the particular file
        """

        # load the right message language
        _ = gettext_set_language(ln)

        urlbase = '%s/%s/%s/files/%s' % (
            CFG_SITE_URL,
            CFG_SITE_RECORD,
            recid,
            '%s%s' % (cgi.escape(name, True), superformat))

        urlargd = {'version' : version}
        if subformat:
            urlargd['subformat'] = subformat

        link_label = '%s%s' % (name, superformat)
        if subformat:
            link_label += ' (%s)' % subformat

        link = create_html_link(urlbase, urlargd, cgi.escape(link_label))

        return """<tr>
                    <td valign="top">
                      <small>%(link)s</small>
                    </td>
                    <td valign="top">
                      <font size="-2" color="green">[%(nice_size)s]</font>
                      <font size="-2"><em>%(md)s</em>
                    </td>
                    <td valign="top"><em>%(description)s</em></td>
                    </tr>""" % {
                      'link' : link,
                      'nice_size' : nice_size_f,
                      'md' : convert_datestruct_to_dategui(md.timetuple(), ln),
                      'description' : cgi.escape(description),
                    }
Esempio n. 6
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(),
                                              g.ln).decode('utf-8')
     return convert_datetext_to_dategui(date, g.ln).decode('utf-8')
    def update_webpage_cache(self):
        """Create collection page header, navtrail, body (including left and right stripes) and footer, and
           call write_cache_file() afterwards to update the collection webpage cache."""

        ## precalculate latest additions for non-aggregate
        ## collections (the info is ln and as independent)
        if self.dbquery and not CFG_WEBSEARCH_I18N_LATEST_ADDITIONS:
            self.create_latest_additions_info()

        ## do this for each language:
        for lang, lang_fullname in language_list_long():

            # but only if some concrete language was not chosen only:
            if lang in task_get_option("language", [lang]):

                if self.dbquery and CFG_WEBSEARCH_I18N_LATEST_ADDITIONS:
                    self.create_latest_additions_info(ln=lang)

                # load the right message language
                _ = gettext_set_language(lang)

                ## first, update navtrail:
                for aas in CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES:
                    self.write_cache_file("navtrail-as=%s-ln=%s" % (aas, lang),
                                          self.create_navtrail_links(aas, lang))

                ## second, update page body:
                for aas in CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES: # do light, simple and advanced search pages:
                    body = websearch_templates.tmpl_webcoll_body(
                        ln=lang, collection=self.name,
                        te_portalbox = self.create_portalbox(lang, 'te'),
                        searchfor = self.create_searchfor(aas, lang),
                        np_portalbox = self.create_portalbox(lang, 'np'),
                        narrowsearch = self.create_narrowsearch(aas, lang, 'r'),
                        focuson = self.create_narrowsearch(aas, lang, "v") + \
                        self.create_external_collections_box(lang),
                        instantbrowse = self.create_instant_browse(aas=aas, ln=lang),
                        ne_portalbox = self.create_portalbox(lang, 'ne')
                        )
                    self.write_cache_file("body-as=%s-ln=%s" % (aas, lang), body)
                ## third, write portalboxes:
                self.write_cache_file("portalbox-tp-ln=%s" % lang, self.create_portalbox(lang, "tp"))
                self.write_cache_file("portalbox-te-ln=%s" % lang, self.create_portalbox(lang, "te"))
                self.write_cache_file("portalbox-lt-ln=%s" % lang, self.create_portalbox(lang, "lt"))
                self.write_cache_file("portalbox-rt-ln=%s" % lang, self.create_portalbox(lang, "rt"))
                ## fourth, write 'last updated' information:
                self.write_cache_file("last-updated-ln=%s" % lang,
                                      convert_datestruct_to_dategui(time.localtime(),
                                                                    ln=lang))
        return
Esempio n. 8
0
    def update_webpage_cache(self):
        """Create collection page header, navtrail, body (including left and right stripes) and footer, and
           call write_cache_file() afterwards to update the collection webpage cache."""

        ## precalculate latest additions for non-aggregate
        ## collections (the info is ln and as independent)
        if self.dbquery and not CFG_WEBSEARCH_I18N_LATEST_ADDITIONS:
            self.create_latest_additions_info()

        ## do this for each language:
        for lang, lang_fullname in language_list_long():

            # but only if some concrete language was not chosen only:
            if lang in task_get_option("language", [lang]):

                if self.dbquery and CFG_WEBSEARCH_I18N_LATEST_ADDITIONS:
                    self.create_latest_additions_info(ln=lang)

                # load the right message language
                _ = gettext_set_language(lang)

                ## first, update navtrail:
                for aas in CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES:
                    self.write_cache_file("navtrail-as=%s-ln=%s" % (aas, lang),
                                          self.create_navtrail_links(aas, lang))

                ## second, update page body:
                for aas in CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES: # do light, simple and advanced search pages:
                    body = websearch_templates.tmpl_webcoll_body(
                        ln=lang, collection=self.name,
                        te_portalbox = self.create_portalbox(lang, 'te'),
                        searchfor = self.create_searchfor(aas, lang),
                        np_portalbox = self.create_portalbox(lang, 'np'),
                        narrowsearch = self.create_narrowsearch(aas, lang, 'r'),
                        focuson = self.create_narrowsearch(aas, lang, "v") + \
                        self.create_external_collections_box(lang),
                        instantbrowse = self.create_instant_browse(aas=aas, ln=lang),
                        ne_portalbox = self.create_portalbox(lang, 'ne')
                        )
                    self.write_cache_file("body-as=%s-ln=%s" % (aas, lang), body)
                ## third, write portalboxes:
                self.write_cache_file("portalbox-tp-ln=%s" % lang, self.create_portalbox(lang, "tp"))
                self.write_cache_file("portalbox-te-ln=%s" % lang, self.create_portalbox(lang, "te"))
                self.write_cache_file("portalbox-lt-ln=%s" % lang, self.create_portalbox(lang, "lt"))
                self.write_cache_file("portalbox-rt-ln=%s" % lang, self.create_portalbox(lang, "rt"))
                ## fourth, write 'last updated' information:
                self.write_cache_file("last-updated-ln=%s" % lang,
                                      convert_datestruct_to_dategui(time.localtime(),
                                                                    ln=lang))
        return
Esempio n. 9
0
    def update_webpage_cache(self, lang):
        """Create collection page header, navtrail, body (including left and right stripes) and footer, and
           call write_cache_file() afterwards to update the collection webpage cache."""

        ## precalculate latest additions for non-aggregate
        ## collections (the info is ln and as independent)
        if self.dbquery:
            if CFG_WEBSEARCH_I18N_LATEST_ADDITIONS:
                self.create_latest_additions_info(ln=lang)
            else:
                self.create_latest_additions_info()

        # load the right message language
        _ = gettext_set_language(lang)

        # create dictionary with data
        cache = {
            "te_portalbox": self.create_portalbox(lang, "te"),
            "np_portalbox": self.create_portalbox(lang, "np"),
            "ne_portalbox": self.create_portalbox(lang, "ne"),
            "tp_portalbox": self.create_portalbox(lang, "tp"),
            "lt_portalbox": self.create_portalbox(lang, "lt"),
            "rt_portalbox": self.create_portalbox(lang, "rt"),
            "last_updated": convert_datestruct_to_dategui(time.localtime(), ln=lang),
        }
        for aas in CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES:  # do light, simple and advanced search pages:
            cache["navtrail_%s" % aas] = self.create_navtrail_links(aas, lang)
            cache["searchfor_%s" % aas] = self.create_searchfor(aas, lang)
            cache["narrowsearch_%s" % aas] = self.create_narrowsearch(aas, lang, "r")
            cache["focuson_%s" % aas] = self.create_narrowsearch(aas, lang, "v") + self.create_external_collections_box(
                lang
            )
            cache["instantbrowse_%s" % aas] = self.create_instant_browse(aas=aas, ln=lang)
        # write cache file
        self.write_cache_file("%s-ln=%s" % (self.name, lang), cache)

        return cache
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://cdsware.cern.ch/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
          'siteurl' : CFG_SITE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,

          }
        return out
Esempio n. 11
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page

        custom_variables = ""
        record_collection = ""
        page_type = ""

        parsed_uri = urlparse(req.unparsed_uri)

        # HACK: I know it's horrible code. :-(
        record_page_match = re.match(
            "^/record/(?P<recid>[0-9]+)(/(?P<page_type>.+)?)?$",
            parsed_uri.path)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(
                record_page_match.group('recid'))
            page_type = record_page_match.group('page_type') or 'detailed'
        if re.match("^/search/?$", parsed_uri.path):
            cc = parse_qs(parsed_uri.query).get('cc', [CFG_SITE_NAME])
            record_collection = cc.pop()
        collection_page_match = re.match(
            "^/$|^/collection/(?P<collection>.+)/?$", parsed_uri.path)
        if collection_page_match:
            record_collection = collection_page_match.groupdict().get(
                'collection', CFG_SITE_NAME)
        if record_collection:
            custom_variables = """\
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          %(collection_name)s, // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': js_escape(record_collection)
            }

        if page_type:
            custom_variables += """\
_paq.push(['setCustomVariable',
          2,
          "Type",
          %(page_type)s,
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          %(page_collection_type)s,
          "page"
          ]);
          """ % {
                'page_type': js_escape(page_type),
                'page_collection_type':
                js_escape(record_collection + page_type)
            }

        out = """\
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
""" % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': '*****@*****.**',
            'msg_search': _("Search"),
            'msg_help': _("Help"),
            'msg_terms': _("Terms of use"),
            'msg_privacy': _("Privacy policy"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Problems/Questions to"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': self.trim_version(CFG_VERSION),
            'pagefooteradd': pagefooteradd,
        }
        if not isUserAdmin(collect_user_info(req)):
            out += """\
<!-- Piwik -->
<script type="text/javascript">
  try {
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="//piwik.inspirehep.net/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 8]);
        %(custom_variables)s
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();}
    catch(err) {
        (function() {
            var img = document.createElement('img');
            img.src = '//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1';
            document.body.appendChild(img);
    })();
    }
</script>
<noscript><p><img src="//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
""" % {
                'custom_variables': custom_variables
            }

        out += """\
</body>
</html>
"""
        return out
Esempio n. 12
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None, pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != "$Date$":
            if lastupdated.startswith("$Date: ") or lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(convert_datecvs_to_datestruct(lastupdated), ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
            "siteurl": CFG_SITE_URL,
            "sitesecureurl": CFG_SITE_SECURE_URL,
            "ln": ln,
            "langlink": "?ln=" + ln,
            "sitename": CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            "sitesupportemail": CFG_SITE_SUPPORT_EMAIL,
            "msg_search": _("Search"),
            "msg_submit": _("Submit"),
            "msg_personalize": _("Personalize"),
            "msg_help": _("Help"),
            "msg_poweredby": _("Powered by"),
            "msg_maintainedby": _("Maintained by"),
            "msg_lastupdated": msg_lastupdated,
            "languagebox": self.tmpl_language_selection_box(req, ln),
            "version": CFG_VERSION,
            "pagefooteradd": pagefooteradd,
        }
        return out
    def tmpl_display_job_history(self, job_results, language=CFG_SITE_LANG):
        """Creates a page displaying information about
        the job results given as a parameter.

        @param job_results: List of JobResult objects containing
        information about the job results that have to be displayed
        @param language: language of the page

        @return: The HTML content of the page
        """
        _ = gettext_set_language(language)

        table_rows = ""
        for current_job_result in job_results:
            current_job = current_job_result.get_job()
            # convert execution date into text proper to be shown to the user
            execution_date_time = current_job_result.get_execution_date_time()
            date = convert_datestruct_to_dategui(execution_date_time)
            # obtain text corresponding to the frequency of execution
            frequency = current_job.get_frequency()
            frequency_text = self._get_frequency_text(frequency, language)
            # set the status text
            if current_job_result.STATUS_CODE_OK == current_job_result.get_status(
            ):
                status = _("OK")
            else:
                status = _("Error")

            records_found = current_job_result.get_number_of_records_found()

            row = """<tr>
            <td><a href="%(job_results_url)s?result_id=%(job_result_id)s&ln=%(language)s">%(job_name)s</a></td>
            <td>%(job_frequency)s</td>
            <td>%(execution_date)s</td>
            <td><b>%(status)s</b>
                <a href="%(display_job_result_url)s?result_id=%(job_result_id)s&ln=%(language)s">
                <small>%(number_of_records_found)s %(label_records_found)s</small>
                </a>
            </td>
            </tr>""" % self._html_escape_dictionary(
                {
                    "job_name": current_job.get_name(),
                    "job_frequency": frequency_text,
                    "execution_date": date,
                    "status": status,
                    "number_of_records_found": records_found,
                    "label_records_found": _("records found"),
                    "job_results_url": self._JOB_RESULTS_URL,
                    "display_job_result_url": self._DISPLAY_JOB_RESULT_URL,
                    "language": language,
                    "job_result_id": current_job_result.get_id()
                })
            table_rows += row

        body = """
        <table class="spacedcells">
            <th>%(label_job_name)s</th>
            <th>%(label_job_frequency)s</th>
            <th>%(label_execution_date)s</th>
            <th>%(label_status)s</th>
            %(table_rows)s
        </table>
        """ % {
            "table_rows": table_rows,
            "label_job_name": _("Job"),
            "label_job_frequency": _("Run"),
            "label_execution_date": _("Date"),
            "label_status": _("Status")
        }

        return body
Esempio n. 14
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
            'siteurl': CFG_SITE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,
            'msg_search': _("Search"),
            'msg_submit': _("Submit"),
            'msg_personalize': _("Personalize"),
            'msg_help': _("Help"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Maintained by"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': CFG_VERSION,
            'pagefooteradd': pagefooteradd,
        }
        return out
    def tmpl_display_job_history(self, job_results, language = CFG_SITE_LANG):
        """Creates a page displaying information about
        the job results given as a parameter.

        @param job_results: List of JobResult objects containing
        information about the job results that have to be displayed
        @param language: language of the page

        @return: The HTML content of the page
        """
        _ = gettext_set_language(language)

        table_rows = ""
        for current_job_result in job_results:
            current_job = current_job_result.get_job()
            # convert execution date into text proper to be shown to the user
            execution_date_time = current_job_result.get_execution_date_time()
            date = convert_datestruct_to_dategui(execution_date_time)
            # obtain text corresponding to the frequency of execution
            frequency = current_job.get_frequency()
            frequency_text = self._get_frequency_text(frequency, language)
            # set the status text
            if current_job_result.STATUS_CODE_OK == current_job_result.get_status():
                status = _("OK")
            else:
                status = _("Error")

            records_found = current_job_result.get_number_of_records_found()

            row = """<tr>
            <td><a href="%(job_results_url)s?result_id=%(job_result_id)s&ln=%(language)s">%(job_name)s</a></td>
            <td>%(job_frequency)s</td>
            <td>%(execution_date)s</td>
            <td><b>%(status)s</b>
                <a href="%(display_job_result_url)s?result_id=%(job_result_id)s&ln=%(language)s">
                <small>%(number_of_records_found)s %(label_records_found)s</small>
                </a>
            </td>
            </tr>""" %  self._html_escape_dictionary({
                        "job_name" : current_job.get_name(),
                        "job_frequency" : frequency_text,
                        "execution_date" : date,
                        "status" : status,
                        "number_of_records_found" : records_found,
                        "label_records_found" : _("records found"),
                        "job_results_url" : self._JOB_RESULTS_URL,
                        "display_job_result_url" : self._DISPLAY_JOB_RESULT_URL,
                        "language" : language,
                        "job_result_id" : current_job_result.get_id()
                        })
            table_rows += row

        body = """
        <table class="spacedcells">
            <th>%(label_job_name)s</th>
            <th>%(label_job_frequency)s</th>
            <th>%(label_execution_date)s</th>
            <th>%(label_status)s</th>
            %(table_rows)s
        </table>
        """ % {
            "table_rows" : table_rows,
            "label_job_name" : _("Job"),
            "label_job_frequency" : _("Run"),
            "label_execution_date" : _("Date"),
            "label_status" : _("Status")
            }

        return body
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft" style="padding-top: 10px;">
  <img style="margin-left: 10px; margin-right: 10px; float: left;" alt="fp7-capacities" src="/img/fp7_sm.png" height="46" width="60">
  <img style="margin-right: 10px; margin-top: 5px; float: left;" alt="e_infrastructures" src="/img/einfra_sm.png" height="33" width="90">
  <div style="float: left; margin-bottom: 10px;">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
  </div>
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://analytics.openaire.eu/" : "http://analytics.openaire.eu/");
document.write(unescape("%%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%%3E%%3C/script%%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="https://analytics.openaire.eu/piwik.php?idsite=2" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tag -->
</body>
</html>
        """ % {
          'siteurl' : CFG_SITE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : CFG_SITE_SUPPORT_EMAIL,

          'msg_search' : _("Search"),
          'msg_submit' : _("Submit"),
          'msg_personalize' : _("Personalize"),
          'msg_help' : _("Help"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Maintained by"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : CFG_VERSION,

          'pagefooteradd' : pagefooteradd,

        }
        return out
Esempio n. 17
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """
        try:
            from invenio.config import CFG_PIWIK
            tracking_code = """<!-- Piwik -->
                                <script type='text/javascript'>
                                  var _paq = _paq || [];
                                  _paq.push(['trackPageView']);
                                  _paq.push(['enableLinkTracking']);
                                  (function() {{
                                    var u='//piwik.tind.io/';
                                    _paq.push(['setTrackerUrl', u+'piwik.php']);
                                    _paq.push(['setSiteId', {0}]);
                                    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
                                    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
                                  }})();
                                </script>
                                <noscript><p><img src='//piwik.tind.io/piwik.php?idsite={0}' style='border:0;' alt='' /></p></noscript>
                               <!-- End Piwik Code -->""".format(CFG_PIWIK)


        except:
            tracking_code = ""
        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
  %(tracking_code)s
<!-- replaced page footer -->
</div>
</body>
</html>
        """ % {
          'siteurl': CFG_BASE_URL,
          'sitesecureurl': CFG_SITE_SECURE_URL,
          'ln': ln,
          'langlink': '?ln=' + ln,

          'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,

          'msg_search': _("Search"),
          'msg_submit': _("Submit"),
          'msg_personalize': _("Personalize"),
          'msg_help': _("Help"),

          'msg_poweredby': _("Powered by"),
          'msg_maintainedby': _("Maintained by"),

          'msg_lastupdated': msg_lastupdated,
          'languagebox': self.tmpl_language_selection_box(req, ln),
          'version': CFG_VERSION,

          'pagefooteradd': pagefooteradd,
          'tracking_code': tracking_code,
        }
        return out
Esempio n. 18
0
                        write_cache_file('%(name)s.lastupdated%(lang)s.html' % \
                                         {'name': webdoc_name,
                                          'lang': '-'+lang},
                                         webdoc_cache_dir,
                                         lastupdated,
                                         verbose)
                    except IOError, e:
                        print e
                    except OSError, e:
                        print e

                # Last updated cache file
                try:
                    write_cache_file('last_updated',
                                     webdoc_cache_dir,
                                     convert_datestruct_to_dategui(
                                         time.localtime()),
                                     verbose=0)
                except IOError, e:
                    print e
                except OSError, e:
                    print e

            if verbose > 0:
                print 'Written cache in %s' % webdoc_cache_dir


def read_webdoc_source(webdoc):
    """
    Returns the source of the given webdoc, along with the path to its
    cache directory.
Esempio n. 19
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page
        record_page_re = re.compile(
            "^/record/(?P<recid>[0-9]+)/?(?P<page_type>.*)")

        custom_variables = ""

        record_page_match = record_page_re.match(req.uri)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(
                record_page_match.group('recid'))
            custom_variables = """
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          "%(collection_name)s", // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': record_collection
            }

            if record_page_match.group('page_type'):
                custom_variables += """
_paq.push(['setCustomVariable',
          2,
          "Type",
          "%(page_type)s",
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          "%(page_collection_type)s",
          "page"
          ]);
          """ % {
                    'page_type':
                    record_page_match.group('page_type'),
                    'page_collection_type':
                    record_collection + record_page_match.group('page_type')
                }

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
 <script type="text/javascript">
 var _paq = _paq || [];
 (function(){ var u=(("https:" == document.location.protocol) ? "https://inspirehep.net/piwik/" : "http://inspirehep.net/piwik/");
 _paq.push(['setSiteId', '8']);
 %(custom_variables)s
 _paq.push(['setTrackerUrl', u+'piwik.php']);
 _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);
 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
 s.parentNode.insertBefore(g,s); })();
  </script>
  <noscript><p><img src="http://inspirehep.net/piwik/piwik.php?idsite=8" style="border:0" alt="" /></p></noscript>
  <!-- End Piwik Code -->
</body>
</html>
        """ % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': '*****@*****.**',
            'msg_search': _("Search"),
            'msg_help': _("Help"),
            'msg_terms': _("Terms of use"),
            'msg_privacy': _("Privacy policy"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Problems/Questions to"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': self.trim_version(CFG_VERSION),
            'pagefooteradd': pagefooteradd,
            'custom_variables': custom_variables
        }
        return out
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page

        custom_variables = ""
        record_collection = ""
        page_type = ""

        parsed_uri = urlparse(req.unparsed_uri)

        # HACK: I know it's horrible code. :-(
        record_page_match = re.match("^/record/(?P<recid>[0-9]+)(/(?P<page_type>.+)?)?$", parsed_uri.path)
        if record_page_match:
            record_collection = guess_primary_collection_of_a_record(record_page_match.group('recid'))
            page_type = record_page_match.group('page_type') or 'detailed'
        if re.match("^/search/?$", parsed_uri.path):
            cc = parse_qs(parsed_uri.query).get('cc', [CFG_SITE_NAME])
            record_collection = cc.pop()
        collection_page_match = re.match("^/$|^/collection/(?P<collection>.+)/?$", parsed_uri.path)
        if collection_page_match:
            record_collection = collection_page_match.groupdict().get('collection', CFG_SITE_NAME)
        if record_collection:
            custom_variables = """\
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          %(collection_name)s, // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
                'collection_name': js_escape(record_collection)
            }

        if page_type:
            custom_variables += """\
_paq.push(['setCustomVariable',
          2,
          "Type",
          %(page_type)s,
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          %(page_collection_type)s,
          "page"
          ]);
          """ % {
                'page_type': js_escape(page_type),
                'page_collection_type': js_escape(record_collection + page_type)
            }

        out = """\
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
""" % {
          'siteurl' : CFG_BASE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_terms': _("Terms of use"),
          'msg_privacy': _("Privacy policy"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,
          }
        if not isUserAdmin(collect_user_info(req)):
            out += """\
<!-- Piwik -->
<script type="text/javascript">
  try {
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="//piwik.inspirehep.net/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 8]);
        %(custom_variables)s
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
    })();}
    catch(err) {
        (function() {
            var img = document.createElement('img');
            img.src = '//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1';
            document.body.appendChild(img);
    })();
    }
</script>
<noscript><p><img src="//piwik.inspirehep.net/piwik.php?idsite=8&amp;rec=1&amp;bots=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
""" % {'custom_variables': custom_variables}

        out += """\
</body>
</html>
"""
        return out
Esempio n. 21
0
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
 <!--
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />-->
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
 <p><em>
 Articles in the SCOAP3 repository are released under a <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by/3.0/"><strong>CC-BY</strong></a> license. Metadata are provided by the corresponding publishers and released under the <a target="_blank"  rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    <strong>CC0</strong>
  </a> waiver.
 </em></p>
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://cds-piwik.cern.ch/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "10"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://cds-piwik.cern.ch/piwik.php?idsite=10&amp;rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->

</body>
</html>
        """ % {
          'siteurl': CFG_BASE_URL,
          'sitesecureurl': CFG_SITE_SECURE_URL,
          'ln': ln,
          'langlink': '?ln=' + ln,

          'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,

          'msg_search': _("Search"),
          'msg_submit': _("Submit"),
          'msg_personalize': _("Personalize"),
          'msg_help': _("Help"),

          'msg_poweredby': _("Powered by"),
          'msg_maintainedby': _("Maintained by"),

          'msg_lastupdated': msg_lastupdated,
          'languagebox': self.tmpl_language_selection_box(req, ln),
          'version': CFG_VERSION,

          'pagefooteradd': pagefooteradd,
        }
        return out
Esempio n. 22
0
    def tmpl_bibdocfile_filelist(
        self, ln, recid, name, version, md, superformat, subformat, nice_size_f, description, comment
    ):
        """
        Displays a file in the file list.

        Parameters:

          - 'ln' *string* - The language to display the interface in

          - 'recid' *int* - The id of the record

          - 'name' *string* - The name of the file

          - 'version' *string* - The version

          - 'md' *datetime* - the modification date

          - 'superformat' *string* - The display superformat

          - 'subformat' *string* - The display subformat

          - 'nice_size_f' *string* - The nice_size of the file

          - 'description' *string* - The description that might have been associated
          to the particular file

          - 'comment' *string* - The comment that might have been associated
          to the particular file
        """

        # load the right message language
        _ = gettext_set_language(ln)

        urlbase = "%s/%s/%s/files/%s" % (
            CFG_SITE_URL,
            CFG_SITE_RECORD,
            recid,
            "%s%s" % (cgi.escape(urllib.quote(name), True), superformat),
        )

        urlargd = {"version": version}
        if subformat:
            urlargd["subformat"] = subformat

        link_label = "%s%s" % (name, superformat)
        if subformat:
            link_label += " (%s)" % subformat

        link = create_html_link(urlbase, urlargd, cgi.escape(link_label))

        return """<tr>
                    <td valign="top">
                      <small>%(link)s</small>
                    </td>
                    <td valign="top">
                      <font size="-2" color="green">[%(nice_size)s]</font>
                      <font size="-2"><em>%(md)s</em>
                      %(comment)s
                    </td>
                    <td valign="top"><em>%(description)s</em></td>
                    </tr>""" % {
            "link": link,
            "nice_size": nice_size_f,
            "md": convert_datestruct_to_dategui(md.timetuple(), ln),
            "description": cgi.escape(description),
            "comment": comment and """<br /><font size="-2"><em>%s</em></font>""" % cgi.escape(comment) or "",
        }
    def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

        Parameters:

        - 'ln' *string* - The language to display

        - 'lastupdated' *string* - when the page was last updated

        - 'pagefooteradd' *string* - additional page footer HTML code

        Output:

        - HTML code of the page headers
        """
        from invenio.search_engine import guess_primary_collection_of_a_record

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        # Prepare Piwik custom variables if we are in a detailed record page
        record_page_re = re.compile("^/record/(?P<recid>[0-9]+)/?(?P<page_type>.*)")

        custom_variables = ""

        record_page_match = record_page_re.match(req.uri)
        if record_page_match:
          record_collection = guess_primary_collection_of_a_record(record_page_match.group('recid'))
          custom_variables = """
_paq.push(['setCustomVariable',
          1, // Index, the number from 1 to 5 where this custom variable name is stored
          "Collection", // Name, the name of the variable
          "%(collection_name)s", // Value
          "page" // Scope of the custom variable
          ]);
          """ % {
            'collection_name': record_collection
          }

          if record_page_match.group('page_type'):
            custom_variables += """
_paq.push(['setCustomVariable',
          2,
          "Type",
          "%(page_type)s",
          "page"
          ]);
_paq.push(['setCustomVariable',
          3,
          "CollectionType",
          "%(page_collection_type)s",
          "page"
          ]);
          """ % {
            'page_type': record_page_match.group('page_type'),
            'page_collection_type': record_collection + record_page_match.group('page_type')
          }

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/terms-of-use">%(msg_terms)s</a>&nbsp;::&nbsp;
  <a class="footer" href="%(siteurl)s/info/general/privacy-policy">%(msg_privacy)s</a>
  <br />
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
 <script type="text/javascript">
 var _paq = _paq || [];
 (function(){ var u=(("https:" == document.location.protocol) ? "https://inspirehep.net/piwik/" : "http://inspirehep.net/piwik/");
 _paq.push(['setSiteId', '8']);
 %(custom_variables)s
 _paq.push(['setTrackerUrl', u+'piwik.php']);
 _paq.push(['trackPageView']);
 _paq.push(['enableLinkTracking']);
 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
 s.parentNode.insertBefore(g,s); })();
  </script>
  <noscript><p><img src="http://inspirehep.net/piwik/piwik.php?idsite=8" style="border:0" alt="" /></p></noscript>
  <!-- End Piwik Code -->
</body>
</html>
        """ % {
          'siteurl' : CFG_BASE_URL,
          'sitesecureurl' : CFG_SITE_SECURE_URL,
          'ln' : ln,
          'langlink': '?ln=' + ln,

          'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
          'sitesupportemail' : '*****@*****.**',

          'msg_search' : _("Search"),
          'msg_help' : _("Help"),

          'msg_terms': _("Terms of use"),
          'msg_privacy': _("Privacy policy"),

          'msg_poweredby' : _("Powered by"),
          'msg_maintainedby' : _("Problems/Questions to"),

          'msg_lastupdated' : msg_lastupdated,
          'languagebox' : self.tmpl_language_selection_box(req, ln),
          'version' : self.trim_version(CFG_VERSION),

          'pagefooteradd' : pagefooteradd,
          'custom_variables': custom_variables
          }
        return out
Esempio n. 24
0
                        write_cache_file('%(name)s.lastupdated%(lang)s.html' % \
                                         {'name': webdoc_name,
                                          'lang': '-'+lang},
                                         webdoc_cache_dir,
                                         lastupdated,
                                         verbose)
                    except IOError, e:
                        print e
                    except OSError, e:
                        print e

                # Last updated cache file
                try:
                    write_cache_file('last_updated',
                                     webdoc_cache_dir,
                                     convert_datestruct_to_dategui(time.localtime()),
                                     verbose=0)
                except IOError, e:
                    print e
                except OSError, e:
                    print e

            if verbose > 0:
                print 'Written cache in %s' % webdoc_cache_dir

def read_webdoc_source(webdoc):
    """
    Returns the source of the given webdoc, along with the path to its
    cache directory.

    Returns (None, None, None) if webdoc cannot be found.
Esempio n. 25
0
    def tmpl_pagefooter(self,
                        req=None,
                        ln=CFG_SITE_LANG,
                        lastupdated=None,
                        pagefooteradd=""):
        """Creates a page footer

           Parameters:

          - 'ln' *string* - The language to display

          - 'lastupdated' *string* - when the page was last updated

          - 'pagefooteradd' *string* - additional page footer HTML code

           Output:

          - HTML code of the page headers
        """

        # load the right message language
        _ = gettext_set_language(ln)

        if lastupdated and lastupdated != '$Date$':
            if lastupdated.startswith("$Date: ") or \
            lastupdated.startswith("$Id: "):
                lastupdated = convert_datestruct_to_dategui(\
                                 convert_datecvs_to_datestruct(lastupdated),
                                 ln=ln)
            msg_lastupdated = _("Last updated") + ": " + lastupdated
        else:
            msg_lastupdated = ""

        out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
 <div class="pagefooterstripeleft">
 <!--
  %(sitename)s&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>&nbsp;::&nbsp;<a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a>&nbsp;::&nbsp;<a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
  <br />-->
  %(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
  <br />
  %(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
  <br />
  %(msg_lastupdated)s
 </div>
 <div class="pagefooterstriperight">
 <p><em>
 Articles in the SCOAP3 repository are released under a <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by/3.0/"><strong>CC-BY</strong></a> license. Metadata are provided by the corresponding publishers and released under the <a target="_blank"  rel="license"
     href="http://creativecommons.org/publicdomain/zero/1.0/">
    <strong>CC0</strong>
  </a> waiver.
 </em></p>
  %(languagebox)s
 </div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);

  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://cds-piwik.cern.ch/";
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setSiteId", "10"]);
    var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
    g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://cds-piwik.cern.ch/piwik.php?idsite=10&amp;rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->

</body>
</html>
        """ % {
            'siteurl': CFG_BASE_URL,
            'sitesecureurl': CFG_SITE_SECURE_URL,
            'ln': ln,
            'langlink': '?ln=' + ln,
            'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
            'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,
            'msg_search': _("Search"),
            'msg_submit': _("Submit"),
            'msg_personalize': _("Personalize"),
            'msg_help': _("Help"),
            'msg_poweredby': _("Powered by"),
            'msg_maintainedby': _("Maintained by"),
            'msg_lastupdated': msg_lastupdated,
            'languagebox': self.tmpl_language_selection_box(req, ln),
            'version': CFG_VERSION,
            'pagefooteradd': pagefooteradd,
        }
        return out