diff --git a/modules/webstyle/lib/.cvsignore b/modules/webstyle/lib/.cvsignore index 9928cf5cf..df3ddb84d 100644 --- a/modules/webstyle/lib/.cvsignore +++ b/modules/webstyle/lib/.cvsignore @@ -1,7 +1,6 @@ Makefile Makefile.in z_* *.O *.shtml -*.py *~ \ No newline at end of file diff --git a/modules/webstyle/lib/Makefile.am b/modules/webstyle/lib/Makefile.am index 052948f93..6f81fa827 100644 --- a/modules/webstyle/lib/Makefile.am +++ b/modules/webstyle/lib/Makefile.am @@ -1,29 +1,25 @@ ## $Id$ ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002, 2003, 2004, 2005 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. pylibdir=$(libdir)/python/cdsware -pylib_DATA=webpage.py +pylib_DATA=webpage.py template.py webstyle_templates.py -FILESWML = $(wildcard $(srcdir)/*.wml) -EXTRA_DIST = $(FILESWML:$(srcdir)/%=%) +EXTRA_DIST = $(pylib_DATA) -CLEANFILES = $(pylib_DATA) *~ *.tmp *.pyc - -%.py: %.py.wml $(top_srcdir)/config/config.wml $(top_builddir)/config/configbis.wml - $(WML) -o $@ $< \ No newline at end of file +CLEANFILES = *~ *.tmp *.pyc diff --git a/modules/webstyle/lib/template.py b/modules/webstyle/lib/template.py new file mode 100644 index 000000000..1cee78a5f --- /dev/null +++ b/modules/webstyle/lib/template.py @@ -0,0 +1,41 @@ +## $Id$ + +## This file is part of the CERN Document Server Software (CDSware). +## Copyright (C) 2002, 2003, 2004, 2005 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. + +"""CDSware templating framework.""" + +__version__ = "$Id$" + +from config import cfg_template_skin + +def load(module=''): + """ Load and returns a template class, given a module name (like + 'websearch', 'webbasket',...). + + The module corresponding to the currently selected template model + (see config.wml, variable CFG_TEMPLATE_SKIN) is tried first. In case it + does not exist, it returns the default template for that module. + """ + + local = {} + # load the right template, based on the template, and the specified module + try: + mymodule = __import__("cdsware.%s_templates_%s" % (module, cfg_template_skin), local, local, ["cdsware.templates.%s_%s" % (module, cfg_template_skin)]) + except ImportError, e: + mymodule = __import__("cdsware.%s_templates" % (module), local, local, ["cdsware.templates.%s" % (module)]) + return mymodule.Template() diff --git a/modules/webstyle/lib/webpage.py b/modules/webstyle/lib/webpage.py index e0aae2950..2ca5181f5 100644 --- a/modules/webstyle/lib/webpage.py +++ b/modules/webstyle/lib/webpage.py @@ -1,243 +1,152 @@ ## $Id$ -## CDSware Web Page Template. ## This file is part of the CERN Document Server Software (CDSware). ## Copyright (C) 2002, 2003, 2004, 2005 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. +## 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" +"""CDSware Web Page Functions""" from config import * from messages import * from webuser import create_userinfobox_body import re import string import sys import time import traceback import urllib -## start Python: -## $Id$ -## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES. -"""CDSware Web Page Template""" - -page_template_header = """ - - - - - <!--CDSNAMEINTL-->: %s - - - - - - - - -""" - -page_template_footer = """ - - - -""" - -page_template_body = """ -
-
-
-
%s
-
%s
-
-
-
-
-
%s
-
%s
-
-
-
- %s -

%s

- %s - %s -
-
-""" +import template +webstyle_templates = template.load('webstyle') def create_navtrailbox_body(title, previous_links, - prolog="", + prolog="", separator=""" > """, epilog="", language=cdslang): """Create navigation trail box body 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 += """%s""" % (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 + + return webstyle_templates.tmpl_navtrailbox_body(weburl = weburl, + ln = language, + title = title, + previous_links = previous_links, + separator = separator, + prolog = prolog, + epilog = epilog) def page(title, body, navtrail="", description="", keywords="", uid=0, cdspageheaderadd="", cdspageboxlefttopadd="", cdspageboxleftbottomadd="", cdspageboxrighttopadd="", cdspageboxrightbottomadd="", cdspagefooteradd="", lastupdated="", language=cdslang, urlargs="", verbose=1, titleprologue="", titleepilogue=""): """page(): display CDS web 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 cdspageboxlefttopadd is a message to be displayed in the page body on left top cdspageboxleftbottomadd is a message to be displayed in the page body on left bottom cdspageboxrighttopadd is a message to be displayed in the page body on right top cdspageboxrightbottomadd is a message to be displayed in the page body on right bottom 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) verbose is verbosity of the page (useful for debugging) titleprologue is to be printed right before page title titleepilogue is to be printed right after page title 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 % (cdspageboxlefttopadd, cdspageboxleftbottomadd, cdspageboxrighttopadd, cdspageboxrightbottomadd, titleprologue, title, titleepilogue, body) - out += page_template_footer % (cdspagefooteradd, cdspagefooter) - out = re.sub(r"", cdsnameintl[language], out) - out = re.sub(r"", msg_search[language], out) - out = re.sub(r"", msg_submit[language], out) - out = re.sub(r"", msg_convert[language], out) - out = re.sub(r"", msg_agenda[language], out) - out = re.sub(r"", msg_webcast[language], out) - out = re.sub(r"", msg_bulletin[language], out) - out = re.sub(r"", msg_library[language], out) - out = re.sub(r"", msg_help[language], out) - out = re.sub(r"", msg_personalize[language], out) - out = re.sub(r"", language, out) - out = re.sub(r"", create_navtrailbox_body(title, navtrail, language=language), out) - out = re.sub(r"", create_userinfobox_body(uid, language), out) - out = re.sub(r"", create_language_selection_box(urlargs, language), out) - out = re.sub(r"", msg_powered_by[language], out) - out = re.sub(r"", msg_maintained_by[language], out) - if lastupdated: - out = re.sub(r"", msg_last_updated[language] + " " + lastupdated, out) - return out + + return webstyle_templates.tmpl_page(weburl = weburl, + ln = language, + headertitle = headerstitle, + sitename = cdsnameintl[language], + supportemail = supportemail, + description = description, + keywords = keywords, + userinfobox = create_userinfobox_body(uid, language), + navtrailbox = create_navtrailbox_body(title, navtrail, language=language), + uid = uid, + # pageheader = cdspageheader, + pageheaderadd = cdspageheaderadd, + boxlefttop = cdspageboxlefttop, + boxlefttopadd = cdspageboxlefttopadd, + boxleftbottomadd = cdspageboxleftbottomadd, + boxleftbottom = cdspageboxleftbottom, + boxrighttop = cdspageboxrighttop, + boxrighttopadd = cdspageboxrighttopadd, + boxrightbottomadd = cdspageboxrightbottomadd, + boxrightbottom = cdspageboxrightbottom, + titleprologue = titleprologue, + title = title, + titleepilogue = titleepilogue, + body = body, + # pagefooter = cdspagefooter, + languagebox = webstyle_templates.tmpl_language_selection_box(urlargs, language), + version = version, + lastupdated = lastupdated, + pagefooteradd = cdspagefooteradd) def pageheaderonly(title, navtrail="", description="", keywords="", uid=0, cdspageheaderadd="", language=cdslang, urlargs="", verbose=1): """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[language], out) - out = re.sub(r"", msg_search[language], out) - out = re.sub(r"", msg_submit[language], out) - out = re.sub(r"", msg_convert[language], out) - out = re.sub(r"", msg_agenda[language], out) - out = re.sub(r"", msg_webcast[language], out) - out = re.sub(r"", msg_bulletin[language], out) - out = re.sub(r"", msg_library[language], out) - out = re.sub(r"", msg_help[language], out) - out = re.sub(r"", msg_personalize[language], out) - out = re.sub(r"", language, out) - out = re.sub(r"", create_navtrailbox_body(title, navtrail, language=language), out) - out = re.sub(r"", create_userinfobox_body(uid, language), out) - out = re.sub(r"", create_language_selection_box(urlargs, language), out) - return out + + return webstyle_templates.tmpl_pageheader(weburl = weburl, + ln = language, + headertitle = title, + sitename = cdsnameintl[language], + supportemail = supportemail, + description = description, + keywords = keywords, + userinfobox = create_userinfobox_body(uid, language), + navtrailbox = create_navtrailbox_body(title, navtrail, language=language), + uid = uid, + # pageheader = cdspageheader, + pageheaderadd = cdspageheaderadd, + languagebox = webstyle_templates.tmpl_language_selection_box(urlargs, language)) def pagefooteronly(cdspagefooteradd="", lastupdated="", language=cdslang, urlargs="", verbose=1): """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[language], out) - out = re.sub(r"", msg_search[language], out) - out = re.sub(r"", msg_submit[language], out) - out = re.sub(r"", msg_convert[language], out) - out = re.sub(r"", msg_agenda[language], out) - out = re.sub(r"", msg_webcast[language], out) - out = re.sub(r"", msg_bulletin[language], out) - out = re.sub(r"", msg_library[language], out) - out = re.sub(r"", msg_help[language], out) - out = re.sub(r"", msg_personalize[language], out) - out = re.sub(r"", language, out) - out = re.sub(r"", msg_powered_by[language], out) - out = re.sub(r"", msg_maintained_by[language], out) - out = re.sub(r"", create_language_selection_box(urlargs, language), out) - if lastupdated: - out = re.sub(r"", msg_last_updated[language] + " " + lastupdated, out) - return out + + return webstyle_templates.tmpl_pagefooter(weburl = weburl, + ln = language, + sitename = cdsnameintl[language], + supportemail = supportemail, + # pagefooter = cdspagefooter, + languagebox = webstyle_templates.tmpl_language_selection_box(urlargs, language), + version = version, + lastupdated = lastupdated, + pagefooteradd = cdspagefooteradd) def create_error_box(req, title=None, verbose=1, ln=cdslang): """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.""" - if title == None: - title = msg_internal_error[ln] - boxhead = """

%s %s %s""" % (title, sys.exc_info()[0], sys.exc_info()[1]) - boxbody = """

""" + msg_please_contact_and_quote[ln] % (urllib.quote(supportemail), supportemail) - boxbody += """

"""
-    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 += """
""" - out = """ - - - - - - - - - - - -
- %s -
%s
""" % (boxhead, boxbody) - return out - + """ + return webstyle_templates.tmpl_error_box(title = title, + ln = ln, + verbose = verbose, + req = req, + supportemail = supportemail) diff --git a/modules/webstyle/lib/webstyle_templates.py b/modules/webstyle/lib/webstyle_templates.py new file mode 100644 index 000000000..033645246 --- /dev/null +++ b/modules/webstyle/lib/webstyle_templates.py @@ -0,0 +1,533 @@ +## $Id$ +## CDSware WebStyle templates. + +## This file is part of the CERN Document Server Software (CDSware). +## Copyright (C) 2002, 2003, 2004, 2005 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. + +import urllib +import time +import cgi +import gettext +import traceback +import sre +import urllib +import sys + +from config import * +from messages import gettext_set_language, language_list_long + +class Template: + def tmpl_navtrailbox_body(self, weburl, ln, title, previous_links, separator, prolog, epilog): + """Create navigation trail box body + + Parameters: + + - 'weburl' *string* - The base URL for the site + + - 'ln' *string* - The language to display + + - 'title' *string* - page title; + + - 'previous_links' *string* - the trail content from site title until current page (both ends exlusive) + + - '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 + """ + + # load the right message language + _ = gettext_set_language(ln) + + out = "" + if title != cdsnameintl[ln]: + out += """%(msg_home)s""" % { + 'weburl' : weburl, + 'ln' : ln, + 'msg_home' : _("Home")} + if previous_links: + if out: + out += separator + out += previous_links + if title: + if out: + out += separator + if title == cdsnameintl[ln]: # hide site name, print Home instead + out += _("Home") + else: + out += title + return prolog + out + epilog + + def tmpl_page(self, weburl, ln, headertitle, sitename = "", supportemail = "", description = "", keywords = "", + userinfobox = "", navtrailbox = "", + pageheaderadd = "", boxlefttop = "", boxlefttopadd = "", + boxleftbottom = "", boxleftbottomadd = "", boxrighttop = "", boxrighttopadd = "", + boxrightbottom = "", boxrightbottomadd = "", titleprologue = "", title = "", titleepilogue = "", body = "", + version = "", lastupdated = None, languagebox = "", + pagefooteradd = "", + uid = 0, + ): + """Creates a complete page + + Parameters: + + - 'weburl' *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 + + - 'supportemail' *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 + + - 'userinfobox' *string* - the HTML code for the user information box + + - '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 + + - 'body' *string* - the body of the page + + - 'version' *string* - the version number of CDSware + + - '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 + """ + + # load the right message language + _ = gettext_set_language(ln) + + if lastupdated: + msg_lastupdated = _("Last updated:") + " " + lastupdated + else: + msg_lastupdated = "" + out = self.tmpl_pageheader( + weburl = weburl, + ln = ln, + headertitle = headertitle, + sitename = sitename, + supportemail = supportemail, + description = description, + keywords = keywords, + userinfobox = userinfobox, + navtrailbox = navtrailbox, + pageheaderadd = pageheaderadd, + languagebox = languagebox, + ) + """ +
+
+
%(boxlefttop)s
+
%(boxlefttopadd)s
+
%(boxleftbottomadd)s
+
%(boxleftbottom)s
+
+
+
%(boxrighttop)s
+
%(boxrighttopadd)s
+
%(boxrightbottomadd)s
+
%(boxrightbottom)s
+
+
+

%(title)s

+ %(body)s +
+
+""" % { + 'boxlefttop' : boxlefttop, + 'boxlefttopadd' : boxlefttopadd, + + 'boxleftbottom' : boxleftbottom, + 'boxleftbottomadd' : boxleftbottomadd, + + 'boxrighttop' : boxrighttop, + 'boxrighttopadd' : boxrighttopadd, + + 'boxrightbottom' : boxrightbottom, + 'boxrightbottomadd' : boxrightbottomadd, + + 'title' : title, + 'body' : body, + +} + self.tmpl_pagefooter( + weburl = weburl, + ln = ln, + sitename = sitename, + supportemail = supportemail, + version = version, + lastupdated = lastupdated, + languagebox = languagebox, + pagefooteradd = pagefooteradd + ) + return out + + def tmpl_pageheader(self, weburl, ln, headertitle = "", sitename = "", supportemail = "", description = "", keywords = "", + userinfobox = "", navtrailbox = "", + pageheaderadd = "", languagebox = "", + uid = 0, + ): + """Creates a page header + + Parameters: + + - 'weburl' *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 + + - 'supportemail' *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 + + - 'userinfobox' *string* - the HTML code for the user information box + + - '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 + + Output: + + - HTML code of the page headers + """ + + # load the right message language + _ = gettext_set_language(ln) + + out = """ + + + + + %(sitename)s: %(headertitle)s + + + + + + + + + """ % { + 'weburl' : weburl, + 'ln' : ln, + + 'sitename' : sitename, + 'headertitle' : headertitle, + 'supportemail' : supportemail, + + 'description' : description, + 'keywords' : keywords, + + 'userinfobox' : userinfobox, + 'navtrailbox' : navtrailbox, + + 'pageheaderadd' : pageheaderadd, + + 'msg_search' : _("Search"), + 'msg_submit' : _("Submit"), + 'msg_personalize' : _("Personalize"), + 'msg_help' : _("Help"), + 'languagebox' : languagebox, + + } + return out + + def tmpl_pagefooter(self, weburl, ln, sitename = "", supportemail = "", + version = "", lastupdated = None, languagebox = "", + pagefooteradd = "" + ): + """Creates a page footer + + Parameters: + + - 'weburl' *string* - The base URL for the site + + - 'ln' *string* - The language to display + + - 'sitename' *string* - the first part of the page HTML title + + - 'supportemail' *string* - email of the support team + + - 'version' *string* - the version number of CDSware + + - '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: + msg_lastupdated = _("Last updated:") + " " + lastupdated + else: + msg_lastupdated = "" + + out = """ + + + + """ % { + 'weburl' : weburl, + 'ln' : ln, + + 'sitename' : sitename, + 'supportemail' : supportemail, + + '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' : languagebox, + 'version' : version, + + 'pagefooteradd' : pagefooteradd, + + } + return out + + def tmpl_language_selection_box(self, urlargs="", language="en"): + """Take URLARGS and LANGUAGE and return textual language + selection box for the given page. + + Parameters: + + - 'urlargs' *string* - The url args that helped produce this page + + - 'language' *string* - The selected language + + """ + + # load the right message language + _ = gettext_set_language(language) + + out = "" + for (lang, lang_namelong) in language_list_long(): + if lang == language: + out += """ %s   """ % lang_namelong + else: + if urlargs: + urlargs = sre.sub(r'ln=.*?(&|$)', '', urlargs) + if urlargs: + if urlargs.endswith('&'): + urlargs += "ln=%s" % lang + else: + urlargs += "&ln=%s" % lang + else: + urlargs = "ln=%s" % lang + out += """ %s   """ % (urlargs, lang_namelong) + return _("This site is also available in the following languages:") + "
" + out + + def tmpl_error_box(self, ln, title, verbose, req, supportemail): + """Produces an error box. + + Parameters: + + - 'title' *string* - The title of the error box + + - 'ln' *string* - The selected language + + - 'verbose' *bool* - If lots of information should be displayed + + - 'req' *object* - the request object + + - 'supportemail' *string* - the supportemail for this installation + """ + + # load the right message language + _ = gettext_set_language(ln) + + if title == None: + title = _("Internal Error") + + error_s = '' + traceback_s = '' + if verbose >= 1: + error_s = """Error: %s %s\n""" % (sys.exc_info()[0], sys.exc_info()[1]) + if verbose >= 9: + traceback_s = "Traceback: \n%s" % string.join(traceback.format_tb(sys.exc_info()[2]),"\n") + + browser_s = '' + if req.headers_in.has_key('User-Agent'): + browser_s = """Browser: %s\n""" % req.headers_in['User-Agent'] + + out = """ + + + + + + + + + + + +
+

%(title)s %(sys1)s %(sys2)s +

+

%(contact)s +

+URI: http://%(host)s%(page)s
+Time: %(time)s
+%(browser)sClient: %(client)s
+%(error)s%(traceback)s
+
+
+ """ % { + 'title' : title, + 'sys1' : sys.exc_info()[0], + 'sys2' : sys.exc_info()[1], + 'contact' : _("Please contact %s quoting the following information:") % (urllib.quote(supportemail), supportemail), + 'host' : req.hostname, + 'page' : req.unparsed_uri, + 'time' : time.strftime("%02d/%b/%Y:%H:%M:%S %z"), + 'browser' : browser_s, + 'client' : req.connection.remote_ip, + 'error' : error_s, + 'traceback' : traceback_s, + } + return out