diff --git a/modules/webstyle/lib/Makefile.am b/modules/webstyle/lib/Makefile.am index db58d1aad..ca5a8d309 100644 --- a/modules/webstyle/lib/Makefile.am +++ b/modules/webstyle/lib/Makefile.am @@ -1,43 +1,46 @@ ## This file is part of Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. pylibdir=$(libdir)/python/invenio wsgiwebdir=$(localstatedir)/www-wsgi/ pylib_DATA = webdoc.py \ webdoc_tests.py \ webdoc_webinterface.py \ webpage.py \ template.py \ webstyle_templates.py \ webstyle_regression_tests.py \ webinterface_handler.py \ webinterface_tests.py \ webinterface_layout.py \ fckeditor_invenio_connector.py \ webinterface_handler_wsgi.py \ webinterface_handler_wsgi_utils.py \ webinterface_handler_config.py \ httptest_webinterface.py \ webstyle_templates_epfl.py \ + header.sig.html \ + header-no-local-search.en.html \ + header-no-local-search.fr.html \ ping_webinterface.py wsgiweb_DATA = invenio.wsgi EXTRA_DIST = $(pylib_DATA) $(wsgiweb_DATA) CLEANFILES = *~ *.tmp *.pyc diff --git a/modules/webstyle/lib/webstyle_templates_epfl.py b/modules/webstyle/lib/webstyle_templates_epfl.py index 7f6e880b4..226448b53 100644 --- a/modules/webstyle/lib/webstyle_templates_epfl.py +++ b/modules/webstyle/lib/webstyle_templates_epfl.py @@ -1,619 +1,595 @@ # -*- coding: utf-8 -*- """ EPFL templates. Webstyle handles header, general page design and main navigation. """ import os import urllib, cgi from datetime import datetime from invenio.config import CFG_SITE_LANG, CFG_SITE_URL, CFG_SITE_SECURE_URL, CFG_SITE_NAME, CFG_SITE_NAME_INTL, CFG_SITE_SUPPORT_EMAIL, CFG_VERSION from invenio.messages import gettext_set_language from invenio.urlutils import make_canonical_urlargd, create_html_link from invenio.webuser import collect_user_info from invenio import webstyle_templates from xml.sax import saxutils class Template(webstyle_templates.Template): """EPFL template""" def tmpl_pageheader(self, req, ln=CFG_SITE_LANG, headertitle="", description="", keywords="", userinfobox="", useractivities_menu="", adminactivities_menu="", navtrailbox="", pageheaderadd="", uid=0, secure_page_p=0, navmenuid="admin", metaheaderadd="", rssurl='', body_css_classes=None): if secure_page_p: external_scripts = """ """ else: # secure_page_p seems to be empty all the time... Therefore, we # return https all the time. external_scripts = """ """ rss = '' if rssurl: rss = '' % (CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME), rssurl) out = """\ %(title)s %(rss)s %(external_scripts)s %(signature)s %(metaheaderadd)s %(header)s
%(breadcrumbs)s %(language)s

Infoscience

%(message)s %(navigation)s -""" % {'signature': epfl_header_version(), +""" % {'signature': epfl_header_sig, 'body_css_classes' : body_css_classes and ' class="%s"' % ' '.join(body_css_classes) or '', 'ln' : ln, 'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME), 'sitesupportemail': CFG_SITE_SUPPORT_EMAIL, 'siteurl': CFG_SITE_URL, 'rss': rss, 'unAPIurl': '%s/unapi' % CFG_SITE_URL, 'metaheaderadd': metaheaderadd, - 'header': epfl_header(ln), + 'header': epfl_header_html_fr if ln == 'fr' else epfl_header_html_en, 'title': saxutils.unescape(headertitle), 'breadcrumbs': navtrailbox, 'language': self.tmpl_language_selection_box(req, ln), 'navigation': self.get_navigation(req, useractivities_menu, adminactivities_menu, navmenuid, ln), 'external_scripts': external_scripts, 'message': '' #self.maintenance_warning(ln), } return out def maintenance_warning(self, ln=CFG_SITE_LANG): return """

%(warning)s

%(message)s

""" % { 'warning': ln=='en' and 'Maintenance notice' or 'Avis de maintenance', 'message': ln=='en' and "Due to the moving of its main server, Infoscience will be set in read-only mode from Wednesday, 20th at 18:00 to Friday 22nd at 9:00. We apologize for the inconvenience. Exports of publication lists on your web sites will not be affected." or "Infoscience ne sera accessible qu'en lecture entre le mercredi 20 à 18h et le vendredi 22 à 9h à cause d'un déplacement de serveur. Nous vous prions de nous excuser pour les désagréments. Les exports de listes de publications vers vos sites web continueront de fonctionner."} def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None, pagefooteradd="", ): _ = gettext_set_language(ln) out = """
%(pagefooteradd)s """ % { 'about': ln=='fr' and 'a-propos' or 'about', 'about_label': _("About Infoscience"), 'contact_label': _("Contact"), 'accessibility_label': _("Accessibility"), 'login_link': self.get_login_link(req, ln), 'ln': ln, 'pagefooteradd': pagefooteradd, 'year': datetime.now().year, 'version': CFG_VERSION, } return out def get_login_link(self, req, ln=CFG_SITE_LANG): _ = gettext_set_language(ln) if req: if req.subprocess_env.has_key('HTTPS') \ and req.subprocess_env['HTTPS'] == 'on': url_referer = CFG_SITE_SECURE_URL + req.unparsed_uri else: url_referer = CFG_SITE_URL + req.unparsed_uri if '/youraccount/logout' in url_referer: url_referer = '' else: url_referer = CFG_SITE_URL user_info = collect_user_info(req) if int(user_info.get('guest', '1')): login_link = '%(login)s' % { 'sitesecureurl': CFG_SITE_SECURE_URL, 'ln' : ln, 'referer' : url_referer and ('&referer=%s' % urllib.quote(url_referer)) or '', 'login' : _('Login') } else: login_link = """%(logout)s""" % {'ln' : ln, 'logout' : _("Logout (%(username)s)") % {'username': user_info.get('external_uid', [None])[0] or user_info.get('email')} } return login_link def tmpl_page(self, req=None, ln=CFG_SITE_LANG, description="", keywords="", userinfobox="", useractivities_menu="", adminactivities_menu="", navtrailbox="", pageheaderadd="", boxlefttop="", boxlefttopadd="", boxleftbottom="", boxleftbottomadd="", boxrighttop="", boxrighttopadd="", boxrightbottom="", boxrightbottomadd="", titleprologue="", title="", titleepilogue="", body="", lastupdated=None, pagefooteradd="", uid=0, secure_page_p=0, navmenuid="", metaheaderadd="", rssurl=CFG_SITE_URL+"/rss", show_title_p=True, body_css_classes=None): """Creates a complete page Parameters: - 'ln' *string* - The language to display - 'description' *string* - description goes to the metadata in the header of the HTML page - 'keywords' *string* - keywords goes to the metadata in the header of the HTML page - 'userinfobox' *string* - the HTML code for the user information box - 'useractivities_menu' *string* - the HTML code for the user activities menu - 'adminactivities_menu' *string* - the HTML code for the admin activities menu - 'navtrailbox' *string* - the HTML code for the navigation trail box - 'pageheaderadd' *string* - additional page header HTML code - 'boxlefttop' *string* - left-top box HTML code - 'boxlefttopadd' *string* - additional left-top box HTML code - 'boxleftbottom' *string* - left-bottom box HTML code - 'boxleftbottomadd' *string* - additional left-bottom box HTML code - 'boxrighttop' *string* - right-top box HTML code - 'boxrighttopadd' *string* - additional right-top box HTML code - 'boxrightbottom' *string* - right-bottom box HTML code - 'boxrightbottomadd' *string* - additional right-bottom box HTML code - 'title' *string* - the title of the page - 'titleprologue' *string* - what to print before page title - 'titleepilogue' *string* - what to print after page title - 'body' *string* - the body of the page - 'lastupdated' *string* - when the page was last updated - 'uid' *int* - user ID - 'pagefooteradd' *string* - additional page footer HTML code - 'secure_page_p' *int* (0 or 1) - are we to use HTTPS friendly page elements or not? - 'navmenuid' *string* - the id of the navigation item to highlight for this page - 'metaheaderadd' *string* - list of further tags to add to the part of the page - 'rssurl' *string* - the url of the RSS feed for this page - 'show_title_p' *int* (0 or 1) - do we display the page title in the body of the page? - 'body_css_classes' *list* - list of classes to add to the body tag Output: - HTML code of the page """ # load the right message language _ = gettext_set_language(ln) if title == CFG_SITE_NAME: title = _("Infoscience: Scientific publications of EPFL") else: title = title + ' - Infoscience' header = self.tmpl_pageheader(req, ln = ln, headertitle = title, description = description, keywords = keywords, metaheaderadd = metaheaderadd, userinfobox = userinfobox, navtrailbox = navtrailbox, pageheaderadd = pageheaderadd, secure_page_p = secure_page_p, navmenuid=navmenuid, rssurl=rssurl, body_css_classes=body_css_classes, useractivities_menu=useractivities_menu, adminactivities_menu=adminactivities_menu) footer = self.tmpl_pagefooter(req, ln=ln, lastupdated=lastupdated, pagefooteradd=pagefooteradd) if navmenuid == 'search': #IDEE: trouver un moyen de reconnaitre webcoll: navmenuid=search; délégation de content, right col # search: navmenuid=search; délégation de content et right-col body = body elif navmenuid == 'yourbaskets': body = body elif navmenuid == 'youralerts': body = body elif navmenuid == '503': body = body elif boxlefttop or boxlefttopadd or boxleftbottom or boxleftbottomadd or \ boxrighttop or boxrighttopadd or boxrightbottom or boxrightbottomadd: body = """

%(title)s

%(body)s
%(blt)s %(blta)s %(blba)s %(blb)s %(brt)s %(brta)s %(brba)s %(brb)s
""" % {'title': title, 'body': body, 'navmenuid':navmenuid, 'blt': boxlefttop, 'blta': boxlefttopadd, 'blb': boxleftbottom, 'blba': boxleftbottomadd, 'brt': boxrighttop, 'brta': boxrighttopadd, 'brb': boxrightbottom, 'brba': boxrightbottomadd } else: body = """

%(title)s

%(body)s
""" % {'title': title, 'body': body, 'navmenuid':navmenuid} out = """ %(header)s %(body)s %(footer)s """ % {'header': header, 'title': title, 'navigation': self.get_navigation(req, useractivities_menu, adminactivities_menu, navmenuid, ln), 'body': body, 'footer': footer, } return out def tmpl_language_selection_box(self, req, language=CFG_SITE_LANG): """Take URLARGS and LANGUAGE and return textual language selection box for the given page. Parameters: - 'req' - The mod_python request object - 'language' *string* - The selected language """ _ = gettext_set_language(language) argd = {} if req and req.args: argd.update(cgi.parse_qs(req.args)) if language == 'en': out = """ """ argd['ln'] = 'fr' else: out = """ """ argd['ln'] = 'en' return out % (_("Choose your language"), urllib.quote(req.uri, '/:?') + make_canonical_urlargd(argd, {})) def get_navigation(self, req, useractivities_menu='', adminactivities_menu='', navmenuid='', ln=CFG_SITE_LANG): _ = gettext_set_language(ln) search_menu_cls = '' browse_menu_cls = '' account_menu_cls = '' admin_menu_cls = '' if req.uri.strip() == '/' : search_menu_cls = '' elif req.uri.startswith('/collection/'): browse_menu_cls = 'current' elif navmenuid == 'search': search_menu_cls = 'current' elif navmenuid.startswith('your') or navmenuid == 'personalize': account_menu_cls = 'current' elif navmenuid in ['stats', 'collection population', 'search frequency', 'search type distribution', 'download frequency', 'custom event', 'custom event help', 'export', 'batchuploader', 'admin']: admin_menu_cls = 'current' if adminactivities_menu: admin_menu = """ """ % {'admin_menu_cls': admin_menu_cls, 'admin_menu': adminactivities_menu, 'ln': ln} else: admin_menu = '' if useractivities_menu: account_menu = """ """ % {'label1': _("My account"), 'site_url' : CFG_SITE_URL, 'account_menu_cls': account_menu_cls, 'account_menu': useractivities_menu, 'ln': ln} else: account_menu = '' out = """ """ return out % { 'secure_domain': CFG_SITE_SECURE_URL, 'search_menu_cls': search_menu_cls, 'browse_menu_cls': browse_menu_cls, 'account_menu_cls': account_menu_cls, 'admin_menu': admin_menu, 'account_menu': account_menu, 'ln': ln, 'search_label': _("Search"), 'browse_label': _("Browse"), 'by_school': _("Publications by school"), 'ENAC': _("ENAC - Architecture, Civil and Environmental Engineering"), 'IC': _("I&C - Computer & Communication Sciences"), 'SB': _("SB - Basic Sciences"), 'STI': _("STI - Engineering"), 'SV': _("SV - Life Sciences"), 'CDM': _("CDM - Management of Technology"), 'CDH': _("CDH - College of Humanities"), 'ENT': _("ENT - Transdisciplinary Entities"), 'by_doctype': _("Publications by document type"), 'ARTICLE': _("Journal Articles"), 'CONF': _("Conference Papers"), 'THESIS': _("Theses"), 'REPORT': _("Reports"), 'submit_label': _("Deposit / Publish"), 'help_label': _("Help"), 'about': _('About Infoscience'), 'openaccess': _('Open Access & Copyright'), 'start': _('Start using Infoscience'), 'add': _('Add a document'), 'doctypes': _("Document types"), 'status': _("Publication status"), 'manage': _("Manage publications"), 'edit': _("Edit a publication"), 'remove': _("Remove a publication"), 'export': _('Export a publication list'), 'manage_a': _("Manage my account"), 'basket': _("Create a personal collection"), 'people': _('Display my publications in people@EPFL'), 'about_p': ln=='fr' and 'a-propos' or 'about', 'openaccess_p': ln=='fr' and 'libre-acces' or 'open-access', 'deposit_p': ln=='fr' and 'deposer' or 'deposit', 'start_p': ln=='fr' and 'deposer/demarrer' or 'deposit/start', 'add_p': ln=='fr' and 'deposer/nouveau' or 'deposit/new', 'doctypes_p': ln=='fr' and 'deposer/types-de-documents' or 'deposit/document-types', 'status_p': ln=='fr' and 'deposer/statut' or 'deposit/status', 'search_p': ln=='fr' and 'rechercher' or 'search', 'manage_p': ln=='fr' and 'gerer-les-publications' or 'manage-publications', 'edit_p': ln=='fr' and 'gerer-les-publications/editer' or 'manage-publications/edit', 'remove_p': ln=='fr' and 'gerer-les-publications/supprimer' or 'manage-publications/remove', 'export_p': ln=='fr' and 'gerer-les-publications/exporter' or 'manage-publications/export', 'manage_a_p': ln=='fr' and 'gerer-mon-compte' or 'manage-my-account', 'basket_p': ln=='fr' and 'gerer-mon-compte/collections' or 'manage-my-account/collections', 'people_p': ln=='fr' and 'gerer-les-publications/people' or 'manage-publications/people', } def tmpl_navtrailbox_body(self, ln, title, previous_links, separator, prolog, epilog): """Create navigation trail box body Parameters: - 'ln' *string* - The language to display - 'title' *string* - page title; - 'previous_links' *string* - the trail content from site title until current page (both ends exclusive) - 'prolog' *string* - HTML code to prefix the navtrail item with - 'epilog' *string* - HTML code to suffix the navtrail item with - 'separator' *string* - HTML code that separates two navtrail items Output: - text containing the navtrail """ _ = gettext_set_language(ln) previous_links = previous_links.strip() title = title.strip() if title == CFG_SITE_NAME: # Homepage return """ """ % create_html_link('http://www.epfl.ch', {}, 'EPFL', {'title': _("EPFL Homepage")}) if previous_links and not previous_links.startswith('
  • %s
  • %s
  • %s %s """ return out % (create_html_link('http://www.epfl.ch', {}, 'EPFL', {'title': _("EPFL Homepage")}), create_html_link('/', {'ln': ln}, 'Infoscience', {'title': _("Infoscience Homepage")}), previous_links, title) def detailed_record_container_top(self, recid, tabs, ln=CFG_SITE_LANG, show_similar_rec_p=True, creationdate=None, modificationdate=None, show_short_rec_p=True, citationnum=-1, referencenum=-1): """Prints the box displayed in detailed records pages, with tabs at the top. Returns content as it is if the number of tabs for this record is smaller than 2 => EPFL: no tabs!""" return '' def detailed_record_container_bottom(self, recid, tabs, ln=CFG_SITE_LANG, show_similar_rec_p=True, creationdate=None, modificationdate=None, show_short_rec_p=True): """Prints the box displayed in detailed records pages, with tabs at the top. Returns content as it is if the number of tabs for this record is smaller than 2 => EPFL: no tabs """ # If no tabs, returns nothing return '' def detailed_record_mini_panel(self, recid, ln=CFG_SITE_LANG, format='hd', files='', reviews='', actions=''): """Displays the actions dock at the bottom of the detailed record pages. => EFL: no minipane""" return '' -epfl_header_html_fr = "" -epfl_header_html_en = "" -epfl_header_sig = "" +def epfl_header(template_file): + with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + template_file), + 'r') as my_file: + return my_file.read() -def epfl_header(ln): - if ln == 'fr': - global epfl_header_html_fr - if not epfl_header_html_fr: - with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'header-no-local-search.fr.html'), - 'r') as my_file: - epfl_header_html_fr = my_file.read().replace('\n', '') - - return epfl_header_html_fr - else: - global epfl_header_html_en - - if not epfl_header_html_en: - with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'header-no-local-search.en.html'), - 'r') as my_file: - epfl_header_html_en = my_file.read().replace('\n', '') - - return epfl_header_html_en - -def epfl_header_version(): - global epfl_header_sig - - if not epfl_header_sig: - with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'header.sig.html'), 'r') as my_file: - epfl_header_sig = my_file.read().replace('\n', '') - - return epfl_header_sig +epfl_header_html_fr = epfl_header('header-no-local-search.fr.html') +epfl_header_html_en = epfl_header('header-no-local-search.en.html') +epfl_header_sig = epfl_header('header.sig.html')