Page MenuHomec4science

index.py
No OneTemporary

File Metadata

Created
Sat, May 18, 08:11

index.py

## $Id$
## CDSware Search Interface.
## 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"
## start Python:
<protect>## $Id$
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
## fill config variables:
pylibdir = "<LIBDIR>/python"
import sys
import sre
import MySQLdb
sys.path.append('%s' % pylibdir)
from cdsware.config import weburl,cdsname,cdslang,cachedir,cdsnameintl
from cdsware.messages import *
from cdsware.dbquery import run_sql
from cdsware.webpage import page, create_error_box
from cdsware.webuser import getUid
def index(req, c=cdsname, as="0", verbose="1", ln=cdslang):
"Display search interface page for collection c by looking in the collection cache."
# wash params:
try:
as = int(as)
except:
as = 0
try:
verbose = int(verbose)
except:
verbose = 1
if type(c) is list:
c = c[0]
ln = wash_language(ln)
# get user ID:
try:
uid = getUid(req)
except MySQLdb.Error, e:
return page(title=msg_internal_error[ln],
body = create_error_box(req, verbose=verbose, ln=ln),
description="%s - Internal Error" % cdsname,
keywords="%s, CDSware, Internal Error" % cdsname,
language=ln,
urlargs=req.args)
# start display:
req.content_type = "text/html"
req.send_http_header()
# deduce collection id:
collid = get_collid(c)
if type(collid) is not int:
return page(title=msg_collection_not_found_head[ln] % c,
body=msg_collection_not_found_body[ln] % (c, weburl, cdsname),
description="%s - Not found: %s " % (cdsname, c),
keywords="%s, CDSware" % cdsname,
uid=uid,
language=ln,
urlargs=req.args)
# display collection interface page:
try:
fp = open("%s/collections/%d/navtrail-as=%d-ln=%s.html" % (cachedir, collid, as, ln), "r")
c_navtrail = fp.read()
fp.close()
fp = open("%s/collections/%d/body-as=%d-ln=%s.html" % (cachedir, collid, as, ln), "r")
c_body = fp.read()
fp.close()
fp = open("%s/collections/%d/portalbox-lt-ln=%s.html" % (cachedir, collid, ln), "r")
c_portalbox_lt = fp.read()
fp.close()
fp = open("%s/collections/%d/portalbox-lb-ln=%s.html" % (cachedir, collid, ln), "r")
c_portalbox_lb = fp.read()
fp.close()
fp = open("%s/collections/%d/portalbox-rt-ln=%s.html" % (cachedir, collid, ln), "r")
c_portalbox_rt = fp.read()
fp.close()
fp = open("%s/collections/%d/portalbox-rb-ln=%s.html" % (cachedir, collid, ln), "r")
c_portalbox_rb = fp.read()
fp.close()
fp = open("%s/collections/%d/last-updated-ln=%s.html" % (cachedir, collid, ln), "r")
c_last_updated = fp.read()
fp.close()
if c == cdsname: # title of the page depends on collection name and language
title = cdsnameintl[ln]
else:
title = c
return page(title=title,
body=c_body,
navtrail=c_navtrail,
description="%s - %s" % (cdsname, c),
keywords="%s, CDSware, %s" % (cdsname, c),
uid=uid,
language=ln,
urlargs=req.args,
cdspagerightstripeadd=c_portalbox_rt,
lastupdated=c_last_updated)
except:
if verbose >= 9:
req.write("<br>c=%s" % c)
req.write("<br>as=%s" % as)
req.write("<br>ln=%s" % ln)
req.write("<br>collid=%s" % collid)
req.write("<br>uid=%s" % uid)
return page(title=msg_internal_error[ln],
body = create_error_box(req, ln=ln),
description="%s - Internal Error" % cdsname,
keywords="%s, CDSware, Internal Error" % cdsname,
uid=uid,
language=ln,
urlargs=req.args)
return "\n"
def get_collid(c):
"Return collection ID for given collection name. Return None if no match found."
collid = None
res = run_sql("SELECT id FROM collection WHERE name=%s", (c,), 1)
if res:
collid = res[0][0]
return collid

Event Timeline