forked from SCOAP3/scoap3-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webstyle_templates_scoap3.py
436 lines (376 loc) · 17.6 KB
/
webstyle_templates_scoap3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
## This file is part of SCOAP3.
## Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 CERN.
##
## SCOAP3 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.
##
## SCOAP3 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 SCOAP3; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
WebStyle templates for SCOAP3
"""
import cgi
from invenio.config import (CFG_SITE_LANG,
CFG_SITE_NAME,
CFG_BASE_URL,
CFG_INSPIRE_SITE,
CFG_SITE_RECORD,
CFG_SITE_NAME_INTL,
CFG_SITE_SECURE_URL,
CFG_SITE_SUPPORT_EMAIL,
CFG_SITE_URL,
CFG_WEBLINKBACK_TRACKBACK_ENABLED,
CFG_WEBSTYLE_INSPECT_TEMPLATES,
CFG_WEBSTYLE_TEMPLATE_SKIN,
CFG_VERSION)
from invenio.messages import gettext_set_language, is_language_rtl
from invenio.dateutils import convert_datecvs_to_datestruct, convert_datestruct_to_dategui
from invenio.webstyle_templates import Template as DefaultTemplate
class Template(DefaultTemplate):
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=CFG_BASE_URL+"/rss", body_css_classes=None):
"""Creates a page header
Parameters:
- 'ln' *string* - The language to display
- 'headertitle' *string* - the title of the HTML page, not yet escaped for HTML
- 'description' *string* - description goes to the metadata in the header of the HTML page,
not yet escaped for HTML
- 'keywords' *string* - keywords goes to the metadata in the header of the HTML page,
not yet escaped for HTML
- '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
- 'uid' *int* - user ID
- '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 <HEAD></HEAD> part of the page
- 'rssurl' *string* - the url of the RSS feed for this page
- 'body_css_classes' *list* - list of classes to add to the body tag
Output:
- HTML code of the page headers
"""
# Including HEPData headers ( Ugly hack but no obvious way to avoid this ...)
if CFG_INSPIRE_SITE:
hepDataAdditions = """<script type="text/javascript" src="%s/js/hepdata.js"></script>""" \
% (CFG_BASE_URL, )
hepDataAdditions += """<link rel="stylesheet" href="%s/img/hepdata.css" type="text/css" />""" \
% (CFG_BASE_URL, )
else:
hepDataAdditions = ""
# load the right message language
_ = gettext_set_language(ln)
if body_css_classes is None:
body_css_classes = []
body_css_classes.append(navmenuid)
uri = req.unparsed_uri
headerLinkbackTrackbackLink = ''
if CFG_WEBLINKBACK_TRACKBACK_ENABLED:
from invenio.weblinkback_templates import get_trackback_auto_discovery_tag
# Embed a link in the header to subscribe trackbacks
# TODO: This hack must be replaced with the introduction of the new web framework
recordIndexInURI = uri.find('/' + CFG_SITE_RECORD + '/')
# substring found --> offer trackback link in header
if recordIndexInURI != -1:
recid = uri[recordIndexInURI:len(uri)].split('/')[2].split("?")[0] #recid might end with ? for journal records
headerLinkbackTrackbackLink = get_trackback_auto_discovery_tag(recid)
if CFG_WEBSTYLE_INSPECT_TEMPLATES:
inspect_templates_message = '''
<table width="100%%" cellspacing="0" cellpadding="2" border="0">
<tr bgcolor="#aa0000">
<td width="100%%">
<font color="#ffffff">
<strong>
<small>
CFG_WEBSTYLE_INSPECT_TEMPLATES debugging mode is enabled. Please
hover your mouse pointer over any region on the page to see which
template function generated it.
</small>
</strong>
</font>
</td>
</tr>
</table>
'''
else:
inspect_templates_message = ""
sitename = CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME)
if headertitle == sitename:
pageheadertitle = headertitle
else:
pageheadertitle = headertitle + ' - ' + sitename
metabase = ""
stripped_url = CFG_SITE_URL.replace("://", "")
if not CFG_BASE_URL and '/' in stripped_url:
metabase = "<base href='%s'>" % (CFG_SITE_URL,)
out = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="%(ln_iso_639_a)s" xml:lang="%(ln_iso_639_a)s" xmlns:og="http://opengraphprotocol.org/schema/" >
<head>
<title>%(pageheadertitle)s</title>
%(metabase)s
<link rev="made" href="mailto:%(sitesupportemail)s" />
<link rel="stylesheet" href="%(cssurl)s/img/invenio%(cssskin)s.css" type="text/css" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="%(cssurl)s/img/invenio%(cssskin)s-ie7.css" />
<![endif]-->
<!--[if gt IE 8]>
<style type="text/css">div.restrictedflag {filter:none;}</style>
<![endif]-->
%(canonical_and_alternate_urls)s
<!-- <link rel="alternate" type="application/rss+xml" title="%(sitename)s RSS" href="%(rssurl)s" /> -->
<link rel="search" type="application/opensearchdescription+xml" href="%(siteurl)s/opensearchdescription" title="%(sitename)s" />
<link rel="unapi-server" type="application/xml" title="unAPI" href="%(unAPIurl)s" />
<link rel="icon" href="/img/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="/img/favicon.ico" type="image/x-icon">
%(linkbackTrackbackLink)s
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="%(ln)s" />
<meta name="description" content="%(description)s" />
<meta name="keywords" content="%(keywords)s" />
<meta name="google-site-verification" content="mLqufkdPNxUHXFW4obCfN5NJXr4sD_SlnvsOla7RZAE" />
<meta name="msvalidate.01" content="EA9805F0F62E4FF22B98853713964B28" />
<script type="text/javascript" src="%(cssurl)s/js/jquery.min.js"></script>
%(hepDataAdditions)s
%(metaheaderadd)s
</head>
<body%(body_css_classes)s lang="%(ln_iso_639_a)s"%(rtl_direction)s>
<div class="pageheader">
%(inspect_templates_message)s
<!-- replaced page header -->
<div class="headerlogo">
<table class="headerbox" cellspacing="0">
<tr>
<td align="right" valign="top" colspan="12">
<div class="headerboxbodylogo">
<a href="%(cssurl)s/?ln=%(ln)s">SCOAP<sup>3</sup> Repository (βeta)</a>
</div>
</td>
</tr>
<tr style="background-color: #679A70;">
<td style="padding: 10px; font-size: medium; color: #FFF;"><a href="/" style="text-decoration: none; color: #FFF;">HOME</a> :: <a href="http://scoap3.org/" style="text-decoration: none; color: #FFF;">SCOAP<sup>3</sup></a> :: <a href="http://scoap3.org/scoap3-repository-help" style="text-decoration: none; color: #FFF;">HELP</a> :: <a href="http://scoap3.org/scoap3-repository" style="text-decoration: none; color: #FFF;">ABOUT</a></td>
</tr>
<!--
<tr class="menu">
<td class="headermoduleboxbodyblank">
</td>
<td class="headermoduleboxbodyblank">
</td>
<td class="headermoduleboxbody%(search_selected)s">
<a class="header%(search_selected)s" href="%(cssurl)s/?ln=%(ln)s">%(msg_search)s</a>
</td>
<td class="headermoduleboxbodyblank">
</td>
<td class="headermoduleboxbody%(submit_selected)s">
<a class="header%(submit_selected)s" href="%(cssurl)s/submit?ln=%(ln)s">%(msg_submit)s</a>
</td>
<td class="headermoduleboxbodyblank">
</td>
<td class="headermoduleboxbody%(personalize_selected)s">
%(useractivities)s
</td>
<td class="headermoduleboxbodyblank">
</td>
<td class="headermoduleboxbody%(help_selected)s">
<a class="header%(help_selected)s" href="%(cssurl)s/help/%(langlink)s">%(msg_help)s</a>
</td>
%(adminactivities)s
<td class="headermoduleboxbodyblanklast">
</td>
</tr>-->
</table>
</div>
<table class="navtrailbox">
<tr>
<td class="navtrailboxbody">
%(navtrailbox)s
</td>
</tr>
</table>
<!-- end replaced page header -->
%(pageheaderadd)s
</div>
""" % {
'metabase': metabase,
'rtl_direction': is_language_rtl(ln) and ' dir="rtl"' or '',
'siteurl': CFG_SITE_URL,
'sitesecureurl' : CFG_SITE_SECURE_URL,
'canonical_and_alternate_urls' : self.tmpl_canonical_and_alternate_urls(uri),
'cssurl' : CFG_BASE_URL,
'cssskin' : CFG_WEBSTYLE_TEMPLATE_SKIN != 'default' and '_' + CFG_WEBSTYLE_TEMPLATE_SKIN or '',
'rssurl': rssurl,
'ln' : ln,
'ln_iso_639_a' : ln.split('_', 1)[0],
'langlink': '?ln=' + ln,
'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
'pageheadertitle': cgi.escape(pageheadertitle),
'sitesupportemail' : CFG_SITE_SUPPORT_EMAIL,
'description' : cgi.escape(description, True),
'keywords' : cgi.escape(keywords, True),
'metaheaderadd' : metaheaderadd,
'userinfobox' : userinfobox,
'navtrailbox' : navtrailbox,
'useractivities': useractivities_menu,
'adminactivities': adminactivities_menu and ('<td class="headermoduleboxbodyblank"> </td><td class="headermoduleboxbody%(personalize_selected)s">%(adminactivities)s</td>' % \
{'personalize_selected': navmenuid.startswith('admin') and "selected" or "",
'adminactivities': adminactivities_menu}) or '<td class="headermoduleboxbodyblank"> </td>',
'pageheaderadd' : pageheaderadd,
'body_css_classes' : body_css_classes and ' class="%s"' % ' '.join(body_css_classes) or '',
'search_selected': navmenuid == 'search' and "selected" or "",
'submit_selected': navmenuid == 'submit' and "selected" or "",
'personalize_selected': navmenuid.startswith('your') and "selected" or "",
'help_selected': navmenuid == 'help' and "selected" or "",
'msg_search' : _("Search"),
'msg_submit' : _("Submit"),
'msg_personalize' : _("Personalize"),
'msg_help' : _("Help"),
'unAPIurl' : cgi.escape('%s/unapi' % CFG_SITE_URL),
'linkbackTrackbackLink': headerLinkbackTrackbackLink,
'hepDataAdditions': hepDataAdditions,
'inspect_templates_message' : inspect_templates_message
}
return out
def tmpl_pagefooter(self, req=None, ln=CFG_SITE_LANG, lastupdated=None,
pagefooteradd=""):
"""Creates a page footer
Parameters:
- 'ln' *string* - The language to display
- 'lastupdated' *string* - when the page was last updated
- 'pagefooteradd' *string* - additional page footer HTML code
Output:
- HTML code of the page headers
"""
# load the right message language
_ = gettext_set_language(ln)
if lastupdated and lastupdated != '$Date$':
if lastupdated.startswith("$Date: ") or \
lastupdated.startswith("$Id: "):
lastupdated = convert_datestruct_to_dategui(\
convert_datecvs_to_datestruct(lastupdated),
ln=ln)
msg_lastupdated = _("Last updated") + ": " + lastupdated
else:
msg_lastupdated = ""
out = """
<div class="pagefooter">
%(pagefooteradd)s
<!-- replaced page footer -->
<div class="pagefooterstripeleft">
<!--
%(sitename)s :: <a class="footer" href="%(siteurl)s/?ln=%(ln)s">%(msg_search)s</a> :: <a class="footer" href="%(siteurl)s/submit?ln=%(ln)s">%(msg_submit)s</a> :: <a class="footer" href="%(sitesecureurl)s/youraccount/display?ln=%(ln)s">%(msg_personalize)s</a> :: <a class="footer" href="%(siteurl)s/help/%(langlink)s">%(msg_help)s</a>
<br />-->
%(msg_poweredby)s <a class="footer" href="http://invenio-software.org/">Invenio</a> v%(version)s
<br />
%(msg_maintainedby)s <a class="footer" href="mailto:%(sitesupportemail)s">%(sitesupportemail)s</a>
<br />
%(msg_lastupdated)s
</div>
<div class="pagefooterstriperight">
<p><em>
Articles in the SCOAP3 repository are released under a <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by/3.0/"><strong>CC-BY</strong></a> license. Metadata are provided by the corresponding publishers and released under the <a target="_blank" rel="license"
href="http://creativecommons.org/publicdomain/zero/1.0/">
<strong>CC0</strong>
</a> waiver.
</em></p>
%(languagebox)s
</div>
<!-- replaced page footer -->
</div>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://cds-piwik.cern.ch/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "10"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript>
<!-- Piwik Image Tracker -->
<img src="https://cds-piwik.cern.ch/piwik.php?idsite=10&rec=1" style="border:0" alt="" />
<!-- End Piwik -->
</noscript>
<!-- End Piwik Code -->
</body>
</html>
""" % {
'siteurl': CFG_BASE_URL,
'sitesecureurl': CFG_SITE_SECURE_URL,
'ln': ln,
'langlink': '?ln=' + ln,
'sitename': CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME),
'sitesupportemail': CFG_SITE_SUPPORT_EMAIL,
'msg_search': _("Search"),
'msg_submit': _("Submit"),
'msg_personalize': _("Personalize"),
'msg_help': _("Help"),
'msg_poweredby': _("Powered by"),
'msg_maintainedby': _("Maintained by"),
'msg_lastupdated': msg_lastupdated,
'languagebox': self.tmpl_language_selection_box(req, ln),
'version': CFG_VERSION,
'pagefooteradd': pagefooteradd,
}
return out
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
Parameters:
- recid *int* - the id of the displayed record
- tabs ** - the tabs displayed at the top of the box.
- ln *string* - the language of the page in which the box is displayed
- show_similar_rec_p *bool* print 'similar records' link in the box
- creationdate *string* - the creation date of the displayed record
- modificationdate *string* - the last modification date of the displayed record
- show_short_rec_p *boolean* - prints a very short version of the record as reminder.
"""
# If no tabs, returns nothing
if len(tabs) <= 1:
return ''
# load the right message language
_ = gettext_set_language(ln)
similar = ""
out = """
<div class="bottom-left-folded">%(dates)s</div>
<div class="bottom-right-folded" style="text-align:right;padding-bottom:2px;">
<span class="moreinfo" style="margin-right:10px;">%(similar)s</span></div>
</div>
</div>
</div>
<br/>
""" % {'similar' : similar,
'dates' : creationdate and '<div class="recordlastmodifiedbox" style="position:relative;margin-left:1px"> %(dates)s</div>' % {
'dates': _("Record created %(x_date_creation)s, last modified %(x_date_modification)s") % \
{'x_date_creation': creationdate,
'x_date_modification': modificationdate},
} or ''
}
return out