diff --git a/modules/websearch/lib/websearch_templates_epfl.py b/modules/websearch/lib/websearch_templates_epfl.py index e65eb8879..836e0e7fb 100644 --- a/modules/websearch/lib/websearch_templates_epfl.py +++ b/modules/websearch/lib/websearch_templates_epfl.py @@ -1,2438 +1,2444 @@ # -*- coding: utf-8 -*- # pylint: disable=C0301 """ EPFL templates. Websearch handles search pages and detailed record pages. These templates are also used by webcoll CLI """ import cgi, re, math from urllib import quote, FancyURLopener from invenio.config import \ CFG_WEBSEARCH_ADVANCEDSEARCH_PATTERN_BOX_WIDTH, \ CFG_WEBSEARCH_SPLIT_BY_COLLECTION, \ CFG_WEBSEARCH_DEF_RECORDS_IN_GROUPS, \ CFG_BIBRANK_SHOW_READING_STATS, \ CFG_BIBRANK_SHOW_DOWNLOAD_STATS, \ CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS, \ CFG_SITE_LANG, \ CFG_SITE_NAME, \ CFG_SITE_NAME_INTL, \ CFG_SITE_URL, \ CFG_INSPIRE_SITE, \ CFG_WEBSEARCH_DEFAULT_SEARCH_INTERFACE, \ CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES, \ CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS, \ CFG_BIBINDEX_CHARS_PUNCTUATION from invenio.dbquery import run_sql from invenio.messages import gettext_set_language from invenio.urlutils import make_canonical_urlargd, drop_default_urlargd, create_html_link, create_url from invenio.intbitset import intbitset import invenio.websearch_templates _RE_PUNCTUATION = re.compile(CFG_BIBINDEX_CHARS_PUNCTUATION) _RE_SPACES = re.compile(r"\s+") def get_fieldvalues(recID, tag): """Return list of field values for field TAG inside record RECID. FIXME: should be imported commonly for search_engine too.""" out = [] if tag == "001___": # we have asked for recID that is not stored in bibXXx tables out.append(str(recID)) else: # we are going to look inside bibXXx tables digit = tag[0:2] bx = "bib%sx" % digit bibx = "bibrec_bib%sx" % digit query = "SELECT bx.value FROM %s AS bx, %s AS bibx WHERE bibx.id_bibrec='%s' AND bx.id=bibx.id_bibxxx AND bx.tag LIKE '%s'" \ "ORDER BY bibx.field_number, bx.tag ASC" % (bx, bibx, recID, tag) res = run_sql(query) for row in res: out.append(row[0]) return out class Template(invenio.websearch_templates.Template): # Type of the allowed parameters for the web interface for search results search_results_default_urlargd = { 'cc': (str, CFG_SITE_NAME), 'c': (list, []), 'p': (str, ""), 'f': (str, ""), 'rg': (int, CFG_WEBSEARCH_DEF_RECORDS_IN_GROUPS), 'sf': (str, ""), 'so': (str, "d"), 'sp': (str, ""), 'rm': (str, ""), 'of': (str, "hb"), 'ot': (list, []), 'aas': (int, CFG_WEBSEARCH_DEFAULT_SEARCH_INTERFACE), 'as': (int, CFG_WEBSEARCH_DEFAULT_SEARCH_INTERFACE), 'p1': (str, ""), 'f1': (str, ""), 'm1': (str, ""), 'op1':(str, ""), 'p2': (str, ""), 'f2': (str, ""), 'm2': (str, ""), 'op2':(str, ""), 'p3': (str, ""), 'f3': (str, ""), 'm3': (str, ""), 'sc': (int, 0), 'jrec': (int, 0), 'recid': (int, -1), 'recidb': (int, -1), 'sysno': (str, ""), 'id': (int, -1), 'idb': (int, -1), 'sysnb': (str, ""), 'action': (str, "search"), 'action_search': (str, ""), 'action_browse': (str, ""), 'd1': (str, ""), 'd1y': (int, 0), 'd1m': (int, 0), 'd1d': (int, 0), 'd2': (str, ""), 'd2y': (int, 0), 'd2m': (int, 0), 'd2d': (int, 0), 'dt': (str, ""), 'ap': (int, 1), 'verbose': (int, 0), 'ec': (list, []), 'ext': (list, []), } # ...and for search interfaces search_interface_default_urlargd = { 'aas': (int, CFG_WEBSEARCH_DEFAULT_SEARCH_INTERFACE), 'as': (int, CFG_WEBSEARCH_DEFAULT_SEARCH_INTERFACE), 'verbose': (int, 0)} def tmpl_xml_marc_prologue(self): """Creates XML MARC prologue.""" out = """\n""" return out def build_search_url(self, known_parameters={}, **kargs): """ Helper for generating a canonical search url. 'known_parameters' is the list of query parameters you inherit from your current query. You can then pass keyword arguments to modify this query. build_search_url(known_parameters, of="xm") The generated URL is absolute. """ parameters = {} parameters.update(known_parameters) parameters.update(kargs) # Now, we only have the arguments which have _not_ their default value parameters = drop_default_urlargd(parameters, self.search_results_default_urlargd) # Treat `as' argument specially: if parameters.has_key('aas'): parameters['as'] = parameters['aas'] del parameters['aas'] # Asking for a recid? Return a /record/ URL if 'recid' in parameters: target = "/record/%s" % parameters['recid'] del parameters['recid'] target += make_canonical_urlargd(parameters, self.search_results_default_urlargd) return target return "/search%s" % make_canonical_urlargd(parameters, self.search_results_default_urlargd) def build_search_interface_url(self, known_parameters={}, **kargs): """ Helper for generating a canonical search interface URL.""" parameters = {} parameters.update(known_parameters) parameters.update(kargs) if parameters.get('cc'): c = None else: c = parameters['c'] del parameters['c'] # Now, we only have the arguments which have _not_ their default value parameters = drop_default_urlargd(parameters, self.search_results_default_urlargd) # Treat `as' argument specially: if parameters.has_key('aas'): parameters['as'] = parameters['aas'] del parameters['aas'] if c and c != CFG_SITE_NAME: base = '/collection/' + quote(c) elif parameters: base = '/search' else: base = '' return create_url(base, parameters) def tmpl_record_page_header_content(self, req, recid, ln): """ Provide extra information in the header of /record pages """ _ = gettext_set_language(ln) title = get_fieldvalues(recid, "245__a") - if title: + hidden = get_fieldvalues(recid, "980__c") + is_hidden = False + + if hidden and hidden[0] == 'HIDDEN': + is_hidden = True + + if not is_hidden and title: title = cgi.escape(title[0]) else: title = _("Record") + ' #%d' % recid keywords = ', '.join(get_fieldvalues(recid, "6531_a")) description = ' '.join(get_fieldvalues(recid, "520__a")) description += "\n" description += '; '.join(get_fieldvalues(recid, "100__a") + get_fieldvalues(recid, "700__a")) return [cgi.escape(x, True) for x in (title, description, keywords)] def tmpl_navtrail_links(self, aas, ln, dads): """ EPFL Creates the navigation bar at top of each search page (*Home > Root collection > subcollection > ...*) Parameters: - 'aas' *int* - Should we display an advanced search box? - 'ln' *string* - The language to display - 'separator' *string* - The separator between two consecutive collections - 'dads' *list* - A list of parent links, eachone being a dictionary of ('name', 'longname') """ links = [] for url, name in dads: args = {'c': url, 'as': aas, 'ln': ln} links.append(create_html_link(self.build_search_interface_url(**args), {}, url.split('/')[-1] )) out = [] if len(links): out += ['
  • %s
  • ' % link for link in links] return ''.join(out) def tmpl_webcoll_body(self, ln, collection, te_portalbox, searchfor, np_portalbox, narrowsearch, focuson, instantbrowse, ne_portalbox): """ EPFL Creates the body of the main search page. Parameters: - 'ln' *string* - language of the page being generated - 'collection' - collection id of the page being generated - 'te_portalbox' *string* - The HTML code for the portalbox on top of search - 'searchfor' *string* - The HTML code for the search for box - 'np_portalbox' *string* - The HTML code for the portalbox on bottom of search - 'narrowsearch' *string* - The HTML code for the search categories (left bottom of page) - 'focuson' *string* - The HTML code for the "focuson" categories (right bottom of page) - 'ne_portalbox' *string* - The HTML code for the bottom of the page """ from invenio.websearch_webcoll import Collection _ = gettext_set_language(ln) if collection == CFG_SITE_NAME: return self.tmpl_homepage(searchfor, ln) c = Collection(collection) if narrowsearch: right_col = """ """ % {'narrowsearch': narrowsearch, 'focuson': focuson,} else: right_col = """ """ % { 'title': _("Infoscience, EPFL's scientific publications"), 'guidelines_url': ln == 'en' and 'http://polylex.epfl.ch/files/content/sites/polylex/files/recueil_pdf/ENG/3.3.2_principe_integrite_recherche_an.pdf' or 'http://polylex.epfl.ch/files/content/sites/polylex/files/recueil_pdf/3.3.2_principe_integrite_recherche_fr.pdf', 'guidelines_label': _("EPFL Directive for Research Integrity"), 'fns1_url': ln == 'en' and 'http://www.snf.ch/SiteCollectionDocuments/allg_reglement_valorisierung_e.pdf' or 'http://www.snf.ch/SiteCollectionDocuments/dos_OA_Weisung_f.pdf', 'fns1_label': _("SNSF regulations on information, valorisation and rights to research results"), 'fns2_url': ln == 'en' and 'http://www.snf.ch/SiteCollectionDocuments/Dossiers/dos_OA_regelung_auf_einen_blick_e.pdf' or 'http://www.snf.ch/SiteCollectionDocuments/Dossiers/dos_OA_regelung_auf_einen_blick_f.pdf', 'fns2_label': _("Overview of SNSF Guidelines on Open Access"), 'erc_url': 'http://erc.europa.eu/sites/default/files/press_release/files/open_access_policy_researchers_funded_ERC.pdf', 'erc_label': _("Open Access Guidelines for researchers funded by the ERC"), } body = """

    %(title)s

    %(te_portalbox)s %(searchfor)s %(np_portalbox)s

    %(instant_label)s

    %(instantbrowse)s %(ne_portalbox)s
    %(right_col)s
    """ % \ {'title': c.get_name(ln=ln), 'te_portalbox': te_portalbox, 'searchfor': searchfor, 'np_portalbox': np_portalbox, 'ne_portalbox': ne_portalbox, 'right_col': right_col, 'instantbrowse': instantbrowse, 'instant_label': _('Latest additions'), 'feed': self.build_rss_url({'c': collection, 'ln': ln}), 'feed_label': 'RSS', } return body def tmpl_homepage(self, searchfor, ln): """ EPFL: infoscience's homepage """ from invenio.websearch_webcoll import Collection research = Collection('Infoscience/Research') resource = Collection('Infoscience/Resource') _ = gettext_set_language(ln) try: f = FancyURLopener().open('https://actu.epfl.ch/webservice?channel=79&lang=%s&template=4' % ln) news_feed = f.read() except: news_feed = '' body = """ %(maintenance_msg)s %(right_col)s """ return body % {'title': _("Search publications"), 'searchfor': searchfor, 'ln': ln, 'research_label': _("Access to the %s scientific publications") % self.tmpl_nice_number_via_locale(research.nbrecs, ln), 'resource_label': _("Access to the %s documentary resources") % self.tmpl_nice_number_via_locale(resource.nbrecs, ln), 'news_feed': news_feed, 'more_news_label': _('More news'), 'maintenance_msg': self.tmpl_maintenance_msg(ln), 'right_col': self.tmpl_default_right_col(ln), 'feed': self.build_rss_url({'c': 'Infoscience', 'ln': ln}), 'feed_label': 'RSS', } def tmpl_maintenance_msg(self, ln): # desactivate but keep here for future use return "" _ = gettext_set_language(ln) out = """

    ⚠ Maintenance

    %(msg)s

    """ return out % { 'msg': ('Infoscience will not be available due to server maintenance on March 2 between 7:30am and 8am.' \ if ln == 'en' else \ 'Infoscience sera indisponible pour des raisons de maintenance des serveurs le mercredi 2 mars entre 7h30 et 8h00.' ) } def tmpl_default_right_col(self, ln): """EPFL => right column """ _ = gettext_set_language(ln) out = """
    """ return out % { 'title': _("Infoscience, EPFL's scientific publications"), 'guidelines_url': ln == 'en' and 'http://polylex.epfl.ch/files/content/sites/polylex/files/recueil_pdf/ENG/3.3.2_principe_integrite_recherche_an.pdf' or 'http://polylex.epfl.ch/files/content/sites/polylex/files/recueil_pdf/3.3.2_principe_integrite_recherche_fr.pdf', 'guidelines_label': _("EPFL Directive for Research Integrity"), 'fns1_url': ln == 'en' and 'http://www.snf.ch/SiteCollectionDocuments/allg_reglement_valorisierung_e.pdf' or 'http://www.snf.ch/SiteCollectionDocuments/dos_OA_Weisung_f.pdf', 'fns1_label': _("SNSF regulations on information, valorisation and rights to research results"), 'fns2_url': ln == 'en' and 'http://www.snf.ch/SiteCollectionDocuments/Dossiers/dos_OA_regelung_auf_einen_blick_e.pdf' or 'http://www.snf.ch/SiteCollectionDocuments/Dossiers/dos_OA_regelung_auf_einen_blick_f.pdf', 'fns2_label': _("Overview of SNSF Guidelines on Open Access"), 'erc_url': 'http://erc.europa.eu/sites/default/files/press_release/files/open_access_policy_researchers_funded_ERC.pdf', 'erc_label': _("Open Access Guidelines for researchers funded by the ERC"), } def tmpl_portalbox(self, title, body): """ EPFL Creates portalboxes based on the parameters Parameters: - 'title' *string* - The title of the box - 'body' *string* - The HTML code for the body of the box """ out = """

    %(title)s

    %(body)s

    """ % {'title' : title, 'body' : body} return out def tmpl_advanced_search_box(self, ln, ext=None): """ EPFL """ _ = gettext_set_language(ln) if not ext: ext = [] # ext: ['collection:ARTICLE', 'review:REVIEWED'] out = """

    %(filter_doctype_label)s

    """ return out % {'filter_doctype_label': _("Filter by document type"), 'category_publications': _("Publications"), 'ARTICLE': _("Journal Articles"), 'c_article': 'collection:ARTICLE' in ext and 'checked="checked"', 'REVIEW': _("Reviews"), 'c_review': 'collection:REVIEW' in ext and 'checked="checked"', 'CONF': _("Conference Papers"), 'c_conf': 'collection:CONF' in ext and 'checked="checked"', 'category_monographs': _("Monographs"), 'BOOK': _("Books"), 'c_book': 'collection:BOOK' in ext and 'checked="checked"', 'THESIS': _("Theses"), 'c_thesis': 'collection:THESIS' in ext and 'checked="checked"', 'CHAPTER': _("Book Chapters"), 'c_chapter': 'collection:CHAPTER' in ext and 'checked="checked"', 'PROC': _("Conference Proceedings"), 'c_proc': 'collection:PROC' in ext and 'checked="checked"', 'category_presentations': _("Presentations & Talks"), 'POSTER': _("Posters"), 'c_poster': 'collection:POSTER' in ext and 'checked="checked"', 'TALK': _("Presentations & Talks"), 'c_talk': 'collection:TALK' in ext and 'checked="checked"', 'category_patent': _("Standards & Patents"), 'STANDARD': _("Standards"), 'c_standard': 'collection:STANDARD' in ext and 'checked="checked"', 'PATENT': _("Patents"), 'c_patent': 'collection:PATENT' in ext and 'checked="checked"', 'category_reports': _("Reports"), 'REPORT': _("Technical Reports"), 'c_report': 'collection:REPORT' in ext and 'checked="checked"', 'WORKING': _("Working Papers"), 'c_working': 'collection:WORKING' in ext and 'checked="checked"', 'category_teaching': _("Lectures & teaching material"), 'POLY': _("Teaching Documents"), 'c_poly': 'collection:POLY' in ext and 'checked="checked"', 'STUDENT': _("Student Projects"), 'c_student': 'collection:STUDENT' in ext and 'checked="checked"', 'filter_status_label': _("Filter by publication status"), 'REVIEWED': _("Peer-reviewed publications"), 'c_reviewed': 'review:REVIEWED' in ext and 'checked="checked"', 'PUBLISHED': _("Published"), 'c_published': 'status:PUBLISHED' in ext and 'checked="checked"', 'ACCEPTED': _("Accepted"), 'c_accepted': 'status:ACCEPTED' in ext and 'checked="checked"', 'SUBMITTED': _("Submitted"), 'c_submitted': 'status:SUBMITTED' in ext and 'checked="checked"', 'filter_affiliation_label': _("Filter by origin"), 'EPFL': _("Work produced at EPFL"), 'c_epfl': 'affiliation:EPFL' in ext and 'checked="checked"', 'filter_fulltext_label': _("Filter by fulltext availability"), 'PUBLIC': _("Publicly available"), 'c_public': 'fulltext:PUBLIC' in ext and 'checked="checked"', 'RESTRICTED': _("Restricted access"), 'c_restricted': 'fulltext:RESTRICTED' in ext and 'checked="checked"', } def tmpl_search_help(self, ln): """ EPFL : print search tips """ _ = gettext_set_language(ln) help_section = """

    %(b_label)s

    %(p_label)s

    %(paren)s

    %(link)s""" % { 'b_label': _("Boolean operators"), 'and': _("AND: vetterli AND wavelet (you can also use + char instead of AND)"), 'not': _("NOT: vetterli NOT wavelet (you can also use - char instead of NOT)"), 'or': _("OR: vetterli OR wavelet (you can also use | char instead of OR)"), 'p_label': _("Parentheses"), 'paren': _("You can also use parentheses in your queries to group boolean expressions together. Nested parentheses are also supported."), 'link': _("Full documentation about searching"), 'page': ln == 'en' and 'search' or 'rechercher', } return help_section def tmpl_searchfor_simple(self, ln, collection_id, collection_name, record_count, middle_option): """ EPFL Produces simple *Search for* box for the current collection. Parameters: - 'ln' *string* - *str* The language to display - 'collection_id' - *str* The collection id - 'collection_name' - *str* The collection name in current language - 'record_count' - *str* Number of records in this collection - 'middle_option' *string* - HTML code for the options (any field, specific fields ...) """ # load the right message language _ = gettext_set_language(ln) argd = drop_default_urlargd({'ln': ln, 'cc': collection_id, 'sc': CFG_WEBSEARCH_SPLIT_BY_COLLECTION}, self.search_results_default_urlargd) hidden_values = '' for field, value in argd.items(): hidden_values += self.tmpl_input_hidden(field, value) asearchurl = self.build_search_interface_url(c=collection_id, aas=max(CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES), ln=ln) out = """
    %(hidden_values)s
    %(search_within)s
    %(help_label)s
    %(help_section)s
    """ return out % {'siteurl' : CFG_SITE_URL, 'hidden_values': hidden_values, 'search_within': middle_option, 'asearch_url': asearchurl, 'search_url': ln=='en' and 'search' or 'rechercher', 'label': _("Search"), 'help_label': _("Search Tips"), 'advanced_label': _("Advanced Search"), 'advanced_box': self.tmpl_advanced_search_box(ln), 'help_section': self.tmpl_search_help(ln), } def tmpl_searchfor_advanced(self, ln, # current language collection_id, collection_name, record_count, middle_option_1, middle_option_2, middle_option_3, searchoptions, sortoptions, rankoptions, displayoptions, formatoptions ): """ Produces advanced *Search for* box for the current collection. Parameters: - 'ln' *string* - The language to display - 'middle_option_1' *string* - HTML code for the first row of options (any field, specific fields ...) - 'middle_option_2' *string* - HTML code for the second row of options (any field, specific fields ...) - 'middle_option_3' *string* - HTML code for the third row of options (any field, specific fields ...) - 'searchoptions' *string* - HTML code for the search options - 'sortoptions' *string* - HTML code for the sort options - 'rankoptions' *string* - HTML code for the rank options - 'displayoptions' *string* - HTML code for the display options - 'formatoptions' *string* - HTML code for the format options """ # load the right message language _ = gettext_set_language(ln) out = ''' ''' argd = drop_default_urlargd({'ln': ln, 'aas': 1, 'cc': collection_id, 'sc': CFG_WEBSEARCH_SPLIT_BY_COLLECTION}, self.search_results_default_urlargd) # Only add non-default hidden values for field, value in argd.items(): out += self.tmpl_input_hidden(field, value) header = _("Search %s records for") % \ self.tmpl_nbrecs_info(record_count, "", "") header += ':' ssearchurl = self.build_search_interface_url(c=collection_id, aas=min(CFG_WEBSEARCH_ENABLED_SEARCH_INTERFACES), ln=ln) out += ''' ''' % {'ln' : ln, 'sizepattern' : CFG_WEBSEARCH_ADVANCEDSEARCH_PATTERN_BOX_WIDTH, 'langlink': ln != CFG_SITE_LANG and '?ln=' + ln or '', 'siteurl' : CFG_SITE_URL, 'ssearch' : create_html_link(ssearchurl, {}, _("Simple Search")), 'header' : header, 'matchbox_m1' : self.tmpl_matchtype_box('m1', ln=ln), 'middle_option_1' : middle_option_1, 'andornot_op1' : self.tmpl_andornot_box('op1', ln=ln), 'matchbox_m2' : self.tmpl_matchtype_box('m2', ln=ln), 'middle_option_2' : middle_option_2, 'andornot_op2' : self.tmpl_andornot_box('op2', ln=ln), 'matchbox_m3' : self.tmpl_matchtype_box('m3', ln=ln), 'middle_option_3' : middle_option_3, 'msg_search' : _("Search"), 'msg_browse' : _("Browse"), 'msg_search_tips' : _("Search Tips")} if (searchoptions): out += """""" % { 'searchheader' : _("Search options:"), 'searchoptions' : searchoptions } out += """ """ % { 'added' : _("Added/modified since:"), 'until' : _("until:"), 'added_or_modified': self.tmpl_inputdatetype(ln=ln), 'date_added' : self.tmpl_inputdate("d1", ln=ln), 'date_until' : self.tmpl_inputdate("d2", ln=ln), 'msg_sort' : _("Sort by:"), 'msg_display' : _("Display results:"), 'msg_format' : _("Output format:"), 'sortoptions' : sortoptions, 'rankoptions' : rankoptions, 'displayoptions' : displayoptions, 'formatoptions' : formatoptions } return out def tmpl_narrowsearch(self, aas, ln, type, father, has_grandchildren, sons, display_grandsons, grandsons): """ EPFL Creates list of collection descendants of type *type* under title *title*. If aas==1, then links to Advanced Search interfaces; otherwise Simple Search. Suitable for 'Narrow search' and 'Focus on' boxes. Parameters: - 'aas' *bool* - Should we display an advanced search box? - 'ln' *string* - The language to display - 'type' *string* - The type of the produced box (virtual collections or normal collections) - 'father' *collection* - The current collection - 'has_grandchildren' *bool* - If the current collection has grand children - 'sons' *list* - The list of the sub-collections (first level) - 'display_grandsons' *bool* - If the grand children collections should be displayed (2 level deep display) - 'grandsons' *list* - The list of sub-collections (second level) """ _ = gettext_set_language(ln) out = """
  • %(label)s
      %(subcollections)s
  • """ if type == 'r': label = _("Search specifically in") elif type == 'v': label = _("Focus on") son_accro_tmpl = """
  • %(acronym)s %(name)s %(nb)s %(grandchildren)s
  • """ grandson_accro_tmpl = """
  • %(acronym)s %(name)s %(nb)s
  • """ son_tmpl = """
  • %(name)s %(nb)s %(grandchildren)s
  • """ grandson_tmpl = """
  • %(name)s %(nb)s
  • """ subcollections = [] for son_index, son in enumerate(sons): try: splitted_name = son.get_name(ln).split(' - ') acronym = splitted_name[0] name = ' - '.join(splitted_name[1:]) tmpl = son_accro_tmpl except ValueError: acronym = '' name = son.get_name(ln) tmpl = son_tmpl grandchildren = '' if has_grandchildren: grandchildren = """ """ subsubcollections = [] for grandson in grandsons[son_index]: try: splitted_name = grandson.get_name(ln).split(' - ') subacronym = splitted_name[0] subname = ' - '.join(splitted_name[1:]) grand_tmpl = grandson_accro_tmpl except ValueError: (subacronym, subname) = ('', grandson.get_name(ln)) grand_tmpl = grandson_tmpl subsubcollections.append(grand_tmpl % {'url': self.build_search_interface_url(c=grandson.name, ln=ln, aas=aas), 'acronym': subacronym, 'name': subname, 'nb': self.tmpl_nbrecs_info(grandson.nbrecs, ln=ln) }) grandchildren %=''.join(subsubcollections) subcollections.append(tmpl % {'url': self.build_search_interface_url(c=son.name, ln=ln, aas=aas), 'acronym': acronym, 'name': name, 'nb': self.tmpl_nbrecs_info(son.nbrecs, ln=ln), 'grandchildren': grandchildren }) return out % {'label': label, 'subcollections': '\n'.join(subcollections)} def tmpl_instant_browse(self, aas, ln, recids, more_link = None): """ EPFL Formats a list of records (given in the recids list) from the database. Parameters: - 'aas' *int* - Advanced Search interface or not (0 or 1) - 'ln' *string* - The language to display - 'recids' *list* - the list of records from the database - 'more_link' *string* - the "More..." link for the record. If not given, will not be displayed """ # load the right message language _ = gettext_set_language(ln) body = """ """ if more_link: body += '
    ' + \ create_html_link(more_link, {}, '[>> %s]' % _("more")) + \ '
    ' return body def tmpl_searchwithin_select(self, ln, fieldname, selected, values): """ EPFL Produces 'search within' selection box for the current collection. Parameters: - 'ln' *string* - The language to display - 'fieldname' *string* - the name of the select box produced - 'selected' *string* - which of the values is selected - 'values' *list* - the list of values in the select """ _ = gettext_set_language(ln) out = """ %s """ tmpl = """
  • """ values = [{'value': '', 'text': _("Any field")}, {'value': 'title', 'text': _("Title")}, {'value': 'author', 'text': _("Author")}, {'value': 'keyword', 'text': _("Keyword")}, {'value': 'year', 'text': _("Year")}, {'value': 'source', 'text': _("Source")}, {'value': 'reportnumber', 'text': _("Report number")}, {'value': 'doi', 'text': _("DOI")},] lines = [] s_label = _("Any field") for pair in values: lines.append(tmpl % {'fieldname': fieldname, 'value': pair['value'], 'label': pair['text'], 'checked': pair['value'] == selected and 'checked="checked"' or '', 'checked_class': pair['value'] == selected and 'class="current"' or ''}) if selected == pair['value']: s_label = pair['text'] return out % (s_label, ''.join(lines)) def tmpl_record_links(self, recid, ln, sf='', so='d', sp='', rm=''): """ EPFL Displays the *More info* and *Find similar* links for a record Parameters: - 'ln' *string* - The language to display - 'recid' *string* - the id of the displayed record """ return self.tmpl_print_record_brief_links(ln=ln, recID=recid, sf=sf, so=so, sp=sp, rm=rm, user_info=None) def tmpl_search_in_bibwords(self, p, f, ln, nearest_box): """ Displays the *Words like current ones* links for a search Parameters: - 'p' *string* - Current search words - 'f' *string* - the fields in which the search was done - 'nearest_box' *string* - the HTML code for the "nearest_terms" box - most probably from a create_nearest_terms_box call """ # load the right message language _ = gettext_set_language(ln) out = '

    ' if f: out += _("Words nearest to %(x_word)s inside %(x_field)s in any collection are:") % {'x_word': '' + cgi.escape(p) + '', 'x_field': '' + cgi.escape(f) + ''} else: out += _("Words nearest to %(x_word)s in any collection are:") % {'x_word': '' + cgi.escape(p) + ''} out += '
    ' + nearest_box + '

    ' return out def tmpl_nearest_term_box(self, p, ln, f, terminfo, intro): """ EPFL Displays the *Nearest search terms* box Parameters: - 'p' *string* - Current search words - 'f' *string* - a collection description (if the search has been completed in a collection) - 'ln' *string* - The language to display - 'terminfo': tuple (term, hits, argd) for each near term - 'intro' *string* - the intro HTML to prefix the box with """ _ = gettext_set_language(ln) out = """ %s """ tmpl = """
  • %(term)s (%(hits)s)
  • """ definitions = [] for term, hits, argd in terminfo: if hits: hitsinfo = _("%s results") % str(hits) else: hitsinfo = _("%s results") % str(0) term = cgi.escape(term) if term == p: # print search word for orientation: if hits > 0: term = create_html_link(self.build_search_url(argd), {}, term) else: term = create_html_link(self.build_search_url(argd), {}, term) definitions.append(tmpl % {'hits': hitsinfo, 'term': term}) return out % (intro, ''.join(definitions)) def tmpl_browse_pattern(self, f, fn, ln, browsed_phrases_in_colls, colls, rg): """ Displays the *Nearest search terms* box Parameters: - 'f' *string* - field (*not* i18nized) - 'fn' *string* - field name (i18nized) - 'ln' *string* - The language to display - 'browsed_phrases_in_colls' *array* - the phrases to display - 'colls' *array* - the list of collection parameters of the search (c's) - 'rg' *int* - the number of records """ # load the right message language _ = gettext_set_language(ln) out = """""" % { 'hits' : _("Hits"), 'fn' : cgi.escape(fn) } if len(browsed_phrases_in_colls) == 1: # one hit only found: phrase, nbhits = browsed_phrases_in_colls[0][0], browsed_phrases_in_colls[0][1] query = {'c': colls, 'ln': ln, 'p': '"%s"' % phrase.replace('"', '\\"'), 'f': f, 'rg' : rg} out += """""" % {'nbhits': nbhits, 'link': create_html_link(self.build_search_url(query), {}, cgi.escape(phrase))} elif len(browsed_phrases_in_colls) > 1: # first display what was found but the last one: for phrase, nbhits in browsed_phrases_in_colls[:-1]: query = {'c': colls, 'ln': ln, 'p': '"%s"' % phrase.replace('"', '\\"'), 'f': f, 'rg' : rg} out += """""" % {'nbhits' : nbhits, 'link': create_html_link(self.build_search_url(query), {}, cgi.escape(phrase))} # now display last hit as "previous term": phrase, nbhits = browsed_phrases_in_colls[0] query_previous = {'c': colls, 'ln': ln, 'p': '"%s"' % phrase.replace('"', '\\"'), 'f': f, 'rg' : rg} # now display last hit as "next term": phrase, nbhits = browsed_phrases_in_colls[-1] query_next = {'c': colls, 'ln': ln, 'p': '"%s"' % phrase.replace('"', '\\"'), 'f': f, 'rg' : rg} out += """""" % {'link_previous': create_html_link(self.build_search_url(query_previous, action='browse'), {}, _("Previous")), 'link_next': create_html_link(self.build_search_url(query_next, action='browse'), {}, _("next")), 'siteurl' : CFG_SITE_URL} out += """
    %(hits)s   %(fn)s
    %(nbhits)s   %(link)s
    %(nbhits)s   %(link)s
      %(link_previous)s %(link_next)s
    """ return out def tmpl_search_box(self, ln, aas, cc, cc_intl, ot, sp, action, fieldslist, f1, f2, f3, m1, m2, m3, p1, p2, p3, op1, op2, rm, p, f, coll_selects, d1y, d2y, d1m, d2m, d1d, d2d, dt, sort_fields, sf, so, ranks, sc, rg, formats, of, pl, jrec, ec, show_colls=True, show_title=True, ext=None): """ EPFL Displays the *Nearest search terms* box Parameters: - 'ln' *string* - The language to display - 'aas' *bool* - Should we display an advanced search box? -1 -> 1, from simpler to more advanced - 'cc_intl' *string* - the i18nized current collection name, used for display - 'cc' *string* - the internal current collection name - 'ot', 'sp' *string* - hidden values - 'action' *string* - the action demanded by the user - 'fieldslist' *list* - the list of all fields available, for use in select within boxes in advanced search - 'p, f, f1, f2, f3, m1, m2, m3, p1, p2, p3, op1, op2, op3, rm' *strings* - the search parameters - 'coll_selects' *array* - a list of lists, each containing the collections selects to display - 'd1y, d2y, d1m, d2m, d1d, d2d' *int* - the search between dates - 'dt' *string* - the dates' types (creation dates, modification dates) - 'sort_fields' *array* - the select information for the sort fields - 'sf' *string* - the currently selected sort field - 'so' *string* - the currently selected sort order ("a" or "d") - 'ranks' *array* - ranking methods - 'rm' *string* - selected ranking method - 'sc' *string* - split by collection or not - 'rg' *string* - selected results/page - 'formats' *array* - available output formats - 'of' *string* - the selected output format - 'pl' *string* - `limit to' search pattern - show_colls *bool* - propose coll selection box? - show_title *bool* show cc_intl in page title? """ # load the right message language _ = gettext_set_language(ln) out = "" if aas == -1: argd = drop_default_urlargd({ 'ln': ln, 'aas': aas, 'ot': ot, 'sp': sp, 'ec': ec, }, self.search_results_default_urlargd) else: argd = drop_default_urlargd({ 'cc': cc, 'ln': ln, 'aas': aas, 'ot': ot, 'sp': sp, 'ec': ec, }, self.search_results_default_urlargd) asearchurl = self.build_search_interface_url(c=cc, **argd) if show_title: out += """

    %(ccname)s

    """ else: out += """

    %s

    """ % _("Search results") out += """
    %(hidden_fields)s
    %(search_within)s
    %(help_label)s
    %(help_section)s
    """ return out % {'ccname': cc_intl, 'hidden_fields': ''.join([self.tmpl_input_hidden(field, value) for (field, value) in argd.items()]), 'search_within': self.tmpl_searchwithin_select(ln=ln, fieldname='f', selected=f, values=[]), 'advanced_class': aas == 1 and 'toggled-active' or '', 'toggled': aas == 0 and 'style="display: none"' or '', 'pattern': aas==0 and p or p1, 'asearch_url': asearchurl, 'label': _("Search"), 'help_label': _("Search Tips"), 'advanced_label': _("Advanced Search"), 'advanced_box': self.tmpl_advanced_search_box(ln, ext), 'help_section': self.tmpl_search_help(ln), } if show_colls and aas > -1: # display collections only if there is more than one selects = '' for sel in coll_selects: selects += self.tmpl_select(fieldname='c', values=sel) out += """ """ % { 'leading' : leadingtext, 'msg_coll' : _("collections"), 'colls' : selects, } ## thirdly, print search limits, if applicable: if action != _("Browse") and pl: out += """""" % { 'limitto' : _("Limit to:"), 'sizepattern' : CFG_WEBSEARCH_ADVANCEDSEARCH_PATTERN_BOX_WIDTH, 'pl' : cgi.escape(pl, 1), } ## fourthly, print from/until date boxen, if applicable: if action == _("Browse") or (d1y==0 and d1m==0 and d1d==0 and d2y==0 and d2m==0 and d2d==0): pass # do not need it else: cell_6_a = self.tmpl_inputdatetype(dt, ln) + self.tmpl_inputdate("d1", ln, d1y, d1m, d1d) cell_6_b = self.tmpl_inputdate("d2", ln, d2y, d2m, d2d) out += """""" % { 'added' : _("Added/modified since:"), 'until' : _("until:"), 'added_or_modified': self.tmpl_inputdatetype(dt, ln), 'date1' : self.tmpl_inputdate("d1", ln, d1y, d1m, d1d), 'date2' : self.tmpl_inputdate("d2", ln, d2y, d2m, d2d), } ## fifthly, print Display results box, including sort/rank, formats, etc: if action != _("Browse") and aas > -1: rgs = [] for i in [10, 25, 50, 100, 250, 500]: if i <= CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS: rgs.append({ 'value' : i, 'text' : "%d %s" % (i, _("results"))}) # enrich sort fields list if we are sorting by some MARC tag: sort_fields = self._add_mark_to_field(value=sf, fields=sort_fields, ln=ln) # create sort by HTML box: out += """""" % { 'sort_by' : _("Sort by:"), 'display_res' : _("Display results:"), 'out_format' : _("Output format:"), 'select_sf' : self.tmpl_select(fieldname = 'sf', values = sort_fields, selected = sf, css_class = 'address'), 'select_so' : self.tmpl_select(fieldname = 'so', values = [{ 'value' : 'a', 'text' : _("asc.") }, { 'value' : 'd', 'text' : _("desc.") }], selected = so, css_class = 'address'), 'select_rm' : self.tmpl_select(fieldname = 'rm', values = ranks, selected = rm, css_class = 'address'), 'select_rg' : self.tmpl_select(fieldname = 'rg', values = rgs, selected = rg, css_class = 'address'), 'select_sc' : self.tmpl_select(fieldname = 'sc', values = [{ 'value' : 0, 'text' : _("single list") }, { 'value' : 1, 'text' : _("split by collection") }], selected = sc, css_class = 'address'), 'select_of' : self.tmpl_select( fieldname = 'of', selected = of, values = self._add_mark_to_field(value=of, fields=formats, chars=3, ln=ln), css_class = 'address'), } ## last but not least, print end of search box: out += """""" return out def tmpl_search_pagestart(self, user_info, rss_url='', ln=CFG_SITE_LANG) : "EPFL page start for search page. Will display after the page header" _ = gettext_set_language(ln) rss_button = '' basket_button = '' if rss_url: rss_button = """ """ % rss_url basket_modal = '' if user_info and not int(user_info.get('guest', '1')): uid = user_info.get('uid', -1) import invenio.webbasket_dblayer as db personal_basket_list = db.get_all_personal_basket_ids_and_names_by_topic_for_add_to_list(uid) group_basket_list = db.get_all_group_basket_ids_and_names_by_group_for_add_to_list(uid) from invenio.webbasket_templates_epfl import create_add_box_select_options options = create_add_box_select_options('', '', personal_basket_list, group_basket_list, ln) basket_modal = """ """ % {'title': _("Add record to collection"), 'choose_basket_label': _("Please choose a collection"), 'create_label': _("or %(x_url_open)screate a new one%(x_url_close)s first") % {'x_url_open': '' % ln, 'x_url_close': ''}, 'baskets_list': options, 'mandatory_label': _("This field is required"), 'submit_label': _("Add record"), 'cancel_label': _("Cancel")} out = """
    %(basket_modal)s""" return out % {'rss': rss_button, 'basket_modal': basket_modal, 'export_label': _('Export'), 'export_web_label': _("Integrate these publications into my website")} def tmpl_search_pageend(self, ln) : "EPFL page end for search page. Will display just before the page footer" _ = gettext_set_language(ln) out = """
    """ return out def tmpl_print_warning(self, msg, type, prologue, epilogue): """ EPFL Prints warning message and flushes output. Parameters: - 'msg' *string* - The message string - 'type' *string* - the warning type - 'prologue' *string* - HTML code to display before the warning - 'epilogue' *string* - HTML code to display after the warning """ out = """

    %s

    """ if type: msg = '%s: %s' % (type, msg) return out % msg def tmpl_pagination(self, query_params, nb_recs, recs_per_page, jrec, ln): """EPFL """ def get_link(page): if not 'rg' in query_params: return self.build_search_url(jrec= 1 + (page -1) * recs_per_page, rg=recs_per_page, **query_params) return self.build_search_url(jrec= 1 + (page -1) * recs_per_page, **query_params) _ = gettext_set_language(ln) LEADING_PAGE_RANGE_DISPLAYED = TRAILING_PAGE_RANGE_DISPLAYED = 5 LEADING_PAGE_RANGE = TRAILING_PAGE_RANGE = 4 NUM_PAGES_OUTSIDE_RANGE = 2 ADJACENT_PAGES = 2 in_leading_range = in_trailing_range = False pages_outside_leading_range = pages_outside_trailing_range = range(0) total_nb_pages = int(math.ceil(float(nb_recs) / float(recs_per_page))) current_page = (jrec / recs_per_page) + 1 if total_nb_pages <= LEADING_PAGE_RANGE_DISPLAYED: in_leading_range = in_trailing_range = True page_numbers = [n for n in range(1, total_nb_pages + 1)] elif current_page <= LEADING_PAGE_RANGE: in_leading_range = True page_numbers = [n for n in range(1, LEADING_PAGE_RANGE_DISPLAYED + 1) if n > 0 and n <= total_nb_pages] pages_outside_leading_range = [n + total_nb_pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)] pages_outside_leading_range.reverse() elif current_page > total_nb_pages - TRAILING_PAGE_RANGE: in_trailing_range = True page_numbers = [n for n in range(total_nb_pages - TRAILING_PAGE_RANGE_DISPLAYED + 1, total_nb_pages + 1) if n > 0 and n <= total_nb_pages] pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)] else: page_numbers = [n for n in range(current_page - ADJACENT_PAGES, current_page + ADJACENT_PAGES + 1) if n > 0 and n <= total_nb_pages] pages_outside_leading_range = [n + total_nb_pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)] pages_outside_leading_range.reverse() pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)] page_tmpl = """
  • %s
  • """ separator = """
  • ...
  • """ out = """
    """ return out def tmpl_print_search_info(self, ln, middle_only, collection, collection_name, collection_id, aas, sf, so, rm, rg, nb_found, of, ot, p, f, f1, f2, f3, m1, m2, m3, op1, op2, p1, p2, p3, d1y, d1m, d1d, d2y, d2m, d2d, dt, all_fieldcodes, cpu_time, pl_in_url, jrec, sc, sp, ext): """ EPFL Prints stripe with the information on 'collection' and 'nb_found' results and CPU time. Also, prints navigation links (beg/next/prev/end) inside the results set. If middle_only is set to 1, it will only print the middle box information (beg/netx/prev/end/etc) links. This is suitable for displaying navigation links at the bottom of the search results page. Parameters: - 'ln' *string* - The language to display - 'middle_only' *bool* - Only display parts of the interface - 'collection' *string* - the collection name - 'collection_name' *string* - the i18nized current collection name - 'aas' *bool* - if we display the advanced search interface - 'sf' *string* - the currently selected sort format - 'so' *string* - the currently selected sort order ("a" or "d") - 'rm' *string* - selected ranking method - 'rg' *int* - selected results/page - 'nb_found' *int* - number of results found - 'of' *string* - the selected output format - 'ot' *string* - hidden values - 'p' *string* - Current search words - 'f' *string* - the fields in which the search was done - 'f1, f2, f3, m1, m2, m3, p1, p2, p3, op1, op2' *strings* - the search parameters - 'jrec' *int* - number of first record on this page - 'd1y, d2y, d1m, d2m, d1d, d2d' *int* - the search between dates - 'dt' *string* the dates' type (creation date, modification date) - 'all_fieldcodes' *array* - all the available fields - 'cpu_time' *float* - the time of the query in seconds """ # load the right message language _ = gettext_set_language(ln) if p2: p = p1 p1 = '' p2 = '' op1 = '' op2 = '' aas = 1 query = {'p': p, 'f': f, 'cc': cgi.escape(collection), 'sf': sf, 'so': so, 'sp': sp, 'rm': rm, 'of': of, 'ot': ot, 'aas': aas, 'ln': ln, 'p1': p1, 'p2': p2, 'p3': p3, 'f1': f1, 'f2': f2, 'f3': f3, 'm1': m1, 'm2': m2, 'm3': m3, 'op1': op1, 'op2': op2, 'sc': sc, 'd1y': d1y, 'd1m': d1m, 'd1d': d1d, 'd2y': d2y, 'd2m': d2m, 'd2d': d2d, 'dt': dt, 'ln': ln, 'ext': ext or [], 'rg': rg, } if middle_only: return self.tmpl_pagination(query_params=query, nb_recs=nb_found, recs_per_page=rg, jrec=jrec, ln=ln) sf_labels = {'': _("Creation date"), 'title': _("Title"), 'author': _("First author"), 'reportnumber': _("Report number"), 'year': _("Publication year")} so_labels = {'a': _("Ascending"), 'd': _("Descending")} of_labels = {'hb': _("HTML brief"), 'hr': _("HTML detailed"), 'hm': _("HTML MARC21")} out = """
    %(records_found_label)s
    """ return out % {'records_found_label': _("%s records found") % self.tmpl_nice_number(nb_found, ln), 'sort_label': _("Sort by"), 'selected_sf': sf_labels.get(sf, sf) , 'collection_id': collection_id, 'sort_by_cd_url': self.build_search_url(query, sf=''), 'sort_by_cd_label': sf_labels.get(''), 'sort_by_year_url': self.build_search_url(query, sf='year'), 'sort_by_year_label': sf_labels.get('year'), 'sort_by_title_url': self.build_search_url(query, sf='title'), 'sort_by_title_label': sf_labels.get('title'), 'sort_by_author_url': self.build_search_url(query, sf='author'), 'sort_by_author_label': sf_labels.get('author'), 'selected_so': so_labels.get(so, so) , 'sort_order_asc_url': self.build_search_url(query, so='a'), 'sort_order_asc_label': so_labels.get('a'), 'sort_order_desc_url': self.build_search_url(query, so='d'), 'sort_order_desc_label': so_labels.get('d'), 'selected_rg': rg, 'results': _("results"), 'nb_results_url': self.build_search_url(query), 'selected_of': of_labels.get(of.lower(), of), 'format_hb_url': self.build_search_url(query, of='hb'), 'format_hb_label': of_labels.get('hb'), 'format_hr_url': self.build_search_url(query, of='hr'), 'format_hr_label': of_labels.get('hr'), 'format_hm_url': self.build_search_url(query, of='hm'), 'format_hm_label': of_labels.get('hm'), } def tmpl_record_format_htmlbrief_header(self, ln): """EPFL Returns the header of the search results list when output is html brief. Note that this function is called for each collection results when 'split by collection' is enabled. See also: tmpl_record_format_htmlbrief_footer, tmpl_record_format_htmlbrief_body Parameters: - 'ln' *string* - The language to display """ # load the right message language _ = gettext_set_language(ln) out = """ """ return out def tmpl_record_format_htmlbrief_body(self, ln, recid, row_number, relevance, record, relevances_prologue, relevances_epilogue, display_add_to_basket=True): """ EPFL Returns the html brief format of one record. Used in the search results list for each record. See also: tmpl_record_format_htmlbrief_header(..), tmpl_record_format_htmlbrief_footer(..) Parameters: - 'ln' *string* - The language to display - 'row_number' *int* - The position of this record in the list - 'recid' *int* - The recID - 'relevance' *string* - The relevance of the record - 'record' *string* - The formatted record - 'relevances_prologue' *string* - HTML code to prepend the relevance indicator - 'relevances_epilogue' *string* - HTML code to append to the relevance indicator (used mostly for formatting) """ # load the right message language _ = gettext_set_language(ln) tmpl = """
  • %(number)s.
    %(record)s
  • """ if False: # TODO: put this feature on when interface is ready to handle checkboxes... #display_add_to_basket: tmpl = """
  • %(number)s.
    %(record)s
  • """ return tmpl % {'recid': recid, 'number': row_number, 'record': record} def tmpl_print_results_overview(self, ln, results_final_nb_total, cpu_time, results_final_nb, colls, ec, hosted_colls_potential_results_p=False): """Prints results overview box with links to particular collections below. Parameters: - 'ln' *string* - The language to display - 'results_final_nb_total' *int* - The total number of hits for the query - 'colls' *array* - The collections with hits, in the format: - 'coll[code]' *string* - The code of the collection (canonical name) - 'coll[name]' *string* - The display name of the collection - 'results_final_nb' *array* - The number of hits, indexed by the collection codes: - 'cpu_time' *string* - The time the query took - 'url_args' *string* - The rest of the search query - 'ec' *array* - selected external collections - 'hosted_colls_potential_results_p' *boolean* - check if there are any hosted collections searches that timed out during the pre-search """ if len(colls) == 1 and not ec: # if one collection only and no external collections, print nothing: return "" # load the right message language _ = gettext_set_language(ln) # first find total number of hits: # if there were no hosted collections that timed out during the pre-search print out the exact number of records found if not hosted_colls_potential_results_p: out = """
    %(founds)s
    """ % { 'founds' : _("%(x_fmt_open)sResults overview:%(x_fmt_close)s Found %(x_nb_records)s records in %(x_nb_seconds)s seconds.") %\ {'x_fmt_open': '', 'x_fmt_close': '', 'x_nb_records': '' + self.tmpl_nice_number(results_final_nb_total, ln) + '', 'x_nb_seconds': '%.2f' % cpu_time} } # if there were (only) hosted_collections that timed out during the pre-search print out a fuzzier message else: if results_final_nb_total == 0: out = """
    %(founds)s
    """ % { 'founds' : _("%(x_fmt_open)sResults overview%(x_fmt_close)s") %\ {'x_fmt_open': '', 'x_fmt_close': ''} } elif results_final_nb_total > 0: out = """
    %(founds)s
    """ % { 'founds' : _("%(x_fmt_open)sResults overview:%(x_fmt_close)s Found at least %(x_nb_records)s records in %(x_nb_seconds)s seconds.") %\ {'x_fmt_open': '', 'x_fmt_close': '', 'x_nb_records': '' + self.tmpl_nice_number(results_final_nb_total, ln) + '', 'x_nb_seconds': '%.2f' % cpu_time} } # then print hits per collection: for coll in colls: if results_final_nb.has_key(coll['code']) and results_final_nb[coll['code']] > 0: out += """ %(coll_name)s, %(number)s
    """ % \ {'coll' : coll['id'], 'coll_name' : cgi.escape(coll['name']), 'number' : _("%s records found") % \ ('' + self.tmpl_nice_number(results_final_nb[coll['code']], ln) + '')} # the following is used for hosted collections that have timed out, # i.e. for which we don't know the exact number of results yet. elif results_final_nb.has_key(coll['code']) and results_final_nb[coll['code']] == -963: out += """ %(coll_name)s
    """ % \ {'coll' : coll['id'], 'coll_name' : cgi.escape(coll['name']), 'number' : _("%s records found") % \ ('' + self.tmpl_nice_number(results_final_nb[coll['code']], ln) + '')} out += "
    " return out def tmpl_print_searchresultbox(self, header, body): """print a nicely formatted box for search results """ #_ = gettext_set_language(ln) # first find total number of hits: out = '
    '+header+'
    '+body+'
    ' return out def tmpl_search_no_boolean_hits(self, ln, nearestterms): """No hits found, proposes alternative boolean queries Parameters: - 'ln' *string* - The language to display - 'nearestterms' *array* - Parts of the interface to display, in the format: - 'nearestterms[nbhits]' *int* - The resulting number of hits - 'nearestterms[url_args]' *string* - The search parameters - 'nearestterms[p]' *string* - The search terms """ # load the right message language _ = gettext_set_language(ln) out = _("Boolean query returned no hits. Please combine your search terms differently.") out += '''
    ''' for term, hits, argd in nearestterms: out += '''\ ''' % {'hits' : hits, 'link': create_html_link(self.build_search_url(argd), {}, cgi.escape(term), {'class': "nearestterms"})} out += """
    %(hits)s   %(link)s
    """ return out def tmpl_similar_author_names(self, authors, ln): """No hits found, proposes alternative boolean queries Parameters: - 'authors': a list of (name, hits) tuples - 'ln' *string* - The language to display """ # load the right message language _ = gettext_set_language(ln) out = ''' ''' % { 'similar' : _("See also: similar author names") } for author, hits in authors: out += '''\ ''' % {'link': create_html_link( self.build_search_url(p=author, f='author', ln=ln), {}, cgi.escape(author), {'class':"google"}), 'nb' : hits} out += """
    %(similar)s
    %(nb)d %(link)s
    """ return out def tmpl_print_record_list_for_similarity_boxen(self, title, recID_score_list, ln=CFG_SITE_LANG): """Print list of records in the "hs" (HTML Similarity) format for similarity boxes. RECID_SCORE_LIST is a list of (recID1, score1), (recID2, score2), etc. """ from invenio.search_engine import print_record, record_public_p recID_score_list_to_be_printed = [] # firstly find 5 first public records to print: nb_records_to_be_printed = 0 nb_records_seen = 0 while nb_records_to_be_printed < 5 and nb_records_seen < len(recID_score_list) and nb_records_seen < 50: # looking through first 50 records only, picking first 5 public ones (recID, score) = recID_score_list[nb_records_seen] nb_records_seen += 1 if record_public_p(recID): nb_records_to_be_printed += 1 recID_score_list_to_be_printed.append([recID, score]) # secondly print them: out = '''
    %(title)s
    ''' % { 'title': cgi.escape(title) } for recid, score in recID_score_list_to_be_printed: out += ''' ''' % { 'score': score, 'info' : print_record(recid, format="hs", ln=ln), } out += """
    (%(score)s)  %(info)s
    """ return out def tmpl_print_record_brief_links(self, ln, recID, sf='', so='d', sp='', rm='', user_info=None): """ EPFL Displays links for brief record on-the-fly Parameters: - 'ln' *string* - The language to display - 'recID' *int* - The record id """ # load the right message language _ = gettext_set_language(ln) links = [] #links.append(create_html_link(self.build_search_url(p="recid:%d" % recID, rm="wrd", ln=ln), # {}, _("Similar records"), # {'class': "infoscience_link_similar"})) if user_info and user_info.get('guest', '1') == '0': links.append(create_html_link('/yourbaskets/add', {'recid': recID, 'ln': ln}, _("Add to my collections"), {'class': "infoscience_link_basket modal-opener", 'rel': '#basket_modal'})) out = '%s' return out % ''.join(links) def tmpl_collection_not_found_page_body(self, colname, ln=CFG_SITE_LANG): """ Create page body for cases when unexisting collection was asked for. """ _ = gettext_set_language(ln) out = """

    %(title)s

    %(sorry)s

    %(you_may_want)s

    """ % { 'title': self.tmpl_collection_not_found_page_title(colname, ln), 'sorry': _("Sorry, collection %s does not seem to exist.") % \ ('' + cgi.escape(colname) + ''), 'you_may_want': _("You may want to start browsing from %s.") % \ ('' + \ cgi.escape(CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME)) + '')} return out def tmpl_alert_rss_teaser_box_for_query(self, id_query, ln, display_email_alert_part=True): """ EPFL Propose teaser for setting up this query as alert or RSS feed. Parameters: - 'id_query' *int* - ID of the query we make teaser for - 'ln' *string* - The language to display - 'display_email_alert_part' *bool* - whether to display email alert part """ return '' def tmpl_detailed_record_metadata(self, recID, ln, format, content, creationdate=None, modificationdate=None): """Returns the main detailed page of a record Parameters: - 'recID' *int* - The ID of the printed record - 'ln' *string* - The language to display - 'format' *string* - The format in used to print the record - 'content' *string* - The main content of the page - 'creationdate' *string* - The creation date of the printed record - 'modificationdate' *string* - The last modification date of the printed record """ _ = gettext_set_language(ln) ## unAPI identifier out = '\n' % recID out += content return out def tmpl_record_plots(self, recID, ln): """ Displays little tables containing the images and captions contained in the specified document. Parameters: - 'recID' *int* - The ID of the printed record - 'ln' *string* - The language to display """ from invenio.search_engine import get_record from invenio.bibrecord import field_get_subfield_values from invenio.bibrecord import record_get_field_instances _ = gettext_set_language(ln) out = '' rec = get_record(recID) flds = record_get_field_instances(rec, '856', '4') images = [] for fld in flds: image = field_get_subfield_values(fld, 'u') caption = field_get_subfield_values(fld, 'y') if type(image) == list and len(image) > 0: image = image[0] else: continue if type(caption) == list and len(caption) > 0: caption = caption[0] else: continue if not image.endswith('.png'): # huh? continue if len(caption) >= 5: images.append((int(caption[:5]), image, caption[5:])) else: # we don't have any idea of the order... just put it on images.append(99999, image, caption) images = sorted(images, key=lambda x: x[0]) for (index, image, caption) in images: # let's put everything in nice little subtables with the image # next to the caption out = out + '' +\ '' +\ '' +\ '
    ' +\ '' + caption + '
    ' out = out + '

    ' return out def tmpl_detailed_record_statistics(self, recID, ln, downloadsimilarity, downloadhistory, viewsimilarity): """Returns the statistics page of a record Parameters: - 'recID' *int* - The ID of the printed record - 'ln' *string* - The language to display - downloadsimilarity *string* - downloadsimilarity box - downloadhistory *string* - downloadhistory box - viewsimilarity *string* - viewsimilarity box """ # load the right message language _ = gettext_set_language(ln) out = '' if CFG_BIBRANK_SHOW_DOWNLOAD_STATS and downloadsimilarity is not None: similar = self.tmpl_print_record_list_for_similarity_boxen ( _("People who downloaded this document also downloaded:"), downloadsimilarity, ln) out = '' out += ''' ''' % { 'siteurl': CFG_SITE_URL, 'recid': recID, 'ln': ln, 'similar': similar, 'more': _("more"), 'graph': downloadsimilarity } out += '
    %(graph)s
    %(similar)s
    ' out += '
    ' if CFG_BIBRANK_SHOW_READING_STATS and viewsimilarity is not None: out += self.tmpl_print_record_list_for_similarity_boxen ( _("People who viewed this page also viewed:"), viewsimilarity, ln) if CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS and downloadhistory is not None: out += downloadhistory + '
    ' return out def tmpl_author_information(self, req, pubs, authorname, num_downloads, aff_pubdict, citedbylist, kwtuples, authors, vtuples, ln): """Prints stuff about the author given as authorname. 1. Author name + his/her institutes. Each institute I has a link to papers where the auhtor has I as institute. 2. Publications, number: link to search by author. 3. Keywords 4. Author collabs 5. Publication venues like journals The parameters are data structures needed to produce 1-6, as follows: req - request pubs - list of recids, probably the records that have the author as an author authorname - evident num_downloads - evident aff_pubdict - a dictionary where keys are inst names and values lists of recordids citedbylist - list of recs that cite pubs kwtuples - keyword tuples like ('HIGGS BOSON',[3,4]) where 3 and 4 are recids authors - a list of authors that have collaborated with authorname """ from invenio.search_engine import perform_request_search _ = gettext_set_language(ln) #make a authoraff string that looks like CERN (1), Caltech (2) etc authoraff = "" aff_pubdict_keys = aff_pubdict.keys() aff_pubdict_keys.sort(lambda x, y: cmp(len(aff_pubdict[y]), len(aff_pubdict[x]))) for a in aff_pubdict_keys: recids = "+or+".join(map(str, aff_pubdict[a])) print_a = a if (print_a == ' '): print_a = _("unknown") if authoraff: authoraff += '
    ' authoraff += ""+print_a+' ('+str(len(aff_pubdict[a]))+")" #print a "general" banner about the author req.write("

    " + authorname + "

    ") # print papers: searchstr = create_html_link(self.build_search_url(p=authorname, f='exactauthor'), {}, "All papers ("+str(len(pubs))+")",) line1 = "" + _("Papers:") + "" line2 = searchstr if CFG_BIBRANK_SHOW_DOWNLOAD_STATS and num_downloads: line2 += " ("+_("downloaded")+" " line2 += str(num_downloads)+" "+_("times")+")" if CFG_INSPIRE_SITE: CFG_COLLS = ['Book', 'Conference', 'Introductory', 'Lectures', 'Preprint', 'Published', 'Report', 'Review', 'Thesis'] else: CFG_COLLS = ['Article', 'Book', 'Preprint',] collsd = {} for coll in CFG_COLLS: coll_num_papers = len(intbitset(pubs) & intbitset(perform_request_search(p="collection:"+coll))) if coll_num_papers: collsd[coll] = coll_num_papers colls = collsd.keys() colls.sort(lambda x, y: cmp(collsd[y], collsd[x])) # sort by number of papers for coll in colls: line2 += "
    " + create_html_link(self.build_search_url(p='exactauthor:"' + authorname + '" ' + \ 'collection:' + coll), {}, coll + " ("+str(collsd[coll])+")",) banner = self.tmpl_print_searchresultbox(line1, line2) req.write("") #print affiliations line1 = "" + _("Affiliations:") + "" line2 = authoraff req.write("") # print frequent keywords: keywstr = "" if (kwtuples): for (kw, freq) in kwtuples: if keywstr: keywstr += '
    ' #create a link in author=x, keyword=y searchstr = create_html_link(self.build_search_url( p='exactauthor:"' + authorname + '" ' + 'keyword:"' + kw + '"'), {}, kw+" ("+str(freq)+")",) keywstr = keywstr+" "+searchstr else: keywstr += 'No Keywords found' banner = self.tmpl_print_searchresultbox("" + _("Frequent keywords:") + "", keywstr) req.write("") # print frequent co-authors: collabstr = "" if (authors): for c in authors: c = c.strip() if collabstr: collabstr += '
    ' #do not add this person him/herself in the list cUP = c.upper() authornameUP = authorname.upper() if not cUP == authornameUP: commpubs = intbitset(pubs) & intbitset(perform_request_search(p="exactauthor:\"%s\" exactauthor:\"%s\"" % (authorname, c))) collabstr = collabstr + create_html_link(self.build_search_url(p='exactauthor:"' + authorname + '" exactauthor:"' + c + '"' ), {}, c + " (" + str(len(commpubs)) + ")",) else: collabstr += 'None' banner = self.tmpl_print_searchresultbox("" + _("Frequent co-authors:") + "", collabstr) req.write("
    ") req.write(banner) req.write(" ") req.write(self.tmpl_print_searchresultbox(line1, line2)) req.write("
    ") req.write(banner) req.write(" ") req.write(banner) req.write("
    ") # print frequently publishes in journals: #if (vtuples): # pubinfo = "" # for t in vtuples: # (journal, num) = t # pubinfo += create_html_link(self.build_search_url(p='exactauthor:"' + authorname + '" ' + \ # 'journal:"' + journal + '"'), # {}, journal + " ("+str(num)+")
    ") # banner = self.tmpl_print_searchresultbox("" + _("Frequently publishes in:") + "", pubinfo) # req.write(banner) # print citations: if len(citedbylist): line1 = "" + _("Citations:") + "" line2 = "" req.write(self.tmpl_print_searchresultbox(line1, line2)) # they will be printed after that