# -*- coding: utf-8 -*-
## $Id: webstyle_templates_cern.py,v 1.23 2008/08/11 09:07:56 jerome Exp $
## CDS Invenio WebStyle templates.
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
##
## CDS 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.
##
## CDS 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 CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
WebStyle templates. Customize the look of pages of CDS Invenio
"""
__revision__ = \
"$Id: webstyle_templates_cern.py,v 1.23 2008/08/11 09:07:56 jerome Exp $"
import urllib
import cgi
from invenio.config import \
CFG_SITE_LANG, \
CFG_SITE_NAME, \
CFG_SITE_NAME_INTL, \
CFG_SITE_SUPPORT_EMAIL, \
CFG_SITE_SECURE_URL, \
CFG_SITE_URL, \
CFG_VERSION
from invenio.messages import gettext_set_language
from invenio.urlutils import make_canonical_urlargd, create_html_link
from invenio.dateutils import convert_datecvs_to_datestruct, \
convert_datestruct_to_dategui
from invenio.webuser import collect_user_info, isUserSubmitter, \
isUserReferee
from invenio.access_control_admin import acc_find_possible_activities
from invenio.webstyle_templates import Template as DefaultTemplate
CFG_DEVEL_SITE = 0
class Template(DefaultTemplate):
"""
Override default Altantis template to provide CERN specific style
"""
def tmpl_pageheader(self, req, ln=CFG_SITE_LANG, headertitle="",
description="", keywords="", userinfobox="",
navtrailbox="", pageheaderadd="", uid=0,
secure_page_p=0, navmenuid="admin", metaheaderadd="",
rssurl=CFG_SITE_URL+"/rss"):
"""Creates a page header
Parameters:
- 'CFG_SITE_URL' *string* - The base URL for the site
- 'ln' *string* - The language to display
- 'sitename' *string* - the first part of the page HTML title
- 'headertitle' *string* - the second part of the page HTML title
- 'CFG_SITE_SUPPORT_EMAIL' *string* - email of the support team
- '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
- 'metaheaderadd' *string* - list of further tags to add to the <HEAD></HEAD> part of the page
- 'userinfobox' *string* - the HTML code for the user information box
- 'userinfobox_structure' *list of tuples* - similar to 'userinfobox' but structured
- 'navtrailbox' *string* - the HTML code for the navigation trail box
- 'pageheaderadd' *string* - additional page header HTML code
- 'languagebox' *string* - the HTML code for the language box
- 'secure_page_p' *int* (0 or 1) - are we to use HTTPS friendly page elements or not?
- 'navmenuid' *string* - the id of the section of the website the displayed page belongs (search, submit, etc.)
- 'rssurl' *string* - the url of the RSS feed for this page
Output:
- HTML code of the page headers
"""
# load the right message language
_ = gettext_set_language(ln)
if headertitle == CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME):
headertitle = _("Home")
out = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="%(ln)s" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%(headertitle)s - %(sitename)s</title>
<link rev="made" href="mailto:%(CFG_SITE_SUPPORT_EMAIL)s" />
<!-- <link rel="stylesheet" href="https://zaguan.unizar.es/combine.php?type=css&files=buzcds.compressed.css,cds.compressed.css" type="text/css" />-->
<link rel="stylesheet" href="https://zaguan.unizar.es/img/newbuzcds.css" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="%(sitename)s RSS" href="%(rssurl)s" />
<link rel="shortcut icon" href="/img/favicon.ico"/>
<meta name="verify-v1" content="UMC2+4TXTky6whrJacawBYJh0MR7tRk1QB7zV5yFDP0=" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="%(description)s" />
<meta name="keywords" content="%(keywords)s" />
<script type="text/javascript" src="https://zaguan.unizar.es/combine.php?type=javascript&files=jquery.js,spoiler.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-6988718-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
%(metaheaderadd)s
</head>
<body><div id='wrapper-miguel' style='min-height:100%%; margin-bottom: -60px;'>""" % {
'CFG_SITE_URL' : CFG_SITE_URL,
'CFG_SITE_SECURE_URL' : CFG_SITE_SECURE_URL,
'cssurl' : secure_page_p and CFG_SITE_SECURE_URL or CFG_SITE_URL,
'rssurl': rssurl,
'ln' : ln,
'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
'headertitle' : headertitle,
'CFG_SITE_SUPPORT_EMAIL' : CFG_SITE_SUPPORT_EMAIL,
'description' : description,
'keywords' : keywords,
'metaheaderadd' : metaheaderadd,
}
# Build the main menu
main_menu = [('search', _("Search"), CFG_SITE_URL + '/?ln=' + ln, None),
('submit', _("Submit"), CFG_SITE_URL+'/submit?ln=' + ln, None),
#('account', _("Personalize"), CFG_SITE_URL+'/youraccount/display?ln='+ln, None),
('help', _("Help"), CFG_SITE_URL+'/help/?ln=' + ln, None)
]
user_activities_menu = get_user_activities_menu(req, ln)
main_menu.extend(user_activities_menu)
# Create HTML for the menu
out += get_navigation_menu_html(req, ln, navmenuid, main_menu, secure_page_p)
out +="""<div class="pageheader">
<table class="navtrailbox">
<tr>
<td class="navtrailboxbody">
%(navtrailbox)s
</td>
</tr>
</table>
<!-- end replaced page header -->
%(pageheaderadd)s
</div>
""" % {'navtrailbox' : navtrailbox,
'pageheaderadd' : pageheaderadd
}
return out
def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
pagefooteradd=""):
"""Creates a page footer
Parameters:
- 'CFG_SITE_URL' *string* - The base URL for the site
- 'ln' *string* - The language to display
- 'sitename' *string* - the first part of the page HTML title
- 'CFG_SITE_SUPPORT_EMAIL' *string* - email of the support team
- 'CFG_VERSION' *string* - the CFG_VERSION number of CDS Invenio
- 'lastupdated' *string* - when the page was last updated
- 'languagebox' *string* - the HTML code for the language box
- '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:
if lastupdated.startswith("$Date: "):
lastupdated = convert_datestruct_to_dategui(\
convert_datecvs_to_datestruct(lastupdated),
ln=ln)
msg_lastupdated = _("Last updated") + ": " + lastupdated
else:
msg_lastupdated = ""
out = '''
</div> <!-- /wrapper-miguel -->
<div class="cdl_pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
<div class="pagefooterstripeleft">
%(sitename)s :: <a class="footer" href="%(CFG_SITE_URL)s/?ln=%(ln)s">%(msg_search)s</a> :: <a class="footer" href="%(CFG_SITE_URL)s/submit?ln=%(ln)s">%(msg_submit)s</a> :: <a class="footer" href="%(CFG_SITE_SECURE_URL)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a> :: <a class="footer" href="%(CFG_SITE_URL)s/help/index.%(ln)s.html">%(msg_help)s</a>
<br />
%(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">CDS Invenio</a><!-- v%(CFG_VERSION)s -->
<!--<br/>
%(msg_maintainedby)s <a class="footer" href="mailto:%(CFG_SITE_SUPPORT_EMAIL)s">%(CFG_SITE_SUPPORT_EMAIL)s</a>-->
<br/>
%(msg_lastupdated)s
</div>
<div class="pagefooterstriperight">
%(languagebox)s
</div>
<div class="pagefooterstriperight">
<a href="http://www.facebook.com/Biblioteca.Universidad.de.Zaragoza">
<img src="https://zaguan.unizar.es/img/ico_facebook.png" alt="facebook biblioteca universidad de Zaragoza" style="height:22px" />
</a>
<a href="http://twitter.com/bibliouz">
<img src="https://zaguan.unizar.es/img/ico_twitter.png" alt="facebook biblioteca universidad de Zaragoza" style="height:22px" />
</a>
<a href="http://www.openarchives.org" title="Open Archives homesite">
<!-- <img class="iconoOAI" src="http://www.openarchives.org/images/OA100.gif"-->
<img class="iconoOAI" src="https://zaguan.unizar.es/img/OA100.gif"
alt="OAI icon."/>
</a>
<a href="http://www.w3.org/WAI/WCAG1AA-Conformance" title="Explicación del Nivel Doble-A de Conformidad">
<!-- <img class="iconow3c" src="http://www.w3.org/WAI/wcag1AA.gif"-->
<img class="iconow3c" src="https://zaguan.unizar.es/img/wcag1AA.gif"
alt="Icono de conformidad con el Nivel Doble-A, de las Directrices de Accesibilidad
para el Contenido Web 1.0 del W3C-WAI. Abre nueva ventana."/>
</a>
<a href="http://validator.w3.org/check?uri=referer">
<!-- <img src="http://www.w3.org/Icons/valid-xhtml10.gif"-->
<img src="https://zaguan.unizar.es/img/valid-xhtml10.gif"
alt="Valid XHTML 1.0 Transitional" class="iconow3c" />
</a>
</div>
<!-- replaced page footer -->
</div>
</body>
</html>
''' % {
'CFG_SITE_URL' : CFG_SITE_URL,
'CFG_SITE_SECURE_URL' : CFG_SITE_SECURE_URL,
'ln' : ln,
'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
'CFG_SITE_SUPPORT_EMAIL' : 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),
'CFG_VERSION' : CFG_VERSION,
'pagefooteradd' : pagefooteradd,
}
return out
# Utility functions
##
def get_user_activities_menu(req, ln):
"""Returns the main navigation menu with actions based on user's
priviledges
- 'ln' *string* - The selected language
- 'req' *object* - the request object
"""
# load the right message language
_ = gettext_set_language(ln)
menus = []
if req is not None:
user_info = collect_user_info(req)
else:
user_info = {}
user_info['guest'] = 1
user_info['nickname'] = ''
user_info['email'] = ''
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
lang_link = '?ln=' + ln
#user_icon = """<img src="%s/img/user.gif" border="0" alt="" />""" % CFG_SITE_URL
if user_info['guest'] == '1' :#.get('guest', True):
your_cds_submenu = [('yourbaskets', _("Your Baskets"), CFG_SITE_SECURE_URL+'/yourbaskets/display%s' % lang_link, None),
('youralerts', _("Your Alerts"), CFG_SITE_SECURE_URL+'/youralerts/list%s' % lang_link, None),
#('youraccount', user_icon+ ' '+_("guest"), CFG_SITE_SECURE_URL+'/youraccount/display?ln='+ln, None),
#('login', _("login"), CFG_SITE_SECURE_URL+'/youraccount/login?ln='+ln, None)
('yoursearches', _("Your Searches"), CFG_SITE_SECURE_URL+'/youralerts/display%s' % lang_link, None)
]
menus = [('yourcds', _("Your options"), CFG_SITE_SECURE_URL+'/youraccount/display%s' % lang_link, None, your_cds_submenu),
#('yourbaskets', _("baskets"), CFG_SITE_SECURE_URL+'/yourbaskets/display?ln='+ln, None),
#('youralerts', _("alerts"), CFG_SITE_SECURE_URL+'/youralerts/list?ln='+ln, None),
#('youraccount', user_icon+ ' '+_("guest"), CFG_SITE_SECURE_URL+'/youraccount/display?ln='+ln, None),
('login', _("login"), CFG_SITE_SECURE_URL+'/youraccount/login%(sep)s%(ln)s%(referer)s' % \
{'sep': (ln or url_referer) and '?' or '',
'ln': 'ln=' + ln,
'referer' : url_referer and \
('&referer=%s' % urllib.quote(url_referer))}, None)
]
else:
username_or_email = user_info['nickname']
if username_or_email is None or username_or_email == '':
username_or_email = user_info['email']
your_cds_submenu = [('yourbaskets', _("Your Baskets"), CFG_SITE_SECURE_URL+'/yourbaskets/display%s' % lang_link, None),
('youralerts', _("Your Alerts"), CFG_SITE_SECURE_URL+'/youralerts/list%s' % lang_link, None),
('yourmessages', _("Your Messages"), CFG_SITE_SECURE_URL+'/yourmessages/display%s' % lang_link, None),
('yourgroups', _("Your Groups"), CFG_SITE_SECURE_URL+'/yourgroups/display%s' % lang_link, None),
('yoursearches', _("Your Searches"), CFG_SITE_SECURE_URL+'/youralerts/display%s' % lang_link, None)
]
if req is not None and isUserSubmitter(user_info):
your_cds_submenu.append(('yoursubmissions', _("Your Submissions"), CFG_SITE_SECURE_URL+'/yoursubmissions.py%s' % lang_link, None))
if req is not None and isUserReferee(user_info):
your_cds_submenu.append(('yourapprovals', _("Your Approvals"), CFG_SITE_SECURE_URL+'/yourapprovals.py%s' % lang_link, None))
your_cds_submenu.append(('youraccount', _("Your Account"), CFG_SITE_SECURE_URL+'/youraccount/display%s' % lang_link, None))
menus = [('yourcds', _("Your options"), CFG_SITE_SECURE_URL+'/youraccount/display%s' % lang_link, None, your_cds_submenu)
#('yourbaskets', _("baskets"), CFG_SITE_SECURE_URL+'/yourbaskets/display?ln='+ln, None),
#('youralerts', _("alerts"), CFG_SITE_SECURE_URL+'/youralerts/list?ln='+ln, None),
#('yourmessages', _("messages"), CFG_SITE_SECURE_URL+'/yourmessages/display?ln='+ln, None),
#('yourgroups', _("groups"), CFG_SITE_SECURE_URL+'/yourgroups/display?ln='+ln, None)
]
if req is not None:
activities = acc_find_possible_activities(user_info, ln)
if len(activities) > 0:
admin_submenu = [(name, name, url, None) for (name, url) in activities.iteritems()]
menus.append(('admin', _("Administracion "),
CFG_SITE_SECURE_URL+'/youraccount/youradminactivities%s' % lang_link, None, admin_submenu))
menus.append(('logout', _("logout"), CFG_SITE_SECURE_URL+'/youraccount/logout%s' % lang_link, None))
menus.append(('youraccount', username_or_email , CFG_SITE_SECURE_URL+'/youraccount/display%s' % lang_link, None))
return menus
def get_navigation_menu_html(req, ln=CFG_SITE_LANG,
selected_main_menu_id='',
main_menu_structure=None,
secure_page_p=0):
"""
Returns the complete navigation menu as HTML.
Parameters:
ln - The language in which the menu is to be returned.
selected_external_links_menu_id - The id (as string) of the selected
tab in the navigation menu.
selected_main_menu_id - The id (as string) of the selected
tab in the main navigation menu.
main_menu_structure - The list of items to display in the main
navigation menu.
"""
external_links_menu = [
('unizar', 'UniZar', 'http://www.unizar.es/',
'Universidad de Zaragoza',
{'en': ('UniZar', 'http://www.unizar.es/', 'University of Zaragoza'),
'es': ('UniZar', 'http://www.unizar.es/', None)
}),
('library', 'Library', 'http://biblioteca.unizar.es/',
'Library of Unizar',
{'en': ('Library', 'http://biblioteca.unizar.es/', None),
'es': ('Biblioteca', 'http://biblioteca.unizar.es/', "Biblioteca de Unizar")
}),
('catalogo', 'Catálogo', 'http://roble.unizar.es/',
'Catalogo de la BUZ',
{'en': ('Cataloge', 'http://roble.unizar.es/search', 'Cataloge of Library'),
'es': ('Catálogo', 'http://roble.unizar.es/', None)
})
]
# Skip to content links
out = '''
<ul class="hidden" title="Keyboard tabbing & Accessibility helper links">
<li><a name="main" id="main" href="#mainContent" accesskey="1">Skip to main content</a></li>
</ul>'''
# Specify if we are on DEV site
if CFG_DEVEL_SITE:
out += '<div style="font-size:small;color:#f00;">You are on the development site. If you are here by mistake, please go to <a href="http://cdsweb.cern.ch/?ln=%s">the production website</a>.</div>' % ln
# Primary navigation menu
out += """
<!--<div id="cdlnav3"/></div>-->
<div id="cdlhead"%(head_class)s>
<map name="Navigation_Bar" id="cdlnav">
<h1 id="cdlheadtitle">
<a href="%(CFG_SITE_URL)s"><!--<img src="/img/logo_buz.png" alt="Logo BUZ" class="iconobuz"/>-->
<img src="/img/banner_nuevo_white.jpg" alt="Logo Zaguan Universidad de Zaragoza" />
<!--(U)Zaguán -->
</a></h1>
<div id="cdlnav1" class="cdsweb">
<h2>Related links</h2>
<ul>\n""" % {'CFG_SITE_SECURE_URL': secure_page_p and CFG_SITE_SECURE_URL or CFG_SITE_URL,
'CFG_SITE_URL':CFG_SITE_URL,
'CFG_SITE_NAME':CFG_SITE_NAME,
'head_class': CFG_DEVEL_SITE and ' class="dev"' or ''}
for menu_item in external_links_menu:
if menu_item[4] is not None and \
menu_item[4].has_key(ln):
label = menu_item[4][ln][0]
if label is None:
label = menu_item[1]
link = menu_item[4][ln][1]
if link is None:
link = menu_item[2]
title = menu_item[4][ln][2]
if title is None:
title = menu_item[3]
else:
label = menu_item[1]
link = menu_item[2]
title = menu_item[3]
li_css_class = [menu_item[0]+'tab']
li_css_class_string = ''
if menu_item[0] == 'cdsweb':
li_css_class.append('on')
#li_css_class.append(selected_external_links_menu_id)
#if menu_item[0] == 'home':
# li_css_class.append('hometab')
if menu_item == external_links_menu[-1]:
# Last element of the list
li_css_class.append('last')
if li_css_class:
li_css_class_string = ' class="%s"' % ' '.join(li_css_class)
out += """ <li%s>
<a href="%s" hreflang="%s" title="%s">%s</a>
</li>\n""" % (li_css_class_string, link, ln, title, label)
argd = {}
if req and req.args:
argd.update(cgi.parse_qs(req.args))
argd['ln'] = 'es'
if req and req.uri:
args = urllib.quote(req.uri, '/:?') + make_canonical_urlargd(argd, {})
else:
args = ""
url_esp = create_html_link(args, {},
"""<img style="border: medium none ;" src="/img/spain-flag.gif" alt="Spanish" height="15" width="22" />""",
{'class': "langinfo"})
argd['ln'] = 'en'
if req and req.uri:
args = urllib.quote(req.uri, '/:?') + make_canonical_urlargd(argd, {})
else:
args = ""
url_eng = create_html_link(args, {},
"""<img style="border: medium none ;" src="/img/england-flag.gif" alt="English" height="15" width="22" />""",
{'class': "langinfo"})
out += """ <li%s>
%s
%s
</li>\n""" % (li_css_class_string, url_esp, url_eng)
out += """ </ul><div class="clear"></div>
</div>
<div id="cdlnav2" class="cdsweb"> <!-- fix -->
<h2><a name="localNavLinks">Main navigation links:</a></h2>
<ul>\n"""
# Secondary navigation menu
for sub_menu_item in main_menu_structure:
if sub_menu_item[0] in []:#['login', 'logout', 'youraccount']:
continue
if sub_menu_item[3] is not None and \
sub_menu_item[3].has_key(ln):
link = sub_menu_item[3][ln][1]
if link is None:
link = sub_menu_item[2]
label = sub_menu_item[3][ln][0]
if label is None:
label = sub_menu_item[1]
else:
link = sub_menu_item[2]
label = sub_menu_item[1]
li_css_class = []
li_css_class_string = ''
# Sub-submenu
sub_sub_menu = ''
if len(sub_menu_item) == 5:
li_css_class.append('hassubmenu')
sub_sub_menu = '<ul class="subsubmenu" style="width:%sem;">%s</ul>'
# Get lenght of longest string, tansform it a bit and
# pass it as inline css for the submenu item width
sub_sub_menu_width = int(max([len(sub_sub_menu_item[1].decode('utf-8')) \
for sub_sub_menu_item in sub_menu_item[4]]))
sub_sub_menu_width = 12 + ((sub_sub_menu_width - 15)* 0.5)
sub_menu_item[4].sort(lambda x, y: cmp(x[1].lower(), y[1].lower())) # sort items
sub_sub_menu = sub_sub_menu % (sub_sub_menu_width, \
''.join(['<li><a href="%s">%s</a></li>' % (sub_sub_menu_item[2], sub_sub_menu_item[1])\
for sub_sub_menu_item in sub_menu_item[4]]))
if sub_menu_item[0] == selected_main_menu_id or \
(sub_menu_item[0] == 'yourcds' and \
selected_main_menu_id.startswith('your') and \
selected_main_menu_id != 'youraccount'):
li_css_class.append('on')
if sub_menu_item[0] == 'login' or \
sub_menu_item[0] == 'logout' or \
sub_menu_item[0] == 'youraccount':
li_css_class.append('right')
if sub_menu_item[0] in ['youraccount', 'login']:
li_css_class.append('user')
if li_css_class:
li_css_class_string = ' class="%s"' % ' '.join(li_css_class)
out +=""" <li%s>
<a href="%s" hreflang="%s">%s</a> %s
</li>
""" % (li_css_class_string, link, ln, label, sub_sub_menu)
out += """</ul><div class="clear"></div>
</div>
</map>
</div>
<a name="mainContent"></a>
"""
return out |