Page MenuHomec4science

websearchadmin.py.wml
No OneTemporary

File Metadata

Created
Fri, Nov 1, 02:38

websearchadmin.py.wml

## $Id$
## CDSware WebSearch Administrator tools.
## 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>
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
"""CDSware WebSearch Administrator."""
## fill config variables:
pylibdir = "<LIBDIR>/python"
import cgi
import os
import sys
import urllib
sys.path.append('%s' % pylibdir)
from cdsware.config import *
from cdsware import search_engine
from cdsware.webpage import page, pageheaderonly, pagefooteronly
from cdsware.webuser import getUid
from cdsware.dbquery import run_sql
from mod_python import apache
__version__ = "$Id$"
### CALLABLES
def index(req):
"""Main entry point to WebSearch Admin."""
__auth_realm__ = "restricted area"
def __auth__(req, user, password): # FIXME: use Mikael's stuff here instead
"""Is user authorized to proceed with the request?"""
import sys
sys.path.append("<LIBDIR>/python")
from cdsware.config import supportemail
from cdsware.webuser import auth_apache_user_p
if user != supportemail:
return 0
if not auth_apache_user_p(user, password):
return 0
return 1
uid = getUid(req)
return page(title="WebSearch Admin",
body=perform_index(),
navtrail="""<a class="navtrail" href="%s/admin/">Admin Area</a>""" % weburl,
description="The administrator of the CDSware WebSearch collections.",
keywords="CDSware, WebSearch, collection, administrator",
uid=uid)
def edit(req, c=cdsname):
"""Edit collection details and propose links to update the information."""
uid = getUid(req)
return page(title="Edit %s" % c,
body=perform_edit(c),
navtrail="""<a class="navtrail" href="%s/admin/">Admin Area</a> &gt; <a class="navtrail" href="%s/websearchadmin.py">WebSearch Admin</a>""" % (weburl, weburl),
description="The administrator of the CDSware WebSearch collections.",
keywords="CDSware, WebSearch, collection, administrator",
uid=uid)
def update(req, c, nc, nq, ur=0, uw=0):
"""Change collection data according to parameters passed:
c = collection name (old)
nc = new collection name
nq = new dbquery
ur = do we update reclist cache?
uw = do we update webpage cache?
"""
# sanity check:
if nq == None:
nq = ""
# print header:
uid = getUid(req)
req.content_type = "text/html"
req.send_http_header()
req.write(pageheaderonly(title="Update %s" %c ,
navtrail="""<a class="navtrail" href="%s/admin/">Admin Area</a> &gt; <a class="navtrail" href="%s/websearchadmin.py">WebSearch Admin</a>""" % (weburl, weburl),
description="The administrator of the CDSware WebSearch collections.",
keywords="CDSware, WebSearch, collection, administrator",
uid=uid))
# update collection name:
req.write("""<h1 class="headline">Updating %s ...</h1>""" % c)
if nc != c:
req.write("\n<p>Updating name ... %s" % c)
res = run_sql("UPDATE collection SET name=%s WHERE name=%s", (nc, c))
req.write(" done.")
# update dbquery:
req.write("\n<p>Updating query (%s) ..." % nq)
res = run_sql("UPDATE collection SET dbquery=%s WHERE name=%s", (nq, nc))
req.write(" done.")
# call reclist, if needed:
if ur:
req.write("\n<p>Updating reclist cache ...\n")
os.environ['collname'] = c
os.system('%s/webcoll update-reclist "$collname"' % bindir)
res = run_sql("SELECT nbrecs FROM collection WHERE name=%s", (nc,))
if res:
req.write(" found %s records." % res[0][0])
if uw:
req.write("\n<p>Updating web page cache ...\n")
os.environ['collname'] = c
os.system('%s/webcoll update-webpage "$collname"' % bindir)
req.write(" done.")
req.write("\n<p>Finished.")
req.write(pagefooteronly())
return "\n"
## IMPLEMENTATION
def perform_index():
"""List all collections and the relevant information."""
out = ""
res = run_sql("SELECT id,name,nbrecs,dbquery FROM collection ORDER BY name ASC")
if res:
out += """<table cellpadding="5" cellspacing="0" border="1">
<thead>
<tr>
<th align="right">
ID
</th>
<th align="left">
Name
</th>
<th align="right">
No. Recs
</th>
<th align="left">
Query
</th>
<th align="left">
ACTION
</th>
</tr>
</thead>
<tbody>"""
for c_id, c_name, c_nbrecs, c_dbquery in res:
out += """<tr><td align="right">%s</td><td align="left">%s</td><td align="right">%s</td><td align="left">%s</td><td align="left"><a href="%s/websearchadmin.py/edit?c=%s">Edit</a></td></tr>""" \
% (c_id, c_name, c_nbrecs, c_dbquery, weburl, urllib.quote_plus(c_name))
out += """</tbody>
</table>"""
else:
out += """<p>No collection seem to be defined."""
return out
def perform_edit(c):
"""Display collection data for editing."""
out = "<blockquote>"
res = run_sql("SELECT nbrecs,dbquery FROM collection WHERE name=%s", (c,))
if res:
c_nbrecs, c_dbquery = res[0][0], res[0][1]
if c_dbquery == None:
c_dbquery = ""
out += """<form action="%s/websearchadmin.py/update">""" % weburl
out += """<input type="hidden" name="c" value="%s">""" % c
out += """<p>New collection name: <input type="text" size="60" name="nc" value="%s">""" % cgi.escape(c, 1)
out += """<p>New collection query: <input type="text" size="60" name="nq" value="%s">""" % cgi.escape(c_dbquery, 1)
out += """<p><input type="checkbox" name="ur" value="y" checked>update reclist cache?"""
out += """<p><input type="checkbox" name="uw" value="y" checked>update webpage cache?"""
out += """<p><input class="formbutton" type="submit" name="action" value="UPDATE">"""
out += """</form>"""
out += """</blockquote>"""
else:
out += "<p>There is no collection named %s.""" % c
return out

Event Timeline