Page MenuHomec4science

webpage.py.wml
No OneTemporary

File Metadata

Created
Fri, May 24, 15:17

webpage.py.wml

## $Id$
## CDSware Web Page Template.
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## read config variables:
#include "config.wml"
#include "configbis.wml"
from config import *
from messages import *
from webuser import create_user_infobox
import re
import string
import sys
import time
import traceback
import urllib
## start Python:
<protect>## $Id$</protect>
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
"""CDSware Web Page Template"""
page_template_header = """
<!-- DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware SOURCES. LOOK THERE FOR THE COPYRIGHT INFO. -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><!--CDSNAMEINTL-->: %s</title>
<link rev="made" href="mailto:<SUPPORTEMAIL>">
<link rel="stylesheet" href="<WEBURL>/img/cds.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="%s">
<meta name="keywords" content="%s">
</head>
<body>
<div class="pageheader">
%s
%s
</div>
"""
page_template_footer = """
<div class="pagefooter">
%s
%s
</div>
</body>
</html>
"""
page_template_body = """
<div class="pagebody">
<table border="0" cellspacing="0" cellpadding="0" width="100%%">
<tr valign="top">
<td class="pagestripemiddle" align="left">
%s
<h1 class="headline">%s</h1>
%s
</td>
<td class="pagestriperight" width="<CDSPAGESTRIPEWIDTH>" align="right" valign="top">
<CDSPAGEBOXRIGHTTOP>
%s
</td>
</tr>
</table>
</div>
"""
def create_navtrail(title,
previous_links,
prolog="",
separator=""" &gt; """,
epilog="",
language=cdslang):
"""create_navtrail(): create navigation trail table box
input: title = page title;
previous_links = the trail content from site title until current page (both ends exlusive).
output: text containing the navtrail
"""
out = ""
if title != cdsnameintl[language]:
out += """<a class="navtrail" href="%s?ln=%s">%s</a>""" % (weburl, language, msg_home[language])
if previous_links:
if out:
out += separator
out += previous_links
if title:
if out:
out += separator
if title == cdsnameintl[language]: # hide site name, print Home instead
out += msg_home[language]
else:
out += title
return prolog + out + epilog
def page(title, body, navtrail="", description="", keywords="", uid=0, cdspagerightstripeadd="", cdspageheaderadd="", cdspagebodyadd="", cdspagefooteradd="", lastupdated="", language=cdslang, urlargs=""):
"""page(): display the cds page
input: title of the page;
body of the page in html format;
description goes to the metadata in the header of the HTML page
keywords goes to the metadata in the header of the html page
cdspageheaderadd is a message to be displayed just under the page header
cdspagefooteradd is a message to be displayed on the top of the page footer
lastupdated is a text containing the info on last update (optional)
language is the language version of the page
urlargs are the URL arguments of the page to display (useful to affect languages)
output: the final cds page with header, footer, etc.
"""
if title == cdsnameintl[language]:
headerstitle = msg_home[language]
else:
headerstitle = title
out = page_template_header % (headerstitle, description, keywords, cdspageheader, cdspageheaderadd)
out += page_template_body % (cdspagebodyadd, title, body, cdspagerightstripeadd)
out += page_template_footer % (cdspagefooteradd, cdspagefooter)
out = re.sub(r"<!--CDSNAMEINTL-->", cdsnameintl[language], out)
out = re.sub(r"<!--MSGSEARCH-->", msg_search[language], out)
out = re.sub(r"<!--MSGSUBMIT-->", msg_submit[language], out)
out = re.sub(r"<!--MSGHELP-->", msg_help[language], out)
out = re.sub(r"<!--MSGPERSONALIZE-->", msg_personalize[language], out)
out = re.sub(r"<!--LN-->", language, out)
out = re.sub(r"<!--NAVTRAILBOX-->", create_navtrail(title, navtrail, language=language), out)
out = re.sub(r"<!--USERINFOBOX-->", create_user_infobox(uid, language), out)
out = re.sub(r"<!--LANGUAGESELECTIONBOX-->", create_language_selection_box(urlargs, language), out)
out = re.sub(r"<!--POWEREDBY-->", msg_powered_by[language], out)
out = re.sub(r"<!--MAINTAINEDBY-->", msg_maintained_by[language], out)
if lastupdated:
out = re.sub(r"<!--LASTUPDATED-->", msg_last_updated[language] + " " + lastupdated, out)
return out
def pageheaderonly(title, navtrail="", description="", keywords="", uid=0, cdspageheaderadd="", language=cdslang, urlargs=""):
"""Return just the beginning of page(), with full headers.
Suitable for the search results page and any long-taking scripts."""
out = page_template_header % (title, description, keywords, cdspageheader, cdspageheaderadd)
out = re.sub(r"<!--CDSNAMEINTL-->", cdsnameintl[language], out)
out = re.sub(r"<!--MSGSEARCH-->", msg_search[language], out)
out = re.sub(r"<!--MSGSUBMIT-->", msg_submit[language], out)
out = re.sub(r"<!--MSGHELP-->", msg_help[language], out)
out = re.sub(r"<!--LN-->", language, out)
out = re.sub(r"<!--NAVTRAILBOX-->", create_navtrail(title, navtrail, language=language), out)
out = re.sub(r"<!--USERINFOBOX-->", create_user_infobox(uid, language), out)
out = re.sub(r"<!--LANGUAGESELECTIONBOX-->", create_language_selection_box(urlargs, language), out)
return out
def pagefooteronly(cdspagefooteradd="", lastupdated="", language=cdslang):
"""Return just the ending of page(), with full footer.
Suitable for the search results page and any long-taking scripts."""
out = page_template_footer % (cdspagefooteradd, cdspagefooter)
out = re.sub(r"<!--CDSNAMEINTL-->", cdsnameintl[language], out)
out = re.sub(r"<!--MSGSEARCH-->", msg_search[language], out)
out = re.sub(r"<!--MSGSUBMIT-->", msg_submit[language], out)
out = re.sub(r"<!--MSGHELP-->", msg_help[language], out)
out = re.sub(r"<!--MSGPERSONALIZE-->", msg_personalize[language], out)
out = re.sub(r"<!--LN-->", language, out)
out = re.sub(r"<!--POWEREDBY-->", msg_powered_by[language], out)
out = re.sub(r"<!--MAINTAINEDBY-->", msg_maintained_by[language], out)
if lastupdated:
out = re.sub(r"<!--LASTUPDATED-->", msg_last_updated[language] + " " + lastupdated, out)
return out
def create_error_box(req, title="<strong>Internal Error:</strong>", verbose=1):
"""Analyse the req object and the sys traceback and return a text
message box with internal information that would be suitful to
display when something bad has happened.
If TRACEBACK_P is set to 0, then don't print traceback, only the error."""
boxhead = """<p>%s %s %s""" % (title, sys.exc_info()[0], sys.exc_info()[1])
boxbody = """<p>Please contact <a href="mailto:%s">%s</a>
quoting the following information:<blockquote><pre>""" % (urllib.quote(supportemail), supportemail)
boxbody += """URI: http://%s%s\n""" % (req.hostname, req.unparsed_uri)
boxbody += """Time: %s\n""" % time.strftime("%02d/%b/%Y:%H:%M:%S %z")
if req.headers_in.has_key('User-Agent'):
boxbody += """Browser: %s\n""" % req.headers_in['User-Agent']
boxbody += """Client: %s\n""" % req.connection.remote_ip
if verbose >= 1:
boxbody += """Error: %s %s\n""" % (sys.exc_info()[0], sys.exc_info()[1])
if verbose >= 9:
boxbody += "Traceback: \n%s" % string.join(traceback.format_tb(sys.exc_info()[2]),"\n")
boxbody += """</pre></blockquote>"""
out = """
<table class="errorbox">
<thead>
<tr>
<th class="errorboxheader">
%s
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="errorboxbody">%s</td>
</tr>
</tbody>
</table>""" % (boxhead, boxbody)
return out

Event Timeline