diff --git a/modules/websearch/lib/websearchadminlib.py b/modules/websearch/lib/websearchadminlib.py
index f0c57105a..66dfad41c 100644
--- a/modules/websearch/lib/websearchadminlib.py
+++ b/modules/websearch/lib/websearchadminlib.py
@@ -1,2942 +1,2637 @@
## Administrator interface for WebSearch
## 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"
#include "cdswmllib.wml"
## $Id$## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
"""CDSware WebSearch Administrator Interface."""
__lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>"""
## fill config variables:
import access_control_engine as acce
import cgi
import re
import MySQLdb
import Numeric
import os
import urllib
+import random
from zlib import compress,decompress
from bibrankadminlib import modify_translations, get_current_name,get_name,get_rnk_nametypes,get_languages,check_user,is_adminuser,adderrorbox,addadminbox,tupletotable,tupletotable_onlyselected,addcheckboxes,createhiddenform,serialize_via_numeric_array_dumps,serialize_via_numeric_array_compr,serialize_via_numeric_array_escape,serialize_via_numeric_array,deserialize_via_numeric_array,serialize_via_marshal,deserialize_via_marshal
from messages import *
from dbquery import run_sql
from config import *
from webpage import page, pageheaderonly, pagefooteronly
from webuser import getUid, get_email
from mod_python import apache
__version__ = "$Id$"
def getnavtrail(previous = ''):
"""Get the navtrail"""
navtrail = """Admin Area > WebSearch Admin """ % (weburl, weburl)
navtrail = navtrail + previous
return navtrail
def perform_modifytranslations(colID, ln=cdslang, sel_type='', trans=[], confirm=-1, callback='yes'):
"""Modify the translations of a collection
sel_type - the nametype to modify
trans - the translations in the same order as the languages from get_languages()"""
output = ''
subtitle = ''
cdslangs = get_languages()
if confirm in ["2", 2] and colID:
finresult = modify_translations(colID, cdslangs, sel_type, trans, "collection")
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """3. Modify translations for collection '%s'   [?]""" % (col_dict[colID], weburl)
if type(trans) is str:
trans = [trans]
if sel_type == '':
sel_type = get_col_nametypes()[0][0]
header = ['Language', 'Translation']
actions = []
types = get_col_nametypes()
if len(types) > 1:
text = """
Name type
"""
output += createhiddenform(action="modifytranslations#3",
text=text,
button="Select",
colID=colID,
ln=ln,
confirm=0)
if confirm in [-1, "-1", 0, "0"]:
trans = []
for (key, value) in cdslangs:
try:
trans_names = get_name(colID, key, sel_type, "collection")
trans.append(trans_names[0][0])
except StandardError, e:
trans.append('')
for nr in range(0,len(cdslangs)):
actions.append(["%s %s" % (cdslangs[nr][1], (cdslangs[nr][0]==cdslang and '(def)' or ''))])
actions[-1].append('' % trans[nr])
text = tupletotable(header=header, tuple=actions)
output += createhiddenform(action="modifytranslations#3",
text=text,
button="Modify",
colID=colID,
sel_type=sel_type,
ln=ln,
- confirm=1)
-
- if sel_type and len(trans):
- if confirm in ["1", 1]:
- text = """Please confirm modification of translations for collection '%s'.""" % (col_dict[colID])
- output += createhiddenform(action="modifytranslations#3",
- text=text,
- button="Confirm",
- colID=colID,
- sel_type=sel_type,
- trans=trans,
- ln=ln,
- confirm=2)
+ confirm=2)
- elif confirm in ["2", 2]:
- if finresult:
- output += """Translations modified for collection '%s'.""" % (col_dict[colID])
- else:
- output += """Sorry, could not modify translations for collection '%s'.""" % (col_dict[colID])
+ if sel_type and len(trans) and confirm in ["2", 2]:
+ if finresult:
+ output += """Translations modified for collection '%s'.""" % (col_dict[colID])
+ else:
+ output += """Sorry, could not modify translations for collection '%s'.""" % (col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifytranslations", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifyrankmethods(colID, ln=cdslang, func='', rnkID='', confirm=0, callback='yes'):
"""Modify which rank methods is visible to the collection
func - remove or add rank method
rnkID - the id of the rank method."""
output = ""
subtitle = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
rnk_dict = dict(get_current_name('',ln, get_rnk_nametypes()[0][0], "rnkMETHOD"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
if func in ["0", 0] and confirm in ["1", 1]:
finresult = attach_rnk_col(colID, rnkID)
elif func in ["1", 1] and confirm in ["1", 1]:
finresult = detach_rnk_col(colID, rnkID)
subtitle = """9. Modify rank options for collection '%s'   [?]""" % (col_dict[colID], weburl)
output = """
The rank methods enabled for the collection '%s' is:
"""
if not rnkmethods:
output += """No rank methods"""
else:
for id, name in rnkmethods:
output += """%s, """ % name
output += """
"""
rnk_list = get_current_name('',ln, get_rnk_nametypes()[0][0], "rnkMETHOD")
rnk_dict_in_col = dict(get_col_rnk(colID, ln))
rnk_list = filter(lambda x: not rnk_dict_in_col.has_key(x[0]), rnk_list)
if rnk_list:
text = """
Enable:
"""
output += createhiddenform(action="modifyrankmethods#9",
text=text,
button="Enable",
colID=colID,
ln=ln,
func=0,
- confirm=0)
-
- if confirm in ["0", 0] and func in ["0", 0] and int(rnkID) != -1:
- text = "Please confirm to enable rank method '%s' for the collection '%s'" % (dict(rnk_list)[int(rnkID)], col_dict[colID])
- output += createhiddenform(action="modifyrankmethods#9",
- text=text,
- button="Confirm",
- colID=colID,
- ln=ln,
- rnkID=rnkID,
- func=0,
confirm=1)
-
- elif confirm in ["1", 1] and func in ["0", 0] and len(rnkID) > 0:
+
+ if confirm in ["1", 1] and func in ["0", 0] and int(rnkID) != -1:
if finresult:
output += """Rank method '%s' enabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
else:
output += """Rank method '%s' could not be enabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
-
+ elif confirm not in ["0", 0] and func in ["0", 0]:
+ output += """Please select a rank method."""
+
coll_list = get_col_rnk(colID, ln)
if coll_list:
text = """
Disable:
"""
output += createhiddenform(action="modifyrankmethods#9",
text=text,
button="Disable",
colID=colID,
ln=ln,
func=1,
- confirm=0)
-
- if confirm in ["0", 0] and func in ["1", 1] and int(rnkID) != -1:
- text = "Please confirm to disable rank method '%s' for collection '%s'" % (rnk_dict[int(rnkID)], col_dict[colID])
- output += createhiddenform(action="modifyrankmethods#9",
- text=text,
- button="Confirm",
- colID=colID,
- ln=ln,
- rnkID=rnkID,
- func=1,
confirm=1)
- elif confirm in ["1", 1] and func in ["1", 1]:
+
+ if confirm in ["1", 1] and func in ["1", 1] and int(rnkID) != -1:
if finresult:
output += """Rank method '%s' disabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
else:
output += """Rank method '%s' could not be disabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
+ elif confirm not in ["0", 0] and func in ["1", 1]:
+ output += """Please select a rank method."""
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifyrankmethods", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_addcollectiontotree(colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1):
"""Form to add a collection to the tree.
add_dad - the dad to add the collection to
add_son - the collection to add
rtype - add it as a regular or virtual
mtype - add it to the regular or virtual tree."""
output = ""
output2 = ""
subtitle = """Attach collection to tree   [?]""" % (weburl)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- if confirm in [0, "0"] and not (add_son and add_dad and rtype):
+ if confirm not in [-1, "-1"] and not (add_son and add_dad and rtype):
output2 += """All fields must be filled.
"""
elif add_son and add_dad and rtype:
add_son = int(add_son)
add_dad = int(add_dad)
- if confirm in [0, "0"]:
+ if confirm not in [-1, "-1"]:
if add_son == add_dad:
output2 += """Cannot add a collection as a pointer to itself.
"""
elif check_col(add_dad, add_son):
- text = """Do you want to add the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- output2 += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollectiontotree" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- add_son=add_son,
- add_dad=add_dad,
- ln=ln,
- rtype=rtype,
- confirm=1)
+ if add_col_dad_son(add_dad, add_son, rtype):
+ output2 += """Added the collection '%s' as a %s subcollection of '%s'.
+ """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
+ else:
+ output2 += """Could not add the collection '%s' as a %s subcollection of '%s'.
+ """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
else:
output2 += """Cannot add the collection '%s' as a %s subcollection of '%s' since it will either create a loop, or the association already exists.
""" % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- else:
- if add_col_dad_son(add_dad, add_son, rtype):
- output2 += """Added the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- else:
- output2 += """Could not add the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
add_son = ''
add_dad = ''
rtype = ''
tree = get_col_tree(colID)
col_list = col_dict.items()
col_list.sort(compare_on_val)
text = """
Attach which Attach to
"""
text += """
Relationship
""" % ((rtype=="r" and 'selected="selected"' or ''), (rtype=="v" and 'selected="selected"' or ''))
output = createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollectiontotree" % weburl,
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
output += output2
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_index(colID, ln, mtype="perform_addcollectiontotree", content=addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_addcollection(colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1):
"""form to add a new collection.
colNAME - the name of the new collection
dbquery - the dbquery of the new collection
rest - the group allowed to access the new collection"""
output = ""
subtitle = """Create new collection [?]""" % (weburl)
text = """
Collection name
""" % colNAME
output = createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollection" % weburl,
text=text,
colID=colID,
ln=ln,
button="Add collection",
- confirm=0)
- if colNAME:
- if confirm in ["0", 0]:
- text = """Add collection with default name: '%s'.
- """ % (colNAME)
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollection" % weburl,
- text=text,
- colID=colID,
- colNAME=colNAME,
- dbquery=dbquery,
- rest=rest,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
- res = add_col(colNAME, '', '')
- if res:
- output += """Added new collection with default name '%s'
- """ % colNAME
- else:
- output += """Sorry, could not add collection, most likely the collection already exists.
- """
- elif confirm in ["0", 0]:
+ confirm=1)
+ if colNAME and confirm in ["1", 1]:
+ res = add_col(colNAME, '', '')
+ if res:
+ output += """Added new collection with default name '%s'
+ """ % colNAME
+ else:
+ output += """Sorry, could not add collection, most likely the collection already exists.
+ """
+ elif confirm not in ["-1", -1]:
output += """Please give the collection a name.
"""
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_index(colID, ln=ln, mtype="perform_addcollection", content=addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifydbquery(colID, ln=cdslang, dbquery='', callback='yes', confirm=-1):
"""form to modify the dbquery of the collection.
dbquery - the dbquery of the collection."""
subtitle = ''
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """1. Modify collection query for collection '%s'   [?]""" % (col_dict[colID], weburl)
if confirm == -1:
res = run_sql("SELECT dbquery FROM collection WHERE id=%s" % colID)
dbquery = res[0][0]
if not dbquery:
dbquery = ''
reg_sons = len(get_col_tree(colID, 'r'))
vir_sons = len(get_col_tree(colID, 'v'))
if reg_sons > 1 or vir_sons > 1:
if dbquery:
output += "Warning: This collection got subcollections, and should because of this not have a collection query, for further explanation, check the WebSearch Guide "
elif reg_sons <= 1 and vir_sons <= 1:
if not dbquery:
output += "Warning: This collection does not have any subcollections, and should because of this have a collection query, for further explanation, check the WebSearch Guide "
text = """
Query
""" % dbquery
output += createhiddenform(action="modifydbquery",
text=text,
button="Modify",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if confirm in ["0", 0]:
- if dbquery:
- text = """Change query for this collection to: '%s'.""" % dbquery
- else:
- text = """Remove query for this collection."""
- output += createhiddenform(action="modifydbquery",
- text=text,
- colID=colID,
- dbquery=dbquery,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
+ if confirm in ["1", 1]:
res = modify_dbquery(colID, dbquery)
if res:
text = """Changed query."""
else:
text = """Sorry, could not change query."""
output += text
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifydbquery", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifyrestricted(colID, ln=cdslang, rest='', callback='yes', confirm=-1):
"""modify which apache group is allowed to access the collection.
rest - the groupname"""
subtitle = ''
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """2. Modify access restrictions for collection '%s'   [?]""" % (col_dict[colID], weburl)
if confirm == -1:
res = run_sql("SELECT restricted FROM collection WHERE id=%s" % colID)
rest = res[0][0]
if not rest:
rest = ''
text = """
Restricted to:
""" % rest
output += createhiddenform(action="modifyrestricted",
text=text,
button="Modify",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if confirm in ["0", 0]:
- if rest:
- text = """Change access restrictions for this collection to: '%s'.""" % rest
- else:
- text = """Remove any access restrictions for this collection."""
-
- output += createhiddenform(action="modifyrestricted",
- colID=colID,
- text=text,
- rest=rest,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
+ if confirm in ["1", 1]:
res = modify_restricted(colID, rest)
if res:
text = """Changed the access restrictions."""
else:
text = """Sorry, could not change the access restrictions."""
output += text
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifyrestricted", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifycollectiontree(colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0):
"""to modify the collection tree: move a collection up and down, delete a collection, or change the father of the collection.
colID - the main collection of the tree, the root
move_up - move this collection up (is not the collection id, but the place in the tree)
move_up - move this collection down (is not the collection id, but the place in the tree)
move_from - move this collection from the current positon (is not the collection id, but the place in the tree)
move_to - move the move_from collection and set this as it's father. (is not the collection id, but the place in the tree)
delete - delete this collection from the tree (is not the collection id, but the place in the tree)
rtype - the type of the collection in the tree, regular or virtual"""
colID = int(colID)
tree = get_col_tree(colID, rtype)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- subtitle = """Modify collection tree: %s [?]""" % (col_dict[colID], weburl)
+ subtitle = """Modify collection tree: %s [?] Printer friendly version""" % (col_dict[colID], weburl, weburl, colID, ln)
fin_output = ""
output = ""
try:
if move_up:
move_up = int(move_up)
switch = find_last(tree, move_up)
if switch and switch_col_treescore(tree[move_up], tree[switch]):
output += """Moved the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]], col_dict[tree[switch][0]])
else:
output += """Could not move the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]], col_dict[tree[switch][0]])
elif move_down:
move_down = int(move_down)
switch = find_next(tree, move_down)
if switch and switch_col_treescore(tree[move_down], tree[switch]):
output += """Moved the %s collection '%s' down and '%s' up.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_down][0]], col_dict[tree[switch][0]])
else:
output += """Could not move the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]],col_dict[tree[switch][0]])
elif delete:
delete = int(delete)
if confirm in [0, "0"]:
if col_dict[tree[delete][0]] != col_dict[tree[delete][3]]:
text = """Do you want to remove the %s collection '%s' and its subcollections in the %s collection '%s'.
""" % ((tree[delete][4]=="r" and 'regular' or 'virtual'), col_dict[tree[delete][0]], (rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
else:
text = """Do you want to remove all subcollections of the %s collection '%s'.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/modifycollectiontree#tree" % weburl,
text=text,
button="Confirm",
colID=colID,
delete=delete,
rtype=rtype,
ln=ln,
confirm=1)
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text="To cancel",
button="Cancel",
colID=colID,
ln=ln)
else:
if remove_col_subcol(tree[delete][0], tree[delete][3], rtype):
if col_dict[tree[delete][0]] != col_dict[tree[delete][3]]:
output += """Removed the %s collection '%s' and its subcollections in subdirectory '%s'.
""" % ((tree[delete][4]=="r" and 'regular' or 'virtual'), col_dict[tree[delete][0]], col_dict[tree[delete][3]])
else:
output += """Removed the subcollections of the %s collection '%s'.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
else:
output += """Could not remove the collection from the tree.
"""
delete = ''
elif move_from and not move_to:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
text = """Select collection to place the %s collection '%s' under.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_from_id][0]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text=text,
button="Cancel",
colID=colID,
ln=ln)
elif move_from and move_to:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
move_to_rtype = move_to[0]
move_to_id = int(move_to[1:len(move_to)])
tree_from = get_col_tree(colID, move_from_rtype)
tree_to = get_col_tree(colID, move_to_rtype)
if confirm in [0, '0']:
if move_from_id == move_to_id and move_from_rtype==move_to_rtype:
output += """Cannot move to itself.
"""
elif tree_from[move_from_id][3] == tree_to[move_to_id][0] and move_from_rtype==move_to_rtype:
output += """The collection is already there.
"""
elif check_col(tree_to[move_to_id][0], tree_from[move_from_id][0]) or (tree_to[move_to_id][0] == 1 and tree_from[move_from_id][3] == tree_to[move_to_id][0] and move_from_rtype != move_to_rtype):
text = """Move %s collection '%s' to the %s collection '%s'.
""" % ((tree_from[move_from_id][4]=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (tree_to[move_to_id][4]=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/modifycollectiontree#tree" % weburl,
text=text,
button="Confirm",
colID=colID,
move_from=move_from,
move_to=move_to,
ln=ln,
rtype=rtype,
confirm=1)
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text="""To cancel""",
button="Cancel",
colID=colID,
ln=ln)
else:
output += """Cannot move the collection '%s' and set it as a subcollection of '%s' since it will create a loop.
""" % (col_dict[tree_from[move_from_id][0]], col_dict[tree_to[move_to_id][0]])
else:
if (move_to_id != 0 and move_col_tree(tree_from[move_from_id], tree_to[move_to_id])) or (move_to_id == 0 and move_col_tree(tree_from[move_from_id], tree_to[move_to_id], move_to_rtype)):
output += """Moved %s collection '%s' to the %s collection '%s'.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (move_to_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
else:
output += """Could not move %s collection '%s' to the %s collection '%s'.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (move_to_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
move_from = ''
move_to = ''
else:
output += """
+ """
+ try:
+ body = [output, extra]
+ except NameError:
+ body = [output]
+
+ return addadminbox(subtitle, body)
+
def perform_addportalbox(colID, ln=cdslang, title='', body='', callback='yes', confirm=-1):
"""form to add a new portalbox
title - the title of the portalbox
body - the body of the portalbox"""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
colID = int(colID)
subtitle = """Create new portalbox"""
text = """
Title Body
""" % (title, body)
output = createhiddenform(action="addportalbox#5.1",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if title and body:
- if confirm in [0, "0"]:
- text ="""Do you want to add the portalbox '%s'.
+ if title and body and confirm in [1, "1"]:
+ res = add_pbx(title, body)
+ if res:
+ output += """Added the portalbox '%s'. To add the portalbox to the collection, go here.""" % (title, colID, ln, res[0][0])
+ else:
+ output += """Cannot add the portalbox '%s'.
""" % title
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addportalbox#5.1" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- title=title,
- body=body,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_pbx(title, body)
- if res:
- output += """Added the portalbox '%s'. To add the portalbox to the collection, go here.""" % (title, colID, ln, res[0][0])
- else:
- output += """Cannot add the portalbox '%s'.
- """ % title
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """All fields must be filled.
"""
try:
body = [output, extra]
except NameError:
body = [output]
return perform_showportalboxes(colID, ln, content=addadminbox(subtitle, body))
def perform_addexistingportalbox(colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=-1):
"""form to add an existing portalbox to a collection.
colID - the collection to add the portalbox to
pbxID - the portalbox to add
score - the importance of the portalbox.
position - the position of the portalbox on the page
sel_ln - the language of the portalbox"""
subtitle = """Add existing portalbox to collection"""
output = ""
colID = int(colID)
res = get_pbx()
pos = get_pbx_pos()
lang = dict(get_languages())
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx(colID)
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if len(res) > 0:
text = """
Portalbox Language Position
"
output += createhiddenform(action="addexistingportalbox#5.2",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
else:
output = """No existing portalboxes to add, please create a new one.
"""
- if pbxID > -1 and position and sel_ln:
+ if pbxID > -1 and position and sel_ln and confirm in [1, "1"]:
pbxID = int(pbxID)
- if confirm in [0, "0"]:
- text = """Do you want to add the portalbox '%s' to the collection '%s'.
+ res = add_col_pbx(colID, pbxID, sel_ln, position, '')
+ if res:
+ output += """Added the portalbox '%s' to the collection '%s'.
""" % (pbx_dict[pbxID], col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingportalbox#5.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- pbxID=pbxID,
- sel_ln=sel_ln,
- score=score,
- position=position,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_col_pbx(colID, pbxID, sel_ln, position, '')
- if res:
- output += """Added the portalbox '%s' to the collection '%s'.
- """ % (pbx_dict[pbxID], col_dict[colID])
- else:
- output += """Cannot add the portalbox '%s' to the collection '%s'.
- """ % (pbx_dict[pbxID], col_dict[colID])
- elif pbxID > -1:
+ else:
+ output += """Cannot add the portalbox '%s' to the collection '%s'.
+ """ % (pbx_dict[pbxID], col_dict[colID])
+ elif pbxID > -1 and confirm not in [-1, "-1"]:
output += """All fields must be filled.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_deleteportalbox(colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1):
"""form to delete a portalbox which is not in use.
colID - the current collection.
pbxID - the id of the portalbox"""
subtitle = """Delete an unused portalbox"""
output = ""
colID = int(colID)
if pbxID not in [-1," -1"] and confirm in [1, "1"]:
ares = get_pbx()
pbx_dict = dict(map(lambda x: (x[0], x[1]), ares))
pname = pbx_dict[int(pbxID)]
ares = delete_pbx(int(pbxID))
res = get_pbx()
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx()
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if len(res) > 0:
text = """
Portalbox """
output += createhiddenform(action="deleteportalbox#5.3",
text=text,
button="Delete",
colID=colID,
ln=ln,
confirm=0)
if pbxID not in [-1,"-1"]:
pbxID = int(pbxID)
if confirm in [0, "0"]:
- text = """Do you want to delete the portalbox '%s'.
+ text = """Are you sure you want to delete the portalbox '%s'.
""" % pbx_dict[pbxID]
output += createhiddenform(action="deleteportalbox#5.3",
text=text,
button="Confirm",
colID=colID,
pbxID=pbxID,
ln=ln,
confirm=1)
elif confirm in [1, "1"]:
if ares:
output += """Deleted the portalbox '%s'.
""" % pname
else:
output += """Cannot delete the portalbox.
"""
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """Choose a portalbox to delete.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_modifyportalbox(colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1):
"""form to modify a portalbox in a collection, or change the portalbox itself.
colID - the id of the collection.
pbxID - the portalbox to change
score - the score of the portalbox connected to colID which should be changed.
position - the position of the portalbox in collection colID to change."""
subtitle = ""
output = ""
colID = int(colID)
res = get_pbx()
pos = get_pbx_pos()
lang = dict(get_languages())
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx(colID)
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if pbxID not in [-1, "-1"]:
pbxID = int(pbxID)
subtitle = """Modify portalbox '%s' for this collection""" % pbx_dict[pbxID]
col_pbx = get_col_pbx(colID)
if not (score and position) and not (body and title):
for (id_pbx, id_collection, tln, score, position, title, body) in col_pbx:
if id_pbx == pbxID:
break
output += """Collection (presentation) specific values (Changes implies only to this collection.) """
text = """
Position """
output += createhiddenform(action="modifyportalbox#5.4",
text=text,
button="Modify",
colID=colID,
pbxID=pbxID,
score=score,
title=title,
body=cgi.escape(body, 1),
sel_ln=sel_ln,
ln=ln,
- confirm=1)
+ confirm=3)
- if pbxID > -1 and score and position:
+ if pbxID > -1 and score and position and confirm in [3, "3"]:
pbxID = int(pbxID)
- if confirm in [1, "1"]:
- text = """Do you want to modify the portalbox '%s' in this collection.
+ res = modify_pbx(colID, pbxID, sel_ln, score, position, '', '')
+ res2 = get_pbx()
+ pbx_dict = dict(map(lambda x: (x[0], x[1]), res2))
+ if res:
+ output += """Modified the presentation of the portalbox '%s' in this collection.
"""
actions.append(["%s" % (i==1 and pos[position] or ''), "%s" % (i==1 and lang[tln] or ''), move, "%s" % title])
+
for col in [(('Modify', 'modifyportalbox'), ('Remove', 'removeportalbox'),)]:
actions[-1].append('%s' % (weburl, col[0][1], colID, ln, pbxID, tln, col[0][0]))
for (str, function) in col[1:]:
actions[-1][-1] += ' / %s' % (weburl, function, colID, ln, pbxID, tln, str)
output += tupletotable(header=header, tuple=actions)
else:
output += """No portalboxes exists for this collection"""
output += content
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_showportalboxes", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_removeportalbox(colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0):
"""form to remove a portalbox from a collection.
colID - the current collection, remove the portalbox from this collection.
sel_ln - remove the portalbox with this language
pbxID - remove the portalbox with this id"""
subtitle = """Remove portalbox"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
res = get_pbx()
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
if colID and pbxID and sel_ln:
colID = int(colID)
pbxID = int(pbxID)
if confirm in ["0", 0]:
text = """Do you want to remove the portalbox '%s' from the collection '%s'.""" % (pbx_dict[pbxID], col_dict[colID])
output += createhiddenform(action="removeportalbox#5.5",
text=text,
button="Confirm",
colID=colID,
pbxID=pbxID,
sel_ln=sel_ln,
confirm=1)
elif confirm in ["1", 1]:
res = remove_pbx(colID, pbxID, sel_ln)
if res:
output += """Removed the portalbox '%s' from the collection '%s'.
""" % (pbx_dict[pbxID], col_dict[colID])
else:
output += """Cannot remove the portalbox from the collection '%s'.
""" % (pbxID, col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_switchfmtscore(colID, type, id_1, id_2, ln=cdslang):
"""Switch the score of id_1 and id_2 in the table type.
colID - the current collection
id_1/id_2 - the id's to change the score for.
type - like "format" """
output = ""
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
if switch_score(colID, id_1, id_2, type):
output = """ '%s' changed position with '%s'
""" % (fmt_dict[int(id_1)], fmt_dict[int(id_2)])
else:
output = """ Could not complete the operation."""
return perform_showoutputformats(colID, ln, content=output)
def perform_switchfldscore(colID, id_1, id_2, fmeth, ln=cdslang):
"""Switch the score of id_1 and id_2 in collection_field_fieldvalue.
colID - the current collection
id_1/id_2 - the id's to change the score for."""
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
if switch_fld_score(colID, id_1, id_2):
output = """ '%s' changed position with '%s'
""" % (fld_dict[int(id_1)], fld_dict[int(id_2)])
else:
output = """ Could not complete the operation."""
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_switchfldvaluescore(colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang):
"""Switch the score of id_1 and id_2 in collection_field_fieldvalue.
colID - the current collection
id_1/id_2 - the id's to change the score for."""
name_1 = run_sql("SELECT name from fieldvalue where id=%s" % id_fldvalue_1)
name_2 = run_sql("SELECT name from fieldvalue where id=%s" % id_fldvalue_2)
if switch_fld_value_score(colID, id_1, id_fldvalue_1, id_fldvalue_2):
output = """ '%s' changed position with '%s'
""" % (name_1[0][0], name_2[0][0])
else:
output = """ Could not complete the operation."""
return perform_showsearchoptions(colID, ln, content=output)
def perform_removefield(colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0):
"""form to remove a field from a collection.
colID - the current collection, remove the field from this collection.
sel_ln - remove the field with this language
fldID - remove the field with this id"""
subtitle = """Remove field"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
res = get_fld_value()
fldv_dict = dict(map(lambda x: (x[0], x[1]), res))
if colID and fldID:
colID = int(colID)
fldID = int(fldID)
if fldvID:
fldvID = int(fldvID)
if confirm in ["0", 0]:
text = """Do you want to remove the field '%s' %s from the collection '%s'.""" % (fld_dict[fldID], (fldvID !="" and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
output += createhiddenform(action="removefield#6.5",
text=text,
button="Confirm",
colID=colID,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
confirm=1)
elif confirm in ["1", 1]:
res = remove_fld(colID, fldID, fldvID)
if res:
output += """Removed the field '%s' %s from the collection '%s'.
""" % (fld_dict[fldID], (fldvID !="" and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
else:
output += """Cannot remove the field from the collection '%s'.
""" % (fldID, col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_addexistingfield(colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1):
"""form to add an existing field to a collection.
colID - the collection to add the field to
fldID - the field to add
score - the importance of the field.
position - the position of the field on the page
sel_ln - the language of the field"""
subtitle = """Add existing field to collection"""
output = ""
if fldID not in [-1, "-1"] and confirm in [1, "1"]:
fldID = int(fldID)
ares = add_col_fld(colID, fldID, fmeth, fldvID)
colID = int(colID)
lang = dict(get_languages())
res = get_current_name('', ln, get_fld_nametypes()[0][0], "field")
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(res)
col_fld = dict(map(lambda x: (x[0], x[1]), get_col_fld(colID, fmeth)))
fld_value = get_fld_value()
fldv_dict = dict(map(lambda x: (x[0], x[1]), fld_value))
if fldvID:
fldvID = int(fldvID)
text = """
Field """
if fmeth == 'seo':
text += """
Fieldvalue """
output += createhiddenform(action="addexistingfield#6.2",
text=text,
button="Add",
colID=colID,
fmeth=fmeth,
ln=ln,
- confirm=0)
+ confirm=1)
- if fldID not in [-1, "-1"]:
+ if fldID not in [-1, "-1"] and confirm in [1, "1"]:
fldID = int(fldID)
- if confirm in [0, "0"]:
- text = """Do you want to add the field '%s' %s to the collection '%s'.
+ if ares:
+ output += """Added the field '%s' %s to the collection '%s'.
""" % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingfield#6.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- fldID=fldID,
- fldvID=fldvID,
- fmeth=fmeth,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- if ares:
- output += """Added the field '%s' %s to the collection '%s'.
- """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- else:
- output += """Cannot add the field '%s' %s to the collection '%s'.
- """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- elif fldID in [-1, "-1"] and confirm in [0, "0"]:
+ else:
+ output += """Cannot add the field '%s' %s to the collection '%s'.
+ """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
+ elif fldID in [-1, "-1"] and confirm not in [-1, "-1"]:
output += """Select a field.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_showsortoptions(colID, ln=cdslang, callback='yes', content='', confirm=-1):
"""show the sort fields of this collection.."""
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
fld_type = get_sort_nametypes()
subtitle = """8. Modify sort options for collection '%s'   [?]""" % (col_dict[colID], weburl)
output = """
"""
+
+
actions.append([move, code, fmt_dict[int(id_format)]])
for col in [(('Remove', 'removeoutputformat'),)]:
actions[-1].append('%s' % (weburl, col[0][1], colID, ln, id_format, col[0][0]))
for (str, function) in col[1:]:
actions[-1][-1] += ' / %s' % (weburl, function, colID, ln, id_format, str)
output += tupletotable(header=header, tuple=actions)
else:
output += """No output formats exists for this collection"""
output += content
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_showoutputformats", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
-def perform_addoutputformat(colID, ln=cdslang, code='', name='', callback='yes', confirm=-1):
- """form to add a new outputformat
- colID - the collection the format should be added to
- code - short code for the format, like xml, html
- name - the default name in the default cdsware language."""
-
- colID = int(colID)
- subtitle = """Create new output format"""
- text = """
- Code
-
- Name
-
- """ % (code, name)
- output = createhiddenform(action="addoutputformat#10.1",
- text=text,
- button="Add",
- colID=colID,
- ln=ln,
- confirm=0)
-
- if code and name:
- if confirm in [0, "0"]:
- text ="""Do you want to add the output format '%s'.
- """ % name
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addoutputformat#10.1" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- code=code,
- name=name,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_fmt(code, name, get_fmt_nametypes()[0][0])
- if res:
- output += """Added the output format '%s'. To add the output format to the collection, go here.
- """ % (name, colID, ln, res[0][0])
- else:
- output += """Cannot add the output format '%s'.
- """ % name
- elif confirm in [0, "0"]:
- output += """All fields must be filled.
- """
-
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- return perform_showoutputformats(colID, ln, content=addadminbox(subtitle, body))
-
def perform_addexistingoutputformat(colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
"""form to add an existing output format to a collection.
colID - the collection the format should be added to
fmtID - the format to add."""
subtitle = """Add existing output format to collection"""
output = ""
if fmtID not in [-1, "-1"] and confirm in [1, "1"]:
ares = add_col_fmt(colID, fmtID)
colID = int(colID)
res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
fmt_dict = dict(res)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
col_fmt = get_col_fmt(colID)
col_fmt = dict(map(lambda x: (x[0], x[2]), col_fmt))
if len(res) > 0:
text = """
Output format
"""
output += createhiddenform(action="addexistingoutputformat#10.2",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
else:
output = """No existing output formats to add, please create a new one.
"""
- if fmtID not in [-1, "-1"]:
+ if fmtID not in [-1, "-1"] and confirm in [1, "1"]:
fmtID = int(fmtID)
- if confirm in [0, "0"]:
- text = """Do you want to add the output format '%s' to the collection '%s'.
+ if ares:
+ output += """Added the output format '%s' to the collection '%s'.
""" % (fmt_dict[fmtID], col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingoutputformat#10.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- fmtID=fmtID,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- if ares:
- output += """Added the output format '%s' to the collection '%s'.
- """ % (fmt_dict[fmtID], col_dict[colID])
- else:
- output += """Cannot add the output format '%s' to the collection '%s'.
- """ % (fmt_dict[fmtID], col_dict[colID])
- elif fmtID in [-1, "-1"] and confirm in [0, "0"]:
+ else:
+ output += """Cannot add the output format '%s' to the collection '%s'.
+ """ % (fmt_dict[fmtID], col_dict[colID])
+ elif fmtID in [-1, "-1"] and confirm not in [-1, "-1"]:
output += """Please select output format.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
def perform_deleteoutputformat(colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
"""form to delete an output format not in use.
colID - the collection id of the current collection.
fmtID - the format id to delete."""
subtitle = """Delete an unused output format"""
output = """
Deleting an output format will also delete the translations associated.
"""
colID = int(colID)
if fmtID not in [-1," -1"] and confirm in [1, "1"]:
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
old_colNAME = fmt_dict[int(fmtID)]
ares = delete_fmt(int(fmtID))
res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
fmt_dict = dict(res)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
col_fmt = get_col_fmt()
col_fmt = dict(map(lambda x: (x[0], x[2]), col_fmt))
if len(res) > 0:
text = """
Output format """
output += createhiddenform(action="deleteoutputformat#10.3",
text=text,
button="Delete",
colID=colID,
ln=ln,
confirm=0)
if fmtID not in [-1,"-1"]:
fmtID = int(fmtID)
if confirm in [0, "0"]:
text = """Do you want to delete the output format '%s'.
""" % fmt_dict[fmtID]
output += createhiddenform(action="deleteoutputformat#10.3",
text=text,
button="Confirm",
colID=colID,
fmtID=fmtID,
ln=ln,
confirm=1)
elif confirm in [1, "1"]:
if ares:
output += """Deleted the output format '%s'.
""" % old_colNAME
else:
output += """Cannot delete the output format.
"""
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """Choose a output format to delete.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
def perform_removeoutputformat(colID, ln=cdslang, fmtID='', callback='yes', confirm=0):
"""form to remove an output format from a collection.
colID - the collection id of the current collection.
fmtID - the format id.
"""
subtitle = """Remove output format"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
if colID and fmtID:
colID = int(colID)
fmtID = int(fmtID)
if confirm in ["0", 0]:
text = """Do you want to remove the output format '%s' from the collection '%s'.""" % (fmt_dict[fmtID], col_dict[colID])
output += createhiddenform(action="removeoutputformat#10.5",
text=text,
button="Confirm",
colID=colID,
fmtID=fmtID,
confirm=1)
elif confirm in ["1", 1]:
res = remove_fmt(colID, fmtID)
if res:
output += """Removed the output format '%s' from the collection '%s'.
""" % (fmt_dict[fmtID], col_dict[colID])
else:
output += """Cannot remove the field from the collection '%s'.
""" % (col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
-
-def perform_modifyoutputformat(colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1):
- """Modify the translations of am output format
- fmtID - format id
- sel_type - nametype to change
- trans - a list of the names in the same order as the languages."""
-
- output = ''
- subtitle = 'Modify translations for output format'
- cdslangs = get_languages()
-
- if confirm in ["2", 2] and fmtID:
- finresult = modify_translations(fmtID, cdslangs, sel_type, trans, "format")
-
- res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
- fmt_dict = dict(res)
-
- text = """
- Output formats
- """
-
- output = createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Select",
- colID=colID,
- ln=ln,
- confirm=0)
-
-
- if fmtID not in [-1, "-1"] and fmt_dict.has_key(int(fmtID)):
- fmtID = int(fmtID)
- subtitle = """Modify translations for output format '%s' """ % fmt_dict[fmtID]
-
- if type(trans) is str:
- trans = [trans]
- if sel_type == '':
- sel_type = get_fmt_nametypes()[0][0]
-
- header = ['Language', 'Translation']
- actions = []
-
- text = """
- Name type
- """
-
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Select",
- colID=colID,
- fmtID=fmtID,
- ln=ln,
- confirm=0)
-
- if confirm in [0, "0"]:
- trans = []
- for key, value in cdslangs:
- try:
- trans_names = get_name(fmtID, key, sel_type, "format")
- trans.append(trans_names[0][0])
- except StandardError, e:
- trans.append('')
-
- for nr in range(0,len(cdslangs)):
- actions.append(["%s %s" % (cdslangs[nr][1], (cdslangs[nr][0]==cdslang and '(def)' or ''))])
- actions[-1].append('' % trans[nr])
-
- text = tupletotable(header=header, tuple=actions)
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Modify",
- colID=colID,
- fmtID=fmtID,
- sel_type=sel_type,
- ln=ln,
- confirm=1)
-
- if sel_type and len(trans):
- if confirm in ["1", 1]:
- text = """Please confirm modification of translations for collection '%s'.""" % (fmt_dict[fmtID])
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Confirm",
- colID=colID,
- fmtID=fmtID,
- sel_type=sel_type,
- trans=trans,
- ln=ln,
-
- confirm=2)
-
- elif confirm in ["2", 2]:
- if finresult:
- output += """Translations modified for output format '%s'.""" % (fmt_dict[fmtID])
- else:
- output += """Sorry, could not modify translations for output format '%s'.""" % (fmt_dict[fmtID])
- elif fmtID in [-1, "-1"] and confirm in ["0", 0]:
- output += """Please chose a output format."""
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- output = " " + addadminbox(subtitle, body)
- return perform_showoutputformats(colID, ln, content=output)
-
+
def perform_index(colID=1, ln=cdslang, mtype='', content='', confirm=0):
"""The index method, calling methods to show the collection tree, create new collections and add collections to tree.
"""
subtitle = "Overview"
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fin_output = ""
output = ""
if mtype == "perform_addcollection":
fin_output += content
else:
fin_output += perform_addcollection(colID=colID, ln=ln, callback='')
fin_output += """
"""
if mtype == "perform_addcollectiontotree":
fin_output += content
else:
fin_output += perform_addcollectiontotree(colID=colID, ln=ln, callback='')
fin_output += """
"""
output = ""
subtitle = "These collections are not in the tree, and should be added"
tree = get_col_tree(colID)
in_tree = {}
for (id, up, down, dad, reltype) in tree:
in_tree[id] = 1
in_tree[dad] = 1
res = run_sql("SELECT id from collection")
if len(res) != len(in_tree):
for id in res:
if not in_tree.has_key(id[0]):
output += """%s ,
""" % (weburl, id[0], ln, col_dict[id[0]])
fin_output += addadminbox(subtitle, [output])
fin_output += """
"""
if mtype == "perform_modifycollectiontree":
fin_output += content
else:
fin_output += perform_modifycollectiontree(colID=colID, ln=ln, callback='')
- fin_output += """
-
- """
+ fin_output += " "
return fin_output
def create_colltree(tree, col_dict, colID, ln, move_from='', move_to='', rtype='', edit=''):
"""Creates the presentation of the collection tree, with the buttons for modifying it.
tree - the tree to present, from get_tree()
col_dict - the name of the collections in a dictionary
colID - the collection id to start with
move_from - if a collection to be moved has been chosen
move_to - the collection which should be set as father of move_from
rtype - the type of the tree, regular or virtual
edit - if the method should output the edit buttons."""
tables = 0
tstack = []
i = 0
text = """
"""
for i in range(0, len(tree)):
id_son = tree[i][0]
up = tree[i][1]
down = tree[i][2]
dad = tree[i][3]
reltype = tree[i][4]
tmove_from = ""
j = i
while j > 0:
j = j - 1
try:
if tstack[j][1] == dad:
table = tstack[j][2]
for k in range(0, tables - table):
tables = tables - 1
text += """
"""
break
except StandardError, e:
pass
text += """
"""
if i > 0 and tree[i][1] == 0:
tables = tables + 1
- text += """
+ text += """
"""
if i == 0:
tstack.append((id_son, dad, 1))
else:
tstack.append((id_son, dad, tables))
-
+
+ text += """
"""
if up == 1 and edit:
- text += """""" % (weburl, colID, ln, i, rtype, weburl)
- elif i != 0:
- text += """
- """ % weburl
-
- text += """
- """
-
+ text += """""" % (weburl, colID, ln, i, rtype, weburl)
+ text += "
"
+
if down == 1 and edit:
- text += """""" % (weburl, colID, ln, i, rtype, weburl)
- elif i != 0:
- text += """
- """ % weburl
- text += """
- """
+ text += """""" % (weburl, colID, ln, i, rtype, weburl)
+ text += "
"
if edit:
if move_from and move_to:
tmove_from = move_from
move_from = ''
if not (move_from == "" and i == 0) and not (move_from != "" and int(move_from[1:len(move_from)]) == i and rtype == move_from[0]):
check = "true"
if move_from:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
tree_from = get_col_tree(colID, move_from_rtype)
tree_to = get_col_tree(colID, rtype)
if tree_from[move_from_id][0] == tree_to[i][0] or not check_col(tree_to[i][0], tree_from[move_from_id][0]):
check = ''
elif not check_col(tree_to[i][0], tree_from[move_from_id][0]):
check = ''
if not check and (tree_to[i][0] == 1 and tree_from[move_from_id][3] == tree_to[i][0] and move_from_rtype != rtype):
check = "true"
if check:
text += """
""" % (weburl, colID, ln, move_from, rtype, i, rtype, weburl, col_dict[tree_from[int(move_from[1:len(move_from)])][0]], col_dict[tree_to[i][0]])
else:
text += """
""" % (weburl, colID, ln, rtype, i, rtype, weburl, col_dict[tree[i][0]])
else:
text += """
""" % weburl
else:
text += """
""" % weburl
text += """
"""
if edit:
text += """
""" % (weburl, colID, ln, i, rtype, weburl)
elif i != 0:
text += """
""" % weburl
text += """
"""
if tmove_from:
move_from = tmove_from
text += """%s%s%s%s%s
""" % ((reltype=="v" and '' or ''), weburl, tree[i][0], ln, col_dict[id_son], (move_to=="%s%s" %(rtype,i) and ' ' % weburl or ''), (move_from=="%s%s" % (rtype,i) and ' ' % weburl or ''), (reltype=="v" and '' or ''))
text += """
"""
while tables > 0:
text += """
"""
tables = tables - 1
text += """
"""
return text
+def perform_deletecollection(colID, ln=cdslang, confirm=-1, callback='yes'):
+ """form to delete a collection
+ colID - id of collection
+ """
+
+ subtitle =''
+ output = """
+
+
+
+
WARNING:
+
When deleting a collection, you also deletes all data related to the collection like translations, relations to other collections and information about which rank methods to use.
+ For more information, please go to the WebSearch guide and read the section regarding deleting a collection.
+
+
+
+ """ % weburl
+
+ col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
+ if colID and col_dict.has_key(int(colID)):
+ colID = int(colID)
+ subtitle = """4. Delete collection '%s'   [?]""" % (col_dict[colID], weburl)
+ res = run_sql("SELECT * from collection_collection WHERE id_dad=%s" % colID)
+ res2 = run_sql("SELECT * from collection_collection WHERE id_son=%s" % colID)
+
+ if not res and not res2:
+ if confirm in ["-1", -1]:
+ text = """Do you want to delete this collection."""
+ output += createhiddenform(action="deletecollection#4",
+ text=text,
+ colID=colID,
+ button="Delete",
+ confirm=0)
+ elif confirm in ["0", 0]:
+ text = """Are you sure you want to delete this collection."""
+ output += createhiddenform(action="deletecollection#4",
+ text=text,
+ colID=colID,
+ button="Confirm",
+ confirm=1)
+ elif confirm in ["1", 1]:
+ result = delete_col(colID)
+ if not result:
+ raise StandardException
+ else:
+ output = """Can not delete a collection that is a part of the collection tree, remove collection from the tree and try again."""
+
+ try:
+ body = [output, extra]
+ except NameError:
+ body = [output]
+
+ if callback:
+ return perform_editcollection(colID, ln, "perform_deletecollection", addadminbox(subtitle, body))
+ else:
+ return addadminbox(subtitle, body)
+
def perform_editcollection(colID=1, ln=cdslang, mtype='', content=''):
"""form to modify a collection. this method is calling other methods which again is calling this and sending back the output of the method.
if callback, the method will call perform_editcollection, if not, it will just return its output.
colID - id of the collection
mtype - the method that called this method.
content - the output from that method."""
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if not col_dict.has_key(colID):
return """Collection deleted.
"""
fin_output = """
""" % (colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln)
if mtype == "perform_modifydbquery" and content:
fin_output += content
elif mtype == "perform_modifydbquery" or not mtype:
fin_output += perform_modifydbquery(colID, ln, callback='')
if mtype == "perform_modifyrestricted" and content:
fin_output += content
elif mtype == "perform_modifyrestricted" or not mtype:
fin_output += perform_modifyrestricted(colID, ln, callback='')
if mtype == "perform_modifytranslations" and content:
fin_output += content
elif mtype == "perform_modifytranslations" or not mtype:
fin_output += perform_modifytranslations(colID, ln, callback='')
if mtype == "perform_deletecollection" and content:
fin_output += content
elif mtype == "perform_deletecollection" or not mtype:
fin_output += perform_deletecollection(colID, ln, callback='')
if mtype == "perform_showportalboxes" and content:
fin_output += content
elif mtype == "perform_showportalboxes" or not mtype:
fin_output += perform_showportalboxes(colID, ln, callback='')
if mtype == "perform_showsearchfields" and content:
fin_output += content
elif mtype == "perform_showsearchfields" or not mtype:
fin_output += perform_showsearchfields(colID, ln, callback='')
if mtype == "perform_showsearchoptions" and content:
fin_output += content
elif mtype == "perform_showsearchoptions" or not mtype:
fin_output += perform_showsearchoptions(colID, ln, callback='')
if mtype == "perform_showsortoptions" and content:
fin_output += content
elif mtype == "perform_showsortoptions" or not mtype:
fin_output += perform_showsortoptions(colID, ln, callback='')
if mtype == "perform_modifyrankmethods" and content:
fin_output += content
elif mtype == "perform_modifyrankmethods" or not mtype:
fin_output += perform_modifyrankmethods(colID, ln, callback='')
if mtype == "perform_showoutputformats" and content:
fin_output += content
elif mtype == "perform_showoutputformats" or not mtype:
fin_output += perform_showoutputformats(colID, ln, callback='')
return addadminbox("Overview of edit options for collection '%s'" % col_dict[colID], [fin_output])
-def perform_deletecollection(colID, ln=cdslang, confirm=-1, callback='yes'):
- """form to delete a collection
- colID - id of collection
- """
-
- subtitle =''
- output = """
-
-
-
-
WARNING:
-
When deleting a collection, you also deletes all data related to the collection like translations, relations to other collections and information about which rank methods to use.
- For more information, please go to the WebSearch guide and read the section regarding deleting a collection.
-
-
-
- """ % weburl
-
- col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- if colID and col_dict.has_key(int(colID)):
- colID = int(colID)
- subtitle = """4. Delete collection '%s'   [?]""" % (col_dict[colID], weburl)
- res = run_sql("SELECT * from collection_collection WHERE id_dad=%s" % colID)
- res2 = run_sql("SELECT * from collection_collection WHERE id_son=%s" % colID)
-
- if not res and not res2:
- if confirm in ["-1", -1]:
- text = """Do you want to delete this collection."""
- output += createhiddenform(action="deletecollection#4",
- text=text,
- colID=colID,
- button="Confirm",
- confirm=0)
- elif confirm in ["0", 0]:
- text = """Are you sure you want to delete this collection."""
- output += createhiddenform(action="deletecollection#4",
- text=text,
- colID=colID,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
- result = delete_col(colID)
- if not result:
- raise StandardException
- else:
- output = """Can not delete a collection that is a part of the collection tree, remove collection from the tree and try again."""
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- if callback:
- return perform_editcollection(colID, ln, "perform_deletecollection", addadminbox(subtitle, body))
- else:
- return addadminbox(subtitle, body)
-
def get_col_tree(colID, rtype=''):
"""Returns a presentation of the tree as a list.
colID - startpoint for the tree
rtype - get regular or virtual part of the tree"""
try:
colID = int(colID)
stack = [colID]
ssize = 0
tree = [(colID, 0, 0, colID, 'r')]
while len(stack) > 0:
ccolID = stack.pop()
if ccolID == colID and rtype:
res = run_sql("SELECT id_son, score, type FROM collection_collection WHERE id_dad=%s AND type='%s' ORDER BY score ASC,id_son" % (ccolID,rtype))
else:
res = run_sql("SELECT id_son, score, type FROM collection_collection WHERE id_dad=%s ORDER BY score ASC,id_son" % ccolID)
ssize += 1
ntree = []
for i in range(0,len(res)):
id_son = res[i][0]
score = res[i][1]
rtype = res[i][2]
stack.append(id_son)
if i == (len(res) - 1):
up = 0
else:
up = 1
if i == 0:
down = 0
else:
down = 1
ntree.insert(0, (id_son, up, down, ccolID, rtype))
tree = tree[0:ssize] + ntree + tree[ssize:len(tree)]
return tree
except StandardError, e:
return ()
def remove_col_subcol(id_son, id_dad, type):
"""Remove a collection as a son of another collection in the tree, if collection isn't used elsewhere in the tree, remove all registered sons of the id_son.
id_son - collection id of son to remove
id_dad - the id of the dad"""
try:
if id_son != id_dad:
tree = get_col_tree(id_son)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (id_son, id_dad))
else:
tree = get_col_tree(id_son, type)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s and type='%s'" % (id_son, id_dad, type))
if not run_sql("SELECT * from collection_collection WHERE id_son=%s and type='%s'" % (id_son, type)):
for (id, up, down, dad, rtype) in tree:
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (id, dad))
return "true"
except StandardError, e:
return ()
def check_col(add_dad, add_son):
"""Check if the collection can be placed as a son of the dad without causing loops.
add_dad - collection id
add_son - collection id"""
try:
stack = [add_dad]
res = run_sql("SELECT id_dad FROM collection_collection WHERE id_dad=%s AND id_son=%s" % (add_dad,add_son))
if res:
raise StandardError
while len(stack) > 0:
colID = stack.pop()
res = run_sql("SELECT id_dad FROM collection_collection WHERE id_son=%s" % colID)
for id in res:
if int(id[0]) == int(add_son):
raise StandardError
else:
stack.append(id[0])
return "true"
except StandardError, e:
return ""
def add_col_dad_son(add_dad, add_son, rtype):
"""Add a son to a collection (dad)
add_dad - add to this collection id
add_son - add this collection id
rtype - either regular or virtual"""
try:
res = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s ORDER BY score ASC" % add_dad)
highscore = 0
for score in res:
if int(score[0]) > highscore:
highscore = int(score[0])
highscore += 1
res = run_sql("INSERT INTO collection_collection(id_dad,id_son,score,type) values(%s,%s,%s,'%s')" % (add_dad, add_son, highscore, rtype))
return highscore
except StandardError, e:
return ()
def switch_col_treescore(col_1, col_2):
try:
res1 = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s and id_son=%s" % (col_1[3], col_1[0]))
res2 = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s and id_son=%s" % (col_2[3], col_2[0]))
res = run_sql("UPDATE collection_collection SET score=%s WHERE id_dad=%s and id_son=%s" % (res2[0][0], col_1[3], col_1[0]))
res = run_sql("UPDATE collection_collection SET score=%s WHERE id_dad=%s and id_son=%s" % (res1[0][0], col_2[3], col_2[0]))
return "true"
except StandardError, e:
return ()
def move_col_tree(col_from, col_to, move_to_rtype=''):
"""Move a collection from one point in the tree to another. becomes a son of the endpoint.
col_from - move this collection from current point
col_to - and set it as a son of this collection.
move_to_rtype - either virtual or regular collection"""
try:
res = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s ORDER BY score asc" % col_to[0])
highscore = 0
for score in res:
if int(score[0]) > highscore:
highscore = int(score[0])
highscore += 1
if not move_to_rtype:
move_to_rtype = col_from[4]
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (col_from[0], col_from[3]))
res = run_sql("INSERT INTO collection_collection(id_dad,id_son,score,type) values(%s,%s,%s,'%s')" % (col_to[0], col_from[0], highscore, move_to_rtype))
return "true"
except StandardError, e:
return ()
def compare_on_val(first, second):
"""Compare the two values"""
return cmp(first[1], second[1])
def get_col_fld(colID=-1, type = '', id_field=''):
"""Returns either all portalboxes associated with a collection, or based on either colID or language or both.
colID - collection id
ln - language id"""
sql = "SELECT id_field,id_fieldvalue,type,score,score_fieldvalue FROM collection_field_fieldvalue, field WHERE id_field=field.id"
try:
if colID > -1:
sql += " AND id_collection=%s" % colID
if id_field:
sql += " AND id_field=%s" % id_field
if type:
sql += " AND type='%s'" % type
sql += " ORDER BY type, score desc, score_fieldvalue desc"
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_col_pbx(colID=-1, ln='', position = ''):
"""Returns either all portalboxes associated with a collection, or based on either colID or language or both.
colID - collection id
ln - language id"""
sql = "SELECT id_portalbox, id_collection, ln, score, position, title, body FROM collection_portalbox, portalbox WHERE id_portalbox = portalbox.id"
try:
if colID > -1:
sql += " AND id_collection=%s" % colID
if ln:
sql += " AND ln='%s'" % ln
if position:
sql += " AND position='%s'" % position
sql += " ORDER BY position, ln, score desc"
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_col_fmt(colID=-1):
"""Returns all formats currently associated with a collection, or for one specific collection
colID - the id of the collection"""
try:
if colID not in [-1, "-1"]:
res = run_sql("SELECT id_format, id_collection, code, score FROM collection_format, format WHERE id_format = format.id AND id_collection=%s ORDER BY score desc" % colID)
else:
res = run_sql("SELECT id_format, id_collection, code, score FROM collection_format, format WHERE id_format = format.id ORDER BY score desc")
return res
except StandardError, e:
return ""
def get_col_rnk(colID, ln=cdslang):
""" Returns a list of the rank methods the given collection is attached to
colID - id from collection"""
try:
res1 = dict(run_sql("SELECT id_rnkMETHOD, '' FROM collection_rnkMETHOD WHERE id_collection=%s" % colID))
res2 = get_current_name('', ln, get_rnk_nametypes()[0][0], "rnkMETHOD")
result = filter(lambda x: res1.has_key(x[0]), res2)
return result
except StandardError, e:
return ()
def get_pbx():
"""Returns all portalboxes"""
try:
res = run_sql("SELECT id, title, body FROM portalbox ORDER by title,body")
return res
except StandardError, e:
return ""
def get_fld_value(fldvID = ''):
"""Returns fieldvalue"""
try:
sql = "SELECT id, name, value FROM fieldvalue"
if fldvID:
sql += " WHERE id=%s" % fldvID
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_pbx_pos():
"""Returns a list of all the positions for a portalbox"""
position = {}
position["rt"] = "Right Top"
position["lt"] = "Left Top"
position["te"] = "Title Epilog"
position["tp"] = "Title Prolog"
position["ne"] = "Narrow by coll epilog"
position["np"] = "Narrow by coll prolog"
return position
def get_sort_nametypes():
"""Return a list of the various translationnames for the fields"""
type = {}
type['soo'] = 'Sort options'
type['seo'] = 'Search options'
type['sew'] = 'Search within'
return type
def get_fmt_nametypes():
"""Return a list of the various translationnames for the output formats"""
type = []
type.append(('ln', 'Long name'))
return type
def get_fld_nametypes():
"""Return a list of the various translationnames for the fields"""
type = []
type.append(('ln', 'Long name'))
return type
def get_col_nametypes():
"""Return a list of the various translationnames for the collections"""
type = []
type.append(('ln', 'Long name'))
return type
def find_last(tree, start_son):
"""Find the previous collection in the tree with the same father as start_son"""
id_dad = tree[start_son][3]
while start_son > 0:
start_son -= 1
if tree[start_son][3] == id_dad:
return start_son
def find_next(tree, start_son):
"""Find the next collection in the tree with the same father as start_son"""
id_dad = tree[start_son][3]
while start_son < len(tree):
start_son += 1
if tree[start_son][3] == id_dad:
return start_son
def attach_rnk_col(colID, rnkID):
"""attach rank method to collection
rnkID - id from rnkMETHOD table
colID - id of collection, as in collection table """
try:
res = run_sql("INSERT INTO collection_rnkMETHOD(id_collection, id_rnkMETHOD) values (%s,%s)" % (colID, rnkID))
return "true"
except StandardError, e:
return ""
def detach_rnk_col(colID, rnkID):
"""detach rank method from collection
rnkID - id from rnkMETHOD table
colID - id of collection, as in collection table """
try:
res = run_sql("DELETE FROM collection_rnkMETHOD WHERE id_collection=%s AND id_rnkMETHOD=%s" % (colID, rnkID))
except StandardError, e:
return ""
return "true"
def remove_pbx(colID, pbxID, ln):
"""Removes a portalbox from the collection given.
colID - the collection the format is connected to
pbxID - the portalbox which should be removed from the collection.
ln - the language of the portalbox to be removed"""
try:
res = run_sql("DELETE FROM collection_portalbox WHERE id_collection=%s AND id_portalbox=%s AND ln='%s'" % (colID, pbxID, ln))
return "true"
except StandardError, e:
return ""
def remove_fmt(colID,fmtID):
"""Removes a format from the collection given.
colID - the collection the format is connected to
fmtID - the format which should be removed from the collection."""
try:
res = run_sql("DELETE FROM collection_format WHERE id_collection=%s AND id_format=%s" % (colID, fmtID))
return "true"
except StandardError, e:
return ""
def remove_fld(colID,fldID, fldvID=''):
"""Removes a field from the collection given.
colID - the collection the format is connected to
fldID - the field which should be removed from the collection."""
try:
sql = "DELETE FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s" % (colID, fldID)
if fldvID:
sql += " AND id_fieldvalue=%s" % fldvID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def delete_pbx(pbxID):
"""Deletes all data for the given portalbox
pbxID - delete all data in the tables associated with portalbox and this id """
try:
res = run_sql("DELETE FROM collection_portalbox WHERE id_portalbox=%s" % pbxID)
res = run_sql("DELETE FROM portalbox WHERE id=%s" % pbxID)
return "true"
except StandardError, e:
return ""
def delete_fmt(fmtID):
"""Deletes all data for the given format
fmtID - delete all data in the tables associated with format and this id """
try:
res = run_sql("DELETE FROM format WHERE id=%s" % fmtID)
res = run_sql("DELETE FROM collection_format WHERE id_format=%s" % fmtID)
res = run_sql("DELETE FROM formatname WHERE id_format=%s" % fmtID)
return "true"
except StandardError, e:
return ""
def delete_col(colID):
"""Deletes all data for the given collection
colID - delete all data in the tables associated with collection and this id """
try:
res = run_sql("DELETE FROM collection WHERE id=%s" % colID)
res = run_sql("DELETE FROM collectionname WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_rnkMETHOD WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_collection WHERE id_dad=%s" % colID)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s" % colID)
res = run_sql("DELETE FROM collection_portalbox WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_format WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_field_fieldvalue WHERE id_collection=%s" % colID)
return "true"
except StandardError, e:
return ""
def add_fmt(code, name, rtype):
"""Add a new output format. Returns the id of the format.
code - the code for the format, max 6 chars.
name - the default name for the default language of the format.
rtype - the default nametype"""
try:
res = run_sql("INSERT INTO format (code, name) values ('%s','%s')" % (MySQLdb.escape_string(code), MySQLdb.escape_string(name)))
fmtID = run_sql("SELECT id FROM format WHERE code='%s'" % MySQLdb.escape_string(code))
res = run_sql("INSERT INTO formatname(id_format, type, ln, value) VALUES (%s,'%s','%s','%s')" % (fmtID[0][0], rtype, cdslang, MySQLdb.escape_string(name)))
return fmtID
except StandardError, e:
return ""
def add_pbx(title, body):
try:
res = run_sql("INSERT INTO portalbox (title, body) values ('%s','%s')" % (MySQLdb.escape_string(title), MySQLdb.escape_string(body)))
res = run_sql("SELECT id FROM portalbox WHERE title='%s' AND body='%s'" % (MySQLdb.escape_string(title), MySQLdb.escape_string(body)))
return res
except StandardError, e:
return ""
def add_col(colNAME, dbquery, rest):
"""Adds a new collection to collection table
colNAME - the default name for the collection, saved to collection and collectionname
dbquery - query related to the collection
rest - name of apache group allowed to access collection"""
try:
rtype = get_col_nametypes()[0][0]
sql = "INSERT INTO collection(name,dbquery,restricted) VALUES('%s'" % MySQLdb.escape_string(colNAME)
if dbquery:
sql += ",'%s'" % MySQLdb.escape_string(dbquery)
else:
sql += ",null"
if rest:
sql += ",'%s'" % MySQLdb.escape_string(rest)
else:
sql += ",null"
sql += ")"
res = run_sql(sql)
colID = run_sql("SELECT id FROM collection WHERE name='%s'" % MySQLdb.escape_string(colNAME))
res = run_sql("INSERT INTO collectionname(id_collection, type, ln, value) VALUES (%s,'%s','%s','%s')" % (colID[0][0], rtype, cdslang, MySQLdb.escape_string(colNAME)))
return colID
except StandardError, e:
return ""
def add_col_pbx(colID, pbxID, ln, position, score=''):
"""add a portalbox to the collection.
colID - the id of the collection involved
pbxID - the portalbox to add
ln - which language the portalbox is for
score - decides which portalbox is the most important
position - position on page the portalbox should appear."""
try:
if score:
res = run_sql("INSERT INTO collection_portalbox(id_portalbox, id_collection, ln, score, position) values (%s,%s,'%s',%s,'%s')" % (pbxID, colID, ln, score, position))
else:
res = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and ln='%s' and position='%s' ORDER BY score desc, ln, position" % (colID, ln, position))
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_portalbox(id_portalbox, id_collection, ln, score, position) values (%s,%s,'%s',%s,'%s')" % (pbxID, colID, ln, (score + 1), position))
return "true"
except StandardError, e:
return ""
def add_col_fmt(colID, fmtID, score=''):
"""Add a output format to the collection.
colID - the id of the collection involved
fmtID - the id of the format.
score - the score of the format, decides sorting, if not given, place the format on top"""
try:
if score:
res = run_sql("INSERT INTO collection_format(id_format, id_collection, score) values (%s,%s,%s)" % (fmtID, colID, score))
else:
res = run_sql("SELECT score FROM collection_format WHERE id_collection=%s ORDER BY score desc" % colID)
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_format(id_format, id_collection, score) values (%s,%s,%s)" % (fmtID, colID, (score + 1)))
return "true"
except StandardError, e:
return ""
def add_col_fld(colID, fldID, type, fldvID=''):
"""Add a sort/search/field to the collection.
colID - the id of the collection involved
fmtID - the id of the format.
score - the score of the format, decides sorting, if not given, place the format on top"""
try:
if fldvID and fldvID not in [-1, "-1"]:
res = run_sql("SELECT score, score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s ORDER BY score desc, score_fieldvalue desc" % (colID, fldID))
if res:
score = int(res[0][0])
v_score = int(res[0][1])
else:
score = 0
v_score = 0
res = run_sql("SELECT * FROM collection_field_fieldvalue where id_field=%s and id_collection=%s and type='%s' and id_fieldvalue=%s" % (fldID, colID, type, fldvID))
if not res:
res = run_sql("INSERT INTO collection_field_fieldvalue(id_field, id_fieldvalue, id_collection, type, score, score_fieldvalue) values (%s,%s,%s,'%s',%s,%s)" % (fldID, fldvID, colID, type, score, (v_score + 1)))
else:
raise StandardError
else:
res = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s ORDER BY score desc" % (colID, fldID))
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_field_fieldvalue(id_field, id_collection, type, score) values (%s,%s,'%s',%s)" % (fldID, colID, type, (score + 1)))
return "true"
except StandardError, e:
return ""
def modify_restricted(colID, rest):
"""Modify the dwhich apache group is allowed to use the collection.
colID - the id of the collection involved
restricted - the new group"""
try:
sql = "UPDATE collection SET restricted="
if rest:
sql += "'%s'" % MySQLdb.escape_string(rest)
else:
sql += "null"
sql += " WHERE id=%s" % colID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def modify_dbquery(colID, dbquery):
"""Modify the dbquery of an collection.
colID - the id of the collection involved
dbquery - the new dbquery"""
try:
sql = "UPDATE collection SET dbquery="
if dbquery:
sql += "'%s'" % MySQLdb.escape_string(dbquery)
else:
sql += "null"
sql += " WHERE id=%s" % colID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def modify_pbx(colID, pbxID, sel_ln, score='', position='', title='', body=''):
"""Modify a portalbox
colID - the id of the collection involved
pbxID - the id of the portalbox that should be modified
sel_ln - the language of the portalbox that should be modified
title - the title
body - the content
score - if several portalboxes in one position, who should appear on top.
position - position on page"""
try:
if title:
res = run_sql("UPDATE portalbox SET title='%s' WHERE id=%s" % (MySQLdb.escape_string(title), pbxID))
if body:
res = run_sql("UPDATE portalbox SET body='%s' WHERE id=%s" % (MySQLdb.escape_string(body), pbxID))
if score:
res = run_sql("UPDATE collection_portalbox SET score='%s' WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (score, colID, pbxID, sel_ln))
if position:
res = run_sql("UPDATE collection_portalbox SET position='%s' WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (position, colID, pbxID, sel_ln))
return "true"
except StandardError, e:
return ""
def switch_fld_score(colID, id_1, id_2):
"""Switch the scores of id_1 and id_2 in collection_field_fieldvalue
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s" % (colID, id_1))
res2 = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s" % (colID, id_2))
res = run_sql("UPDATE collection_field_fieldvalue SET score=%s WHERE id_collection=%s and id_field=%s" % (res2[0][0], colID, id_1))
res = run_sql("UPDATE collection_field_fieldvalue SET score=%s WHERE id_collection=%s and id_field=%s" % (res1[0][0], colID, id_2))
return "true"
except StandardError, e:
return ()
def switch_fld_value_score(colID, id_1, fldvID_1, fldvID_2):
"""Switch the scores of two field_value
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (colID, id_1, fldvID_1))
res2 = run_sql("SELECT score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (colID, id_1, fldvID_2))
res = run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=%s WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (res2[0][0], colID, id_1, fldvID_1))
res = run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=%s WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (res1[0][0], colID, id_1, fldvID_2))
return "true"
except StandardError, e:
return ()
def switch_pbx_score(colID, id_1, id_2, sel_ln):
"""Switch the scores of id_1 and id_2 in the table given by the argument.
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (colID, id_1, sel_ln))
res2 = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (colID, id_2, sel_ln))
res = run_sql("UPDATE collection_portalbox SET score=%s WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (res2[0][0], colID, id_1, sel_ln))
res = run_sql("UPDATE collection_portalbox SET score=%s WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (res1[0][0], colID, id_2, sel_ln))
return "true"
except StandardError, e:
return ()
def switch_score(colID, id_1, id_2, table):
"""Switch the scores of id_1 and id_2 in the table given by the argument.
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_%s WHERE id_collection=%s and id_%s=%s" % (table, colID, table, id_1))
res2 = run_sql("SELECT score FROM collection_%s WHERE id_collection=%s and id_%s=%s" % (table, colID, table, id_2))
res = run_sql("UPDATE collection_%s SET score=%s WHERE id_collection=%s and id_%s=%s" % (table, res2[0][0], colID, table, id_1))
res = run_sql("UPDATE collection_%s SET score=%s WHERE id_collection=%s and id_%s=%s" % (table, res1[0][0], colID, table, id_2))
return "true"
except StandardError, e:
return ()
diff --git a/modules/websearch/lib/websearchadminlib.py.wml b/modules/websearch/lib/websearchadminlib.py.wml
index f0c57105a..66dfad41c 100644
--- a/modules/websearch/lib/websearchadminlib.py.wml
+++ b/modules/websearch/lib/websearchadminlib.py.wml
@@ -1,2942 +1,2637 @@
## Administrator interface for WebSearch
## 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"
#include "cdswmllib.wml"
## $Id$## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
"""CDSware WebSearch Administrator Interface."""
__lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>"""
## fill config variables:
import access_control_engine as acce
import cgi
import re
import MySQLdb
import Numeric
import os
import urllib
+import random
from zlib import compress,decompress
from bibrankadminlib import modify_translations, get_current_name,get_name,get_rnk_nametypes,get_languages,check_user,is_adminuser,adderrorbox,addadminbox,tupletotable,tupletotable_onlyselected,addcheckboxes,createhiddenform,serialize_via_numeric_array_dumps,serialize_via_numeric_array_compr,serialize_via_numeric_array_escape,serialize_via_numeric_array,deserialize_via_numeric_array,serialize_via_marshal,deserialize_via_marshal
from messages import *
from dbquery import run_sql
from config import *
from webpage import page, pageheaderonly, pagefooteronly
from webuser import getUid, get_email
from mod_python import apache
__version__ = "$Id$"
def getnavtrail(previous = ''):
"""Get the navtrail"""
navtrail = """Admin Area > WebSearch Admin """ % (weburl, weburl)
navtrail = navtrail + previous
return navtrail
def perform_modifytranslations(colID, ln=cdslang, sel_type='', trans=[], confirm=-1, callback='yes'):
"""Modify the translations of a collection
sel_type - the nametype to modify
trans - the translations in the same order as the languages from get_languages()"""
output = ''
subtitle = ''
cdslangs = get_languages()
if confirm in ["2", 2] and colID:
finresult = modify_translations(colID, cdslangs, sel_type, trans, "collection")
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """3. Modify translations for collection '%s'   [?]""" % (col_dict[colID], weburl)
if type(trans) is str:
trans = [trans]
if sel_type == '':
sel_type = get_col_nametypes()[0][0]
header = ['Language', 'Translation']
actions = []
types = get_col_nametypes()
if len(types) > 1:
text = """
Name type
"""
output += createhiddenform(action="modifytranslations#3",
text=text,
button="Select",
colID=colID,
ln=ln,
confirm=0)
if confirm in [-1, "-1", 0, "0"]:
trans = []
for (key, value) in cdslangs:
try:
trans_names = get_name(colID, key, sel_type, "collection")
trans.append(trans_names[0][0])
except StandardError, e:
trans.append('')
for nr in range(0,len(cdslangs)):
actions.append(["%s %s" % (cdslangs[nr][1], (cdslangs[nr][0]==cdslang and '(def)' or ''))])
actions[-1].append('' % trans[nr])
text = tupletotable(header=header, tuple=actions)
output += createhiddenform(action="modifytranslations#3",
text=text,
button="Modify",
colID=colID,
sel_type=sel_type,
ln=ln,
- confirm=1)
-
- if sel_type and len(trans):
- if confirm in ["1", 1]:
- text = """Please confirm modification of translations for collection '%s'.""" % (col_dict[colID])
- output += createhiddenform(action="modifytranslations#3",
- text=text,
- button="Confirm",
- colID=colID,
- sel_type=sel_type,
- trans=trans,
- ln=ln,
- confirm=2)
+ confirm=2)
- elif confirm in ["2", 2]:
- if finresult:
- output += """Translations modified for collection '%s'.""" % (col_dict[colID])
- else:
- output += """Sorry, could not modify translations for collection '%s'.""" % (col_dict[colID])
+ if sel_type and len(trans) and confirm in ["2", 2]:
+ if finresult:
+ output += """Translations modified for collection '%s'.""" % (col_dict[colID])
+ else:
+ output += """Sorry, could not modify translations for collection '%s'.""" % (col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifytranslations", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifyrankmethods(colID, ln=cdslang, func='', rnkID='', confirm=0, callback='yes'):
"""Modify which rank methods is visible to the collection
func - remove or add rank method
rnkID - the id of the rank method."""
output = ""
subtitle = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
rnk_dict = dict(get_current_name('',ln, get_rnk_nametypes()[0][0], "rnkMETHOD"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
if func in ["0", 0] and confirm in ["1", 1]:
finresult = attach_rnk_col(colID, rnkID)
elif func in ["1", 1] and confirm in ["1", 1]:
finresult = detach_rnk_col(colID, rnkID)
subtitle = """9. Modify rank options for collection '%s'   [?]""" % (col_dict[colID], weburl)
output = """
The rank methods enabled for the collection '%s' is:
"""
if not rnkmethods:
output += """No rank methods"""
else:
for id, name in rnkmethods:
output += """%s, """ % name
output += """
"""
rnk_list = get_current_name('',ln, get_rnk_nametypes()[0][0], "rnkMETHOD")
rnk_dict_in_col = dict(get_col_rnk(colID, ln))
rnk_list = filter(lambda x: not rnk_dict_in_col.has_key(x[0]), rnk_list)
if rnk_list:
text = """
Enable:
"""
output += createhiddenform(action="modifyrankmethods#9",
text=text,
button="Enable",
colID=colID,
ln=ln,
func=0,
- confirm=0)
-
- if confirm in ["0", 0] and func in ["0", 0] and int(rnkID) != -1:
- text = "Please confirm to enable rank method '%s' for the collection '%s'" % (dict(rnk_list)[int(rnkID)], col_dict[colID])
- output += createhiddenform(action="modifyrankmethods#9",
- text=text,
- button="Confirm",
- colID=colID,
- ln=ln,
- rnkID=rnkID,
- func=0,
confirm=1)
-
- elif confirm in ["1", 1] and func in ["0", 0] and len(rnkID) > 0:
+
+ if confirm in ["1", 1] and func in ["0", 0] and int(rnkID) != -1:
if finresult:
output += """Rank method '%s' enabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
else:
output += """Rank method '%s' could not be enabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
-
+ elif confirm not in ["0", 0] and func in ["0", 0]:
+ output += """Please select a rank method."""
+
coll_list = get_col_rnk(colID, ln)
if coll_list:
text = """
Disable:
"""
output += createhiddenform(action="modifyrankmethods#9",
text=text,
button="Disable",
colID=colID,
ln=ln,
func=1,
- confirm=0)
-
- if confirm in ["0", 0] and func in ["1", 1] and int(rnkID) != -1:
- text = "Please confirm to disable rank method '%s' for collection '%s'" % (rnk_dict[int(rnkID)], col_dict[colID])
- output += createhiddenform(action="modifyrankmethods#9",
- text=text,
- button="Confirm",
- colID=colID,
- ln=ln,
- rnkID=rnkID,
- func=1,
confirm=1)
- elif confirm in ["1", 1] and func in ["1", 1]:
+
+ if confirm in ["1", 1] and func in ["1", 1] and int(rnkID) != -1:
if finresult:
output += """Rank method '%s' disabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
else:
output += """Rank method '%s' could not be disabled for collection '%s'""" % (rnk_dict[int(rnkID)], col_dict[colID])
+ elif confirm not in ["0", 0] and func in ["1", 1]:
+ output += """Please select a rank method."""
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifyrankmethods", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_addcollectiontotree(colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1):
"""Form to add a collection to the tree.
add_dad - the dad to add the collection to
add_son - the collection to add
rtype - add it as a regular or virtual
mtype - add it to the regular or virtual tree."""
output = ""
output2 = ""
subtitle = """Attach collection to tree   [?]""" % (weburl)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- if confirm in [0, "0"] and not (add_son and add_dad and rtype):
+ if confirm not in [-1, "-1"] and not (add_son and add_dad and rtype):
output2 += """All fields must be filled.
"""
elif add_son and add_dad and rtype:
add_son = int(add_son)
add_dad = int(add_dad)
- if confirm in [0, "0"]:
+ if confirm not in [-1, "-1"]:
if add_son == add_dad:
output2 += """Cannot add a collection as a pointer to itself.
"""
elif check_col(add_dad, add_son):
- text = """Do you want to add the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- output2 += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollectiontotree" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- add_son=add_son,
- add_dad=add_dad,
- ln=ln,
- rtype=rtype,
- confirm=1)
+ if add_col_dad_son(add_dad, add_son, rtype):
+ output2 += """Added the collection '%s' as a %s subcollection of '%s'.
+ """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
+ else:
+ output2 += """Could not add the collection '%s' as a %s subcollection of '%s'.
+ """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
else:
output2 += """Cannot add the collection '%s' as a %s subcollection of '%s' since it will either create a loop, or the association already exists.
""" % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- else:
- if add_col_dad_son(add_dad, add_son, rtype):
- output2 += """Added the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
- else:
- output2 += """Could not add the collection '%s' as a %s subcollection of '%s'.
- """ % (col_dict[add_son], (rtype=="r" and 'regular' or 'virtual'), col_dict[add_dad])
add_son = ''
add_dad = ''
rtype = ''
tree = get_col_tree(colID)
col_list = col_dict.items()
col_list.sort(compare_on_val)
text = """
Attach which Attach to
"""
text += """
Relationship
""" % ((rtype=="r" and 'selected="selected"' or ''), (rtype=="v" and 'selected="selected"' or ''))
output = createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollectiontotree" % weburl,
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
output += output2
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_index(colID, ln, mtype="perform_addcollectiontotree", content=addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_addcollection(colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1):
"""form to add a new collection.
colNAME - the name of the new collection
dbquery - the dbquery of the new collection
rest - the group allowed to access the new collection"""
output = ""
subtitle = """Create new collection [?]""" % (weburl)
text = """
Collection name
""" % colNAME
output = createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollection" % weburl,
text=text,
colID=colID,
ln=ln,
button="Add collection",
- confirm=0)
- if colNAME:
- if confirm in ["0", 0]:
- text = """Add collection with default name: '%s'.
- """ % (colNAME)
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addcollection" % weburl,
- text=text,
- colID=colID,
- colNAME=colNAME,
- dbquery=dbquery,
- rest=rest,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
- res = add_col(colNAME, '', '')
- if res:
- output += """Added new collection with default name '%s'
- """ % colNAME
- else:
- output += """Sorry, could not add collection, most likely the collection already exists.
- """
- elif confirm in ["0", 0]:
+ confirm=1)
+ if colNAME and confirm in ["1", 1]:
+ res = add_col(colNAME, '', '')
+ if res:
+ output += """Added new collection with default name '%s'
+ """ % colNAME
+ else:
+ output += """Sorry, could not add collection, most likely the collection already exists.
+ """
+ elif confirm not in ["-1", -1]:
output += """Please give the collection a name.
"""
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_index(colID, ln=ln, mtype="perform_addcollection", content=addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifydbquery(colID, ln=cdslang, dbquery='', callback='yes', confirm=-1):
"""form to modify the dbquery of the collection.
dbquery - the dbquery of the collection."""
subtitle = ''
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """1. Modify collection query for collection '%s'   [?]""" % (col_dict[colID], weburl)
if confirm == -1:
res = run_sql("SELECT dbquery FROM collection WHERE id=%s" % colID)
dbquery = res[0][0]
if not dbquery:
dbquery = ''
reg_sons = len(get_col_tree(colID, 'r'))
vir_sons = len(get_col_tree(colID, 'v'))
if reg_sons > 1 or vir_sons > 1:
if dbquery:
output += "Warning: This collection got subcollections, and should because of this not have a collection query, for further explanation, check the WebSearch Guide "
elif reg_sons <= 1 and vir_sons <= 1:
if not dbquery:
output += "Warning: This collection does not have any subcollections, and should because of this have a collection query, for further explanation, check the WebSearch Guide "
text = """
Query
""" % dbquery
output += createhiddenform(action="modifydbquery",
text=text,
button="Modify",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if confirm in ["0", 0]:
- if dbquery:
- text = """Change query for this collection to: '%s'.""" % dbquery
- else:
- text = """Remove query for this collection."""
- output += createhiddenform(action="modifydbquery",
- text=text,
- colID=colID,
- dbquery=dbquery,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
+ if confirm in ["1", 1]:
res = modify_dbquery(colID, dbquery)
if res:
text = """Changed query."""
else:
text = """Sorry, could not change query."""
output += text
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifydbquery", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifyrestricted(colID, ln=cdslang, rest='', callback='yes', confirm=-1):
"""modify which apache group is allowed to access the collection.
rest - the groupname"""
subtitle = ''
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if colID and col_dict.has_key(int(colID)):
colID = int(colID)
subtitle = """2. Modify access restrictions for collection '%s'   [?]""" % (col_dict[colID], weburl)
if confirm == -1:
res = run_sql("SELECT restricted FROM collection WHERE id=%s" % colID)
rest = res[0][0]
if not rest:
rest = ''
text = """
Restricted to:
""" % rest
output += createhiddenform(action="modifyrestricted",
text=text,
button="Modify",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if confirm in ["0", 0]:
- if rest:
- text = """Change access restrictions for this collection to: '%s'.""" % rest
- else:
- text = """Remove any access restrictions for this collection."""
-
- output += createhiddenform(action="modifyrestricted",
- colID=colID,
- text=text,
- rest=rest,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
+ if confirm in ["1", 1]:
res = modify_restricted(colID, rest)
if res:
text = """Changed the access restrictions."""
else:
text = """Sorry, could not change the access restrictions."""
output += text
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_modifyrestricted", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_modifycollectiontree(colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0):
"""to modify the collection tree: move a collection up and down, delete a collection, or change the father of the collection.
colID - the main collection of the tree, the root
move_up - move this collection up (is not the collection id, but the place in the tree)
move_up - move this collection down (is not the collection id, but the place in the tree)
move_from - move this collection from the current positon (is not the collection id, but the place in the tree)
move_to - move the move_from collection and set this as it's father. (is not the collection id, but the place in the tree)
delete - delete this collection from the tree (is not the collection id, but the place in the tree)
rtype - the type of the collection in the tree, regular or virtual"""
colID = int(colID)
tree = get_col_tree(colID, rtype)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- subtitle = """Modify collection tree: %s [?]""" % (col_dict[colID], weburl)
+ subtitle = """Modify collection tree: %s [?] Printer friendly version""" % (col_dict[colID], weburl, weburl, colID, ln)
fin_output = ""
output = ""
try:
if move_up:
move_up = int(move_up)
switch = find_last(tree, move_up)
if switch and switch_col_treescore(tree[move_up], tree[switch]):
output += """Moved the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]], col_dict[tree[switch][0]])
else:
output += """Could not move the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]], col_dict[tree[switch][0]])
elif move_down:
move_down = int(move_down)
switch = find_next(tree, move_down)
if switch and switch_col_treescore(tree[move_down], tree[switch]):
output += """Moved the %s collection '%s' down and '%s' up.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_down][0]], col_dict[tree[switch][0]])
else:
output += """Could not move the %s collection '%s' up and '%s' down.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_up][0]],col_dict[tree[switch][0]])
elif delete:
delete = int(delete)
if confirm in [0, "0"]:
if col_dict[tree[delete][0]] != col_dict[tree[delete][3]]:
text = """Do you want to remove the %s collection '%s' and its subcollections in the %s collection '%s'.
""" % ((tree[delete][4]=="r" and 'regular' or 'virtual'), col_dict[tree[delete][0]], (rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
else:
text = """Do you want to remove all subcollections of the %s collection '%s'.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/modifycollectiontree#tree" % weburl,
text=text,
button="Confirm",
colID=colID,
delete=delete,
rtype=rtype,
ln=ln,
confirm=1)
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text="To cancel",
button="Cancel",
colID=colID,
ln=ln)
else:
if remove_col_subcol(tree[delete][0], tree[delete][3], rtype):
if col_dict[tree[delete][0]] != col_dict[tree[delete][3]]:
output += """Removed the %s collection '%s' and its subcollections in subdirectory '%s'.
""" % ((tree[delete][4]=="r" and 'regular' or 'virtual'), col_dict[tree[delete][0]], col_dict[tree[delete][3]])
else:
output += """Removed the subcollections of the %s collection '%s'.
""" % ((rtype=="r" and 'regular' or 'virtual'), col_dict[tree[delete][3]])
else:
output += """Could not remove the collection from the tree.
"""
delete = ''
elif move_from and not move_to:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
text = """Select collection to place the %s collection '%s' under.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree[move_from_id][0]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text=text,
button="Cancel",
colID=colID,
ln=ln)
elif move_from and move_to:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
move_to_rtype = move_to[0]
move_to_id = int(move_to[1:len(move_to)])
tree_from = get_col_tree(colID, move_from_rtype)
tree_to = get_col_tree(colID, move_to_rtype)
if confirm in [0, '0']:
if move_from_id == move_to_id and move_from_rtype==move_to_rtype:
output += """Cannot move to itself.
"""
elif tree_from[move_from_id][3] == tree_to[move_to_id][0] and move_from_rtype==move_to_rtype:
output += """The collection is already there.
"""
elif check_col(tree_to[move_to_id][0], tree_from[move_from_id][0]) or (tree_to[move_to_id][0] == 1 and tree_from[move_from_id][3] == tree_to[move_to_id][0] and move_from_rtype != move_to_rtype):
text = """Move %s collection '%s' to the %s collection '%s'.
""" % ((tree_from[move_from_id][4]=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (tree_to[move_to_id][4]=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/modifycollectiontree#tree" % weburl,
text=text,
button="Confirm",
colID=colID,
move_from=move_from,
move_to=move_to,
ln=ln,
rtype=rtype,
confirm=1)
output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/index#tree" % weburl,
text="""To cancel""",
button="Cancel",
colID=colID,
ln=ln)
else:
output += """Cannot move the collection '%s' and set it as a subcollection of '%s' since it will create a loop.
""" % (col_dict[tree_from[move_from_id][0]], col_dict[tree_to[move_to_id][0]])
else:
if (move_to_id != 0 and move_col_tree(tree_from[move_from_id], tree_to[move_to_id])) or (move_to_id == 0 and move_col_tree(tree_from[move_from_id], tree_to[move_to_id], move_to_rtype)):
output += """Moved %s collection '%s' to the %s collection '%s'.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (move_to_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
else:
output += """Could not move %s collection '%s' to the %s collection '%s'.
""" % ((move_from_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_from[move_from_id][0]], (move_to_rtype=="r" and 'regular' or 'virtual'), col_dict[tree_to[move_to_id][0]])
move_from = ''
move_to = ''
else:
output += """
+ """
+ try:
+ body = [output, extra]
+ except NameError:
+ body = [output]
+
+ return addadminbox(subtitle, body)
+
def perform_addportalbox(colID, ln=cdslang, title='', body='', callback='yes', confirm=-1):
"""form to add a new portalbox
title - the title of the portalbox
body - the body of the portalbox"""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
colID = int(colID)
subtitle = """Create new portalbox"""
text = """
Title Body
""" % (title, body)
output = createhiddenform(action="addportalbox#5.1",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
- if title and body:
- if confirm in [0, "0"]:
- text ="""Do you want to add the portalbox '%s'.
+ if title and body and confirm in [1, "1"]:
+ res = add_pbx(title, body)
+ if res:
+ output += """Added the portalbox '%s'. To add the portalbox to the collection, go here.""" % (title, colID, ln, res[0][0])
+ else:
+ output += """Cannot add the portalbox '%s'.
""" % title
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addportalbox#5.1" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- title=title,
- body=body,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_pbx(title, body)
- if res:
- output += """Added the portalbox '%s'. To add the portalbox to the collection, go here.""" % (title, colID, ln, res[0][0])
- else:
- output += """Cannot add the portalbox '%s'.
- """ % title
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """All fields must be filled.
"""
try:
body = [output, extra]
except NameError:
body = [output]
return perform_showportalboxes(colID, ln, content=addadminbox(subtitle, body))
def perform_addexistingportalbox(colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=-1):
"""form to add an existing portalbox to a collection.
colID - the collection to add the portalbox to
pbxID - the portalbox to add
score - the importance of the portalbox.
position - the position of the portalbox on the page
sel_ln - the language of the portalbox"""
subtitle = """Add existing portalbox to collection"""
output = ""
colID = int(colID)
res = get_pbx()
pos = get_pbx_pos()
lang = dict(get_languages())
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx(colID)
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if len(res) > 0:
text = """
Portalbox Language Position
"
output += createhiddenform(action="addexistingportalbox#5.2",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
else:
output = """No existing portalboxes to add, please create a new one.
"""
- if pbxID > -1 and position and sel_ln:
+ if pbxID > -1 and position and sel_ln and confirm in [1, "1"]:
pbxID = int(pbxID)
- if confirm in [0, "0"]:
- text = """Do you want to add the portalbox '%s' to the collection '%s'.
+ res = add_col_pbx(colID, pbxID, sel_ln, position, '')
+ if res:
+ output += """Added the portalbox '%s' to the collection '%s'.
""" % (pbx_dict[pbxID], col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingportalbox#5.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- pbxID=pbxID,
- sel_ln=sel_ln,
- score=score,
- position=position,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_col_pbx(colID, pbxID, sel_ln, position, '')
- if res:
- output += """Added the portalbox '%s' to the collection '%s'.
- """ % (pbx_dict[pbxID], col_dict[colID])
- else:
- output += """Cannot add the portalbox '%s' to the collection '%s'.
- """ % (pbx_dict[pbxID], col_dict[colID])
- elif pbxID > -1:
+ else:
+ output += """Cannot add the portalbox '%s' to the collection '%s'.
+ """ % (pbx_dict[pbxID], col_dict[colID])
+ elif pbxID > -1 and confirm not in [-1, "-1"]:
output += """All fields must be filled.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_deleteportalbox(colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1):
"""form to delete a portalbox which is not in use.
colID - the current collection.
pbxID - the id of the portalbox"""
subtitle = """Delete an unused portalbox"""
output = ""
colID = int(colID)
if pbxID not in [-1," -1"] and confirm in [1, "1"]:
ares = get_pbx()
pbx_dict = dict(map(lambda x: (x[0], x[1]), ares))
pname = pbx_dict[int(pbxID)]
ares = delete_pbx(int(pbxID))
res = get_pbx()
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx()
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if len(res) > 0:
text = """
Portalbox """
output += createhiddenform(action="deleteportalbox#5.3",
text=text,
button="Delete",
colID=colID,
ln=ln,
confirm=0)
if pbxID not in [-1,"-1"]:
pbxID = int(pbxID)
if confirm in [0, "0"]:
- text = """Do you want to delete the portalbox '%s'.
+ text = """Are you sure you want to delete the portalbox '%s'.
""" % pbx_dict[pbxID]
output += createhiddenform(action="deleteportalbox#5.3",
text=text,
button="Confirm",
colID=colID,
pbxID=pbxID,
ln=ln,
confirm=1)
elif confirm in [1, "1"]:
if ares:
output += """Deleted the portalbox '%s'.
""" % pname
else:
output += """Cannot delete the portalbox.
"""
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """Choose a portalbox to delete.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_modifyportalbox(colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1):
"""form to modify a portalbox in a collection, or change the portalbox itself.
colID - the id of the collection.
pbxID - the portalbox to change
score - the score of the portalbox connected to colID which should be changed.
position - the position of the portalbox in collection colID to change."""
subtitle = ""
output = ""
colID = int(colID)
res = get_pbx()
pos = get_pbx_pos()
lang = dict(get_languages())
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
col_pbx = get_col_pbx(colID)
col_pbx = dict(map(lambda x: (x[0], x[5]), col_pbx))
if pbxID not in [-1, "-1"]:
pbxID = int(pbxID)
subtitle = """Modify portalbox '%s' for this collection""" % pbx_dict[pbxID]
col_pbx = get_col_pbx(colID)
if not (score and position) and not (body and title):
for (id_pbx, id_collection, tln, score, position, title, body) in col_pbx:
if id_pbx == pbxID:
break
output += """Collection (presentation) specific values (Changes implies only to this collection.) """
text = """
Position """
output += createhiddenform(action="modifyportalbox#5.4",
text=text,
button="Modify",
colID=colID,
pbxID=pbxID,
score=score,
title=title,
body=cgi.escape(body, 1),
sel_ln=sel_ln,
ln=ln,
- confirm=1)
+ confirm=3)
- if pbxID > -1 and score and position:
+ if pbxID > -1 and score and position and confirm in [3, "3"]:
pbxID = int(pbxID)
- if confirm in [1, "1"]:
- text = """Do you want to modify the portalbox '%s' in this collection.
+ res = modify_pbx(colID, pbxID, sel_ln, score, position, '', '')
+ res2 = get_pbx()
+ pbx_dict = dict(map(lambda x: (x[0], x[1]), res2))
+ if res:
+ output += """Modified the presentation of the portalbox '%s' in this collection.
"""
actions.append(["%s" % (i==1 and pos[position] or ''), "%s" % (i==1 and lang[tln] or ''), move, "%s" % title])
+
for col in [(('Modify', 'modifyportalbox'), ('Remove', 'removeportalbox'),)]:
actions[-1].append('%s' % (weburl, col[0][1], colID, ln, pbxID, tln, col[0][0]))
for (str, function) in col[1:]:
actions[-1][-1] += ' / %s' % (weburl, function, colID, ln, pbxID, tln, str)
output += tupletotable(header=header, tuple=actions)
else:
output += """No portalboxes exists for this collection"""
output += content
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_showportalboxes", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
def perform_removeportalbox(colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0):
"""form to remove a portalbox from a collection.
colID - the current collection, remove the portalbox from this collection.
sel_ln - remove the portalbox with this language
pbxID - remove the portalbox with this id"""
subtitle = """Remove portalbox"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
res = get_pbx()
pbx_dict = dict(map(lambda x: (x[0], x[1]), res))
if colID and pbxID and sel_ln:
colID = int(colID)
pbxID = int(pbxID)
if confirm in ["0", 0]:
text = """Do you want to remove the portalbox '%s' from the collection '%s'.""" % (pbx_dict[pbxID], col_dict[colID])
output += createhiddenform(action="removeportalbox#5.5",
text=text,
button="Confirm",
colID=colID,
pbxID=pbxID,
sel_ln=sel_ln,
confirm=1)
elif confirm in ["1", 1]:
res = remove_pbx(colID, pbxID, sel_ln)
if res:
output += """Removed the portalbox '%s' from the collection '%s'.
""" % (pbx_dict[pbxID], col_dict[colID])
else:
output += """Cannot remove the portalbox from the collection '%s'.
""" % (pbxID, col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showportalboxes(colID, ln, content=output)
def perform_switchfmtscore(colID, type, id_1, id_2, ln=cdslang):
"""Switch the score of id_1 and id_2 in the table type.
colID - the current collection
id_1/id_2 - the id's to change the score for.
type - like "format" """
output = ""
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
if switch_score(colID, id_1, id_2, type):
output = """ '%s' changed position with '%s'
""" % (fmt_dict[int(id_1)], fmt_dict[int(id_2)])
else:
output = """ Could not complete the operation."""
return perform_showoutputformats(colID, ln, content=output)
def perform_switchfldscore(colID, id_1, id_2, fmeth, ln=cdslang):
"""Switch the score of id_1 and id_2 in collection_field_fieldvalue.
colID - the current collection
id_1/id_2 - the id's to change the score for."""
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
if switch_fld_score(colID, id_1, id_2):
output = """ '%s' changed position with '%s'
""" % (fld_dict[int(id_1)], fld_dict[int(id_2)])
else:
output = """ Could not complete the operation."""
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_switchfldvaluescore(colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang):
"""Switch the score of id_1 and id_2 in collection_field_fieldvalue.
colID - the current collection
id_1/id_2 - the id's to change the score for."""
name_1 = run_sql("SELECT name from fieldvalue where id=%s" % id_fldvalue_1)
name_2 = run_sql("SELECT name from fieldvalue where id=%s" % id_fldvalue_2)
if switch_fld_value_score(colID, id_1, id_fldvalue_1, id_fldvalue_2):
output = """ '%s' changed position with '%s'
""" % (name_1[0][0], name_2[0][0])
else:
output = """ Could not complete the operation."""
return perform_showsearchoptions(colID, ln, content=output)
def perform_removefield(colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0):
"""form to remove a field from a collection.
colID - the current collection, remove the field from this collection.
sel_ln - remove the field with this language
fldID - remove the field with this id"""
subtitle = """Remove field"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
res = get_fld_value()
fldv_dict = dict(map(lambda x: (x[0], x[1]), res))
if colID and fldID:
colID = int(colID)
fldID = int(fldID)
if fldvID:
fldvID = int(fldvID)
if confirm in ["0", 0]:
text = """Do you want to remove the field '%s' %s from the collection '%s'.""" % (fld_dict[fldID], (fldvID !="" and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
output += createhiddenform(action="removefield#6.5",
text=text,
button="Confirm",
colID=colID,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
confirm=1)
elif confirm in ["1", 1]:
res = remove_fld(colID, fldID, fldvID)
if res:
output += """Removed the field '%s' %s from the collection '%s'.
""" % (fld_dict[fldID], (fldvID !="" and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
else:
output += """Cannot remove the field from the collection '%s'.
""" % (fldID, col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_addexistingfield(colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1):
"""form to add an existing field to a collection.
colID - the collection to add the field to
fldID - the field to add
score - the importance of the field.
position - the position of the field on the page
sel_ln - the language of the field"""
subtitle = """Add existing field to collection"""
output = ""
if fldID not in [-1, "-1"] and confirm in [1, "1"]:
fldID = int(fldID)
ares = add_col_fld(colID, fldID, fmeth, fldvID)
colID = int(colID)
lang = dict(get_languages())
res = get_current_name('', ln, get_fld_nametypes()[0][0], "field")
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(res)
col_fld = dict(map(lambda x: (x[0], x[1]), get_col_fld(colID, fmeth)))
fld_value = get_fld_value()
fldv_dict = dict(map(lambda x: (x[0], x[1]), fld_value))
if fldvID:
fldvID = int(fldvID)
text = """
Field """
if fmeth == 'seo':
text += """
Fieldvalue """
output += createhiddenform(action="addexistingfield#6.2",
text=text,
button="Add",
colID=colID,
fmeth=fmeth,
ln=ln,
- confirm=0)
+ confirm=1)
- if fldID not in [-1, "-1"]:
+ if fldID not in [-1, "-1"] and confirm in [1, "1"]:
fldID = int(fldID)
- if confirm in [0, "0"]:
- text = """Do you want to add the field '%s' %s to the collection '%s'.
+ if ares:
+ output += """Added the field '%s' %s to the collection '%s'.
""" % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingfield#6.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- fldID=fldID,
- fldvID=fldvID,
- fmeth=fmeth,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- if ares:
- output += """Added the field '%s' %s to the collection '%s'.
- """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- else:
- output += """Cannot add the field '%s' %s to the collection '%s'.
- """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
- elif fldID in [-1, "-1"] and confirm in [0, "0"]:
+ else:
+ output += """Cannot add the field '%s' %s to the collection '%s'.
+ """ % (fld_dict[fldID], (fldvID != -1 and "with fieldvalue '%s'" % fldv_dict[fldvID] or ''), col_dict[colID])
+ elif fldID in [-1, "-1"] and confirm not in [-1, "-1"]:
output += """Select a field.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
if fmeth == "soo":
return perform_showsortoptions(colID, ln, content=output)
elif fmeth == "sew":
return perform_showsearchfields(colID, ln, content=output)
elif fmeth == "seo":
return perform_showsearchoptions(colID, ln, content=output)
def perform_showsortoptions(colID, ln=cdslang, callback='yes', content='', confirm=-1):
"""show the sort fields of this collection.."""
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fld_dict = dict(get_current_name('', ln, get_fld_nametypes()[0][0], "field"))
fld_type = get_sort_nametypes()
subtitle = """8. Modify sort options for collection '%s'   [?]""" % (col_dict[colID], weburl)
output = """
"""
+
+
actions.append([move, code, fmt_dict[int(id_format)]])
for col in [(('Remove', 'removeoutputformat'),)]:
actions[-1].append('%s' % (weburl, col[0][1], colID, ln, id_format, col[0][0]))
for (str, function) in col[1:]:
actions[-1][-1] += ' / %s' % (weburl, function, colID, ln, id_format, str)
output += tupletotable(header=header, tuple=actions)
else:
output += """No output formats exists for this collection"""
output += content
try:
body = [output, extra]
except NameError:
body = [output]
if callback:
return perform_editcollection(colID, ln, "perform_showoutputformats", addadminbox(subtitle, body))
else:
return addadminbox(subtitle, body)
-def perform_addoutputformat(colID, ln=cdslang, code='', name='', callback='yes', confirm=-1):
- """form to add a new outputformat
- colID - the collection the format should be added to
- code - short code for the format, like xml, html
- name - the default name in the default cdsware language."""
-
- colID = int(colID)
- subtitle = """Create new output format"""
- text = """
- Code
-
- Name
-
- """ % (code, name)
- output = createhiddenform(action="addoutputformat#10.1",
- text=text,
- button="Add",
- colID=colID,
- ln=ln,
- confirm=0)
-
- if code and name:
- if confirm in [0, "0"]:
- text ="""Do you want to add the output format '%s'.
- """ % name
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addoutputformat#10.1" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- code=code,
- name=name,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- res = add_fmt(code, name, get_fmt_nametypes()[0][0])
- if res:
- output += """Added the output format '%s'. To add the output format to the collection, go here.
- """ % (name, colID, ln, res[0][0])
- else:
- output += """Cannot add the output format '%s'.
- """ % name
- elif confirm in [0, "0"]:
- output += """All fields must be filled.
- """
-
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- return perform_showoutputformats(colID, ln, content=addadminbox(subtitle, body))
-
def perform_addexistingoutputformat(colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
"""form to add an existing output format to a collection.
colID - the collection the format should be added to
fmtID - the format to add."""
subtitle = """Add existing output format to collection"""
output = ""
if fmtID not in [-1, "-1"] and confirm in [1, "1"]:
ares = add_col_fmt(colID, fmtID)
colID = int(colID)
res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
fmt_dict = dict(res)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
col_fmt = get_col_fmt(colID)
col_fmt = dict(map(lambda x: (x[0], x[2]), col_fmt))
if len(res) > 0:
text = """
Output format
"""
output += createhiddenform(action="addexistingoutputformat#10.2",
text=text,
button="Add",
colID=colID,
ln=ln,
- confirm=0)
+ confirm=1)
else:
output = """No existing output formats to add, please create a new one.
"""
- if fmtID not in [-1, "-1"]:
+ if fmtID not in [-1, "-1"] and confirm in [1, "1"]:
fmtID = int(fmtID)
- if confirm in [0, "0"]:
- text = """Do you want to add the output format '%s' to the collection '%s'.
+ if ares:
+ output += """Added the output format '%s' to the collection '%s'.
""" % (fmt_dict[fmtID], col_dict[colID])
- output += createhiddenform(action="%s/admin/websearch/websearchadmin.py/addexistingoutputformat#10.2" % weburl,
- text=text,
- button="Confirm",
- colID=colID,
- fmtID=fmtID,
- ln=ln,
- confirm=1)
- elif confirm in [1, "1"]:
- if ares:
- output += """Added the output format '%s' to the collection '%s'.
- """ % (fmt_dict[fmtID], col_dict[colID])
- else:
- output += """Cannot add the output format '%s' to the collection '%s'.
- """ % (fmt_dict[fmtID], col_dict[colID])
- elif fmtID in [-1, "-1"] and confirm in [0, "0"]:
+ else:
+ output += """Cannot add the output format '%s' to the collection '%s'.
+ """ % (fmt_dict[fmtID], col_dict[colID])
+ elif fmtID in [-1, "-1"] and confirm not in [-1, "-1"]:
output += """Please select output format.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
def perform_deleteoutputformat(colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
"""form to delete an output format not in use.
colID - the collection id of the current collection.
fmtID - the format id to delete."""
subtitle = """Delete an unused output format"""
output = """
Deleting an output format will also delete the translations associated.
"""
colID = int(colID)
if fmtID not in [-1," -1"] and confirm in [1, "1"]:
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
old_colNAME = fmt_dict[int(fmtID)]
ares = delete_fmt(int(fmtID))
res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
fmt_dict = dict(res)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
col_fmt = get_col_fmt()
col_fmt = dict(map(lambda x: (x[0], x[2]), col_fmt))
if len(res) > 0:
text = """
Output format """
output += createhiddenform(action="deleteoutputformat#10.3",
text=text,
button="Delete",
colID=colID,
ln=ln,
confirm=0)
if fmtID not in [-1,"-1"]:
fmtID = int(fmtID)
if confirm in [0, "0"]:
text = """Do you want to delete the output format '%s'.
""" % fmt_dict[fmtID]
output += createhiddenform(action="deleteoutputformat#10.3",
text=text,
button="Confirm",
colID=colID,
fmtID=fmtID,
ln=ln,
confirm=1)
elif confirm in [1, "1"]:
if ares:
output += """Deleted the output format '%s'.
""" % old_colNAME
else:
output += """Cannot delete the output format.
"""
- elif confirm in [0, "0"]:
+ elif confirm not in [-1, "-1"]:
output += """Choose a output format to delete.
"""
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
def perform_removeoutputformat(colID, ln=cdslang, fmtID='', callback='yes', confirm=0):
"""form to remove an output format from a collection.
colID - the collection id of the current collection.
fmtID - the format id.
"""
subtitle = """Remove output format"""
output = ""
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fmt_dict = dict(get_current_name('', ln, get_fmt_nametypes()[0][0], "format"))
if colID and fmtID:
colID = int(colID)
fmtID = int(fmtID)
if confirm in ["0", 0]:
text = """Do you want to remove the output format '%s' from the collection '%s'.""" % (fmt_dict[fmtID], col_dict[colID])
output += createhiddenform(action="removeoutputformat#10.5",
text=text,
button="Confirm",
colID=colID,
fmtID=fmtID,
confirm=1)
elif confirm in ["1", 1]:
res = remove_fmt(colID, fmtID)
if res:
output += """Removed the output format '%s' from the collection '%s'.
""" % (fmt_dict[fmtID], col_dict[colID])
else:
output += """Cannot remove the field from the collection '%s'.
""" % (col_dict[colID])
try:
body = [output, extra]
except NameError:
body = [output]
output = " " + addadminbox(subtitle, body)
return perform_showoutputformats(colID, ln, content=output)
-
-def perform_modifyoutputformat(colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1):
- """Modify the translations of am output format
- fmtID - format id
- sel_type - nametype to change
- trans - a list of the names in the same order as the languages."""
-
- output = ''
- subtitle = 'Modify translations for output format'
- cdslangs = get_languages()
-
- if confirm in ["2", 2] and fmtID:
- finresult = modify_translations(fmtID, cdslangs, sel_type, trans, "format")
-
- res = get_current_name('', ln, get_fmt_nametypes()[0][0], "format")
- fmt_dict = dict(res)
-
- text = """
- Output formats
- """
-
- output = createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Select",
- colID=colID,
- ln=ln,
- confirm=0)
-
-
- if fmtID not in [-1, "-1"] and fmt_dict.has_key(int(fmtID)):
- fmtID = int(fmtID)
- subtitle = """Modify translations for output format '%s' """ % fmt_dict[fmtID]
-
- if type(trans) is str:
- trans = [trans]
- if sel_type == '':
- sel_type = get_fmt_nametypes()[0][0]
-
- header = ['Language', 'Translation']
- actions = []
-
- text = """
- Name type
- """
-
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Select",
- colID=colID,
- fmtID=fmtID,
- ln=ln,
- confirm=0)
-
- if confirm in [0, "0"]:
- trans = []
- for key, value in cdslangs:
- try:
- trans_names = get_name(fmtID, key, sel_type, "format")
- trans.append(trans_names[0][0])
- except StandardError, e:
- trans.append('')
-
- for nr in range(0,len(cdslangs)):
- actions.append(["%s %s" % (cdslangs[nr][1], (cdslangs[nr][0]==cdslang and '(def)' or ''))])
- actions[-1].append('' % trans[nr])
-
- text = tupletotable(header=header, tuple=actions)
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Modify",
- colID=colID,
- fmtID=fmtID,
- sel_type=sel_type,
- ln=ln,
- confirm=1)
-
- if sel_type and len(trans):
- if confirm in ["1", 1]:
- text = """Please confirm modification of translations for collection '%s'.""" % (fmt_dict[fmtID])
- output += createhiddenform(action="modifyoutputformat#10.4",
- text=text,
- button="Confirm",
- colID=colID,
- fmtID=fmtID,
- sel_type=sel_type,
- trans=trans,
- ln=ln,
-
- confirm=2)
-
- elif confirm in ["2", 2]:
- if finresult:
- output += """Translations modified for output format '%s'.""" % (fmt_dict[fmtID])
- else:
- output += """Sorry, could not modify translations for output format '%s'.""" % (fmt_dict[fmtID])
- elif fmtID in [-1, "-1"] and confirm in ["0", 0]:
- output += """Please chose a output format."""
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- output = " " + addadminbox(subtitle, body)
- return perform_showoutputformats(colID, ln, content=output)
-
+
def perform_index(colID=1, ln=cdslang, mtype='', content='', confirm=0):
"""The index method, calling methods to show the collection tree, create new collections and add collections to tree.
"""
subtitle = "Overview"
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
fin_output = ""
output = ""
if mtype == "perform_addcollection":
fin_output += content
else:
fin_output += perform_addcollection(colID=colID, ln=ln, callback='')
fin_output += """
"""
if mtype == "perform_addcollectiontotree":
fin_output += content
else:
fin_output += perform_addcollectiontotree(colID=colID, ln=ln, callback='')
fin_output += """
"""
output = ""
subtitle = "These collections are not in the tree, and should be added"
tree = get_col_tree(colID)
in_tree = {}
for (id, up, down, dad, reltype) in tree:
in_tree[id] = 1
in_tree[dad] = 1
res = run_sql("SELECT id from collection")
if len(res) != len(in_tree):
for id in res:
if not in_tree.has_key(id[0]):
output += """%s ,
""" % (weburl, id[0], ln, col_dict[id[0]])
fin_output += addadminbox(subtitle, [output])
fin_output += """
"""
if mtype == "perform_modifycollectiontree":
fin_output += content
else:
fin_output += perform_modifycollectiontree(colID=colID, ln=ln, callback='')
- fin_output += """
-
- """
+ fin_output += " "
return fin_output
def create_colltree(tree, col_dict, colID, ln, move_from='', move_to='', rtype='', edit=''):
"""Creates the presentation of the collection tree, with the buttons for modifying it.
tree - the tree to present, from get_tree()
col_dict - the name of the collections in a dictionary
colID - the collection id to start with
move_from - if a collection to be moved has been chosen
move_to - the collection which should be set as father of move_from
rtype - the type of the tree, regular or virtual
edit - if the method should output the edit buttons."""
tables = 0
tstack = []
i = 0
text = """
"""
for i in range(0, len(tree)):
id_son = tree[i][0]
up = tree[i][1]
down = tree[i][2]
dad = tree[i][3]
reltype = tree[i][4]
tmove_from = ""
j = i
while j > 0:
j = j - 1
try:
if tstack[j][1] == dad:
table = tstack[j][2]
for k in range(0, tables - table):
tables = tables - 1
text += """
"""
break
except StandardError, e:
pass
text += """
"""
if i > 0 and tree[i][1] == 0:
tables = tables + 1
- text += """
+ text += """
"""
if i == 0:
tstack.append((id_son, dad, 1))
else:
tstack.append((id_son, dad, tables))
-
+
+ text += """
"""
if up == 1 and edit:
- text += """""" % (weburl, colID, ln, i, rtype, weburl)
- elif i != 0:
- text += """
- """ % weburl
-
- text += """
- """
-
+ text += """""" % (weburl, colID, ln, i, rtype, weburl)
+ text += "
"
+
if down == 1 and edit:
- text += """""" % (weburl, colID, ln, i, rtype, weburl)
- elif i != 0:
- text += """
- """ % weburl
- text += """
- """
+ text += """""" % (weburl, colID, ln, i, rtype, weburl)
+ text += "
"
if edit:
if move_from and move_to:
tmove_from = move_from
move_from = ''
if not (move_from == "" and i == 0) and not (move_from != "" and int(move_from[1:len(move_from)]) == i and rtype == move_from[0]):
check = "true"
if move_from:
move_from_rtype = move_from[0]
move_from_id = int(move_from[1:len(move_from)])
tree_from = get_col_tree(colID, move_from_rtype)
tree_to = get_col_tree(colID, rtype)
if tree_from[move_from_id][0] == tree_to[i][0] or not check_col(tree_to[i][0], tree_from[move_from_id][0]):
check = ''
elif not check_col(tree_to[i][0], tree_from[move_from_id][0]):
check = ''
if not check and (tree_to[i][0] == 1 and tree_from[move_from_id][3] == tree_to[i][0] and move_from_rtype != rtype):
check = "true"
if check:
text += """
""" % (weburl, colID, ln, move_from, rtype, i, rtype, weburl, col_dict[tree_from[int(move_from[1:len(move_from)])][0]], col_dict[tree_to[i][0]])
else:
text += """
""" % (weburl, colID, ln, rtype, i, rtype, weburl, col_dict[tree[i][0]])
else:
text += """
""" % weburl
else:
text += """
""" % weburl
text += """
"""
if edit:
text += """
""" % (weburl, colID, ln, i, rtype, weburl)
elif i != 0:
text += """
""" % weburl
text += """
"""
if tmove_from:
move_from = tmove_from
text += """%s%s%s%s%s
""" % ((reltype=="v" and '' or ''), weburl, tree[i][0], ln, col_dict[id_son], (move_to=="%s%s" %(rtype,i) and ' ' % weburl or ''), (move_from=="%s%s" % (rtype,i) and ' ' % weburl or ''), (reltype=="v" and '' or ''))
text += """
"""
while tables > 0:
text += """
"""
tables = tables - 1
text += """
"""
return text
+def perform_deletecollection(colID, ln=cdslang, confirm=-1, callback='yes'):
+ """form to delete a collection
+ colID - id of collection
+ """
+
+ subtitle =''
+ output = """
+
+
+
+
WARNING:
+
When deleting a collection, you also deletes all data related to the collection like translations, relations to other collections and information about which rank methods to use.
+ For more information, please go to the WebSearch guide and read the section regarding deleting a collection.
+
+
+
+ """ % weburl
+
+ col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
+ if colID and col_dict.has_key(int(colID)):
+ colID = int(colID)
+ subtitle = """4. Delete collection '%s'   [?]""" % (col_dict[colID], weburl)
+ res = run_sql("SELECT * from collection_collection WHERE id_dad=%s" % colID)
+ res2 = run_sql("SELECT * from collection_collection WHERE id_son=%s" % colID)
+
+ if not res and not res2:
+ if confirm in ["-1", -1]:
+ text = """Do you want to delete this collection."""
+ output += createhiddenform(action="deletecollection#4",
+ text=text,
+ colID=colID,
+ button="Delete",
+ confirm=0)
+ elif confirm in ["0", 0]:
+ text = """Are you sure you want to delete this collection."""
+ output += createhiddenform(action="deletecollection#4",
+ text=text,
+ colID=colID,
+ button="Confirm",
+ confirm=1)
+ elif confirm in ["1", 1]:
+ result = delete_col(colID)
+ if not result:
+ raise StandardException
+ else:
+ output = """Can not delete a collection that is a part of the collection tree, remove collection from the tree and try again."""
+
+ try:
+ body = [output, extra]
+ except NameError:
+ body = [output]
+
+ if callback:
+ return perform_editcollection(colID, ln, "perform_deletecollection", addadminbox(subtitle, body))
+ else:
+ return addadminbox(subtitle, body)
+
def perform_editcollection(colID=1, ln=cdslang, mtype='', content=''):
"""form to modify a collection. this method is calling other methods which again is calling this and sending back the output of the method.
if callback, the method will call perform_editcollection, if not, it will just return its output.
colID - id of the collection
mtype - the method that called this method.
content - the output from that method."""
colID = int(colID)
col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
if not col_dict.has_key(colID):
return """Collection deleted.
"""
fin_output = """
""" % (colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln, colID, ln)
if mtype == "perform_modifydbquery" and content:
fin_output += content
elif mtype == "perform_modifydbquery" or not mtype:
fin_output += perform_modifydbquery(colID, ln, callback='')
if mtype == "perform_modifyrestricted" and content:
fin_output += content
elif mtype == "perform_modifyrestricted" or not mtype:
fin_output += perform_modifyrestricted(colID, ln, callback='')
if mtype == "perform_modifytranslations" and content:
fin_output += content
elif mtype == "perform_modifytranslations" or not mtype:
fin_output += perform_modifytranslations(colID, ln, callback='')
if mtype == "perform_deletecollection" and content:
fin_output += content
elif mtype == "perform_deletecollection" or not mtype:
fin_output += perform_deletecollection(colID, ln, callback='')
if mtype == "perform_showportalboxes" and content:
fin_output += content
elif mtype == "perform_showportalboxes" or not mtype:
fin_output += perform_showportalboxes(colID, ln, callback='')
if mtype == "perform_showsearchfields" and content:
fin_output += content
elif mtype == "perform_showsearchfields" or not mtype:
fin_output += perform_showsearchfields(colID, ln, callback='')
if mtype == "perform_showsearchoptions" and content:
fin_output += content
elif mtype == "perform_showsearchoptions" or not mtype:
fin_output += perform_showsearchoptions(colID, ln, callback='')
if mtype == "perform_showsortoptions" and content:
fin_output += content
elif mtype == "perform_showsortoptions" or not mtype:
fin_output += perform_showsortoptions(colID, ln, callback='')
if mtype == "perform_modifyrankmethods" and content:
fin_output += content
elif mtype == "perform_modifyrankmethods" or not mtype:
fin_output += perform_modifyrankmethods(colID, ln, callback='')
if mtype == "perform_showoutputformats" and content:
fin_output += content
elif mtype == "perform_showoutputformats" or not mtype:
fin_output += perform_showoutputformats(colID, ln, callback='')
return addadminbox("Overview of edit options for collection '%s'" % col_dict[colID], [fin_output])
-def perform_deletecollection(colID, ln=cdslang, confirm=-1, callback='yes'):
- """form to delete a collection
- colID - id of collection
- """
-
- subtitle =''
- output = """
-
-
-
-
WARNING:
-
When deleting a collection, you also deletes all data related to the collection like translations, relations to other collections and information about which rank methods to use.
- For more information, please go to the WebSearch guide and read the section regarding deleting a collection.
-
-
-
- """ % weburl
-
- col_dict = dict(get_current_name('', ln, get_col_nametypes()[0][0], "collection"))
- if colID and col_dict.has_key(int(colID)):
- colID = int(colID)
- subtitle = """4. Delete collection '%s'   [?]""" % (col_dict[colID], weburl)
- res = run_sql("SELECT * from collection_collection WHERE id_dad=%s" % colID)
- res2 = run_sql("SELECT * from collection_collection WHERE id_son=%s" % colID)
-
- if not res and not res2:
- if confirm in ["-1", -1]:
- text = """Do you want to delete this collection."""
- output += createhiddenform(action="deletecollection#4",
- text=text,
- colID=colID,
- button="Confirm",
- confirm=0)
- elif confirm in ["0", 0]:
- text = """Are you sure you want to delete this collection."""
- output += createhiddenform(action="deletecollection#4",
- text=text,
- colID=colID,
- button="Confirm",
- confirm=1)
- elif confirm in ["1", 1]:
- result = delete_col(colID)
- if not result:
- raise StandardException
- else:
- output = """Can not delete a collection that is a part of the collection tree, remove collection from the tree and try again."""
-
- try:
- body = [output, extra]
- except NameError:
- body = [output]
-
- if callback:
- return perform_editcollection(colID, ln, "perform_deletecollection", addadminbox(subtitle, body))
- else:
- return addadminbox(subtitle, body)
-
def get_col_tree(colID, rtype=''):
"""Returns a presentation of the tree as a list.
colID - startpoint for the tree
rtype - get regular or virtual part of the tree"""
try:
colID = int(colID)
stack = [colID]
ssize = 0
tree = [(colID, 0, 0, colID, 'r')]
while len(stack) > 0:
ccolID = stack.pop()
if ccolID == colID and rtype:
res = run_sql("SELECT id_son, score, type FROM collection_collection WHERE id_dad=%s AND type='%s' ORDER BY score ASC,id_son" % (ccolID,rtype))
else:
res = run_sql("SELECT id_son, score, type FROM collection_collection WHERE id_dad=%s ORDER BY score ASC,id_son" % ccolID)
ssize += 1
ntree = []
for i in range(0,len(res)):
id_son = res[i][0]
score = res[i][1]
rtype = res[i][2]
stack.append(id_son)
if i == (len(res) - 1):
up = 0
else:
up = 1
if i == 0:
down = 0
else:
down = 1
ntree.insert(0, (id_son, up, down, ccolID, rtype))
tree = tree[0:ssize] + ntree + tree[ssize:len(tree)]
return tree
except StandardError, e:
return ()
def remove_col_subcol(id_son, id_dad, type):
"""Remove a collection as a son of another collection in the tree, if collection isn't used elsewhere in the tree, remove all registered sons of the id_son.
id_son - collection id of son to remove
id_dad - the id of the dad"""
try:
if id_son != id_dad:
tree = get_col_tree(id_son)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (id_son, id_dad))
else:
tree = get_col_tree(id_son, type)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s and type='%s'" % (id_son, id_dad, type))
if not run_sql("SELECT * from collection_collection WHERE id_son=%s and type='%s'" % (id_son, type)):
for (id, up, down, dad, rtype) in tree:
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (id, dad))
return "true"
except StandardError, e:
return ()
def check_col(add_dad, add_son):
"""Check if the collection can be placed as a son of the dad without causing loops.
add_dad - collection id
add_son - collection id"""
try:
stack = [add_dad]
res = run_sql("SELECT id_dad FROM collection_collection WHERE id_dad=%s AND id_son=%s" % (add_dad,add_son))
if res:
raise StandardError
while len(stack) > 0:
colID = stack.pop()
res = run_sql("SELECT id_dad FROM collection_collection WHERE id_son=%s" % colID)
for id in res:
if int(id[0]) == int(add_son):
raise StandardError
else:
stack.append(id[0])
return "true"
except StandardError, e:
return ""
def add_col_dad_son(add_dad, add_son, rtype):
"""Add a son to a collection (dad)
add_dad - add to this collection id
add_son - add this collection id
rtype - either regular or virtual"""
try:
res = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s ORDER BY score ASC" % add_dad)
highscore = 0
for score in res:
if int(score[0]) > highscore:
highscore = int(score[0])
highscore += 1
res = run_sql("INSERT INTO collection_collection(id_dad,id_son,score,type) values(%s,%s,%s,'%s')" % (add_dad, add_son, highscore, rtype))
return highscore
except StandardError, e:
return ()
def switch_col_treescore(col_1, col_2):
try:
res1 = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s and id_son=%s" % (col_1[3], col_1[0]))
res2 = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s and id_son=%s" % (col_2[3], col_2[0]))
res = run_sql("UPDATE collection_collection SET score=%s WHERE id_dad=%s and id_son=%s" % (res2[0][0], col_1[3], col_1[0]))
res = run_sql("UPDATE collection_collection SET score=%s WHERE id_dad=%s and id_son=%s" % (res1[0][0], col_2[3], col_2[0]))
return "true"
except StandardError, e:
return ()
def move_col_tree(col_from, col_to, move_to_rtype=''):
"""Move a collection from one point in the tree to another. becomes a son of the endpoint.
col_from - move this collection from current point
col_to - and set it as a son of this collection.
move_to_rtype - either virtual or regular collection"""
try:
res = run_sql("SELECT score FROM collection_collection WHERE id_dad=%s ORDER BY score asc" % col_to[0])
highscore = 0
for score in res:
if int(score[0]) > highscore:
highscore = int(score[0])
highscore += 1
if not move_to_rtype:
move_to_rtype = col_from[4]
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s" % (col_from[0], col_from[3]))
res = run_sql("INSERT INTO collection_collection(id_dad,id_son,score,type) values(%s,%s,%s,'%s')" % (col_to[0], col_from[0], highscore, move_to_rtype))
return "true"
except StandardError, e:
return ()
def compare_on_val(first, second):
"""Compare the two values"""
return cmp(first[1], second[1])
def get_col_fld(colID=-1, type = '', id_field=''):
"""Returns either all portalboxes associated with a collection, or based on either colID or language or both.
colID - collection id
ln - language id"""
sql = "SELECT id_field,id_fieldvalue,type,score,score_fieldvalue FROM collection_field_fieldvalue, field WHERE id_field=field.id"
try:
if colID > -1:
sql += " AND id_collection=%s" % colID
if id_field:
sql += " AND id_field=%s" % id_field
if type:
sql += " AND type='%s'" % type
sql += " ORDER BY type, score desc, score_fieldvalue desc"
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_col_pbx(colID=-1, ln='', position = ''):
"""Returns either all portalboxes associated with a collection, or based on either colID or language or both.
colID - collection id
ln - language id"""
sql = "SELECT id_portalbox, id_collection, ln, score, position, title, body FROM collection_portalbox, portalbox WHERE id_portalbox = portalbox.id"
try:
if colID > -1:
sql += " AND id_collection=%s" % colID
if ln:
sql += " AND ln='%s'" % ln
if position:
sql += " AND position='%s'" % position
sql += " ORDER BY position, ln, score desc"
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_col_fmt(colID=-1):
"""Returns all formats currently associated with a collection, or for one specific collection
colID - the id of the collection"""
try:
if colID not in [-1, "-1"]:
res = run_sql("SELECT id_format, id_collection, code, score FROM collection_format, format WHERE id_format = format.id AND id_collection=%s ORDER BY score desc" % colID)
else:
res = run_sql("SELECT id_format, id_collection, code, score FROM collection_format, format WHERE id_format = format.id ORDER BY score desc")
return res
except StandardError, e:
return ""
def get_col_rnk(colID, ln=cdslang):
""" Returns a list of the rank methods the given collection is attached to
colID - id from collection"""
try:
res1 = dict(run_sql("SELECT id_rnkMETHOD, '' FROM collection_rnkMETHOD WHERE id_collection=%s" % colID))
res2 = get_current_name('', ln, get_rnk_nametypes()[0][0], "rnkMETHOD")
result = filter(lambda x: res1.has_key(x[0]), res2)
return result
except StandardError, e:
return ()
def get_pbx():
"""Returns all portalboxes"""
try:
res = run_sql("SELECT id, title, body FROM portalbox ORDER by title,body")
return res
except StandardError, e:
return ""
def get_fld_value(fldvID = ''):
"""Returns fieldvalue"""
try:
sql = "SELECT id, name, value FROM fieldvalue"
if fldvID:
sql += " WHERE id=%s" % fldvID
res = run_sql(sql)
return res
except StandardError, e:
return ""
def get_pbx_pos():
"""Returns a list of all the positions for a portalbox"""
position = {}
position["rt"] = "Right Top"
position["lt"] = "Left Top"
position["te"] = "Title Epilog"
position["tp"] = "Title Prolog"
position["ne"] = "Narrow by coll epilog"
position["np"] = "Narrow by coll prolog"
return position
def get_sort_nametypes():
"""Return a list of the various translationnames for the fields"""
type = {}
type['soo'] = 'Sort options'
type['seo'] = 'Search options'
type['sew'] = 'Search within'
return type
def get_fmt_nametypes():
"""Return a list of the various translationnames for the output formats"""
type = []
type.append(('ln', 'Long name'))
return type
def get_fld_nametypes():
"""Return a list of the various translationnames for the fields"""
type = []
type.append(('ln', 'Long name'))
return type
def get_col_nametypes():
"""Return a list of the various translationnames for the collections"""
type = []
type.append(('ln', 'Long name'))
return type
def find_last(tree, start_son):
"""Find the previous collection in the tree with the same father as start_son"""
id_dad = tree[start_son][3]
while start_son > 0:
start_son -= 1
if tree[start_son][3] == id_dad:
return start_son
def find_next(tree, start_son):
"""Find the next collection in the tree with the same father as start_son"""
id_dad = tree[start_son][3]
while start_son < len(tree):
start_son += 1
if tree[start_son][3] == id_dad:
return start_son
def attach_rnk_col(colID, rnkID):
"""attach rank method to collection
rnkID - id from rnkMETHOD table
colID - id of collection, as in collection table """
try:
res = run_sql("INSERT INTO collection_rnkMETHOD(id_collection, id_rnkMETHOD) values (%s,%s)" % (colID, rnkID))
return "true"
except StandardError, e:
return ""
def detach_rnk_col(colID, rnkID):
"""detach rank method from collection
rnkID - id from rnkMETHOD table
colID - id of collection, as in collection table """
try:
res = run_sql("DELETE FROM collection_rnkMETHOD WHERE id_collection=%s AND id_rnkMETHOD=%s" % (colID, rnkID))
except StandardError, e:
return ""
return "true"
def remove_pbx(colID, pbxID, ln):
"""Removes a portalbox from the collection given.
colID - the collection the format is connected to
pbxID - the portalbox which should be removed from the collection.
ln - the language of the portalbox to be removed"""
try:
res = run_sql("DELETE FROM collection_portalbox WHERE id_collection=%s AND id_portalbox=%s AND ln='%s'" % (colID, pbxID, ln))
return "true"
except StandardError, e:
return ""
def remove_fmt(colID,fmtID):
"""Removes a format from the collection given.
colID - the collection the format is connected to
fmtID - the format which should be removed from the collection."""
try:
res = run_sql("DELETE FROM collection_format WHERE id_collection=%s AND id_format=%s" % (colID, fmtID))
return "true"
except StandardError, e:
return ""
def remove_fld(colID,fldID, fldvID=''):
"""Removes a field from the collection given.
colID - the collection the format is connected to
fldID - the field which should be removed from the collection."""
try:
sql = "DELETE FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s" % (colID, fldID)
if fldvID:
sql += " AND id_fieldvalue=%s" % fldvID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def delete_pbx(pbxID):
"""Deletes all data for the given portalbox
pbxID - delete all data in the tables associated with portalbox and this id """
try:
res = run_sql("DELETE FROM collection_portalbox WHERE id_portalbox=%s" % pbxID)
res = run_sql("DELETE FROM portalbox WHERE id=%s" % pbxID)
return "true"
except StandardError, e:
return ""
def delete_fmt(fmtID):
"""Deletes all data for the given format
fmtID - delete all data in the tables associated with format and this id """
try:
res = run_sql("DELETE FROM format WHERE id=%s" % fmtID)
res = run_sql("DELETE FROM collection_format WHERE id_format=%s" % fmtID)
res = run_sql("DELETE FROM formatname WHERE id_format=%s" % fmtID)
return "true"
except StandardError, e:
return ""
def delete_col(colID):
"""Deletes all data for the given collection
colID - delete all data in the tables associated with collection and this id """
try:
res = run_sql("DELETE FROM collection WHERE id=%s" % colID)
res = run_sql("DELETE FROM collectionname WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_rnkMETHOD WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_collection WHERE id_dad=%s" % colID)
res = run_sql("DELETE FROM collection_collection WHERE id_son=%s" % colID)
res = run_sql("DELETE FROM collection_portalbox WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_format WHERE id_collection=%s" % colID)
res = run_sql("DELETE FROM collection_field_fieldvalue WHERE id_collection=%s" % colID)
return "true"
except StandardError, e:
return ""
def add_fmt(code, name, rtype):
"""Add a new output format. Returns the id of the format.
code - the code for the format, max 6 chars.
name - the default name for the default language of the format.
rtype - the default nametype"""
try:
res = run_sql("INSERT INTO format (code, name) values ('%s','%s')" % (MySQLdb.escape_string(code), MySQLdb.escape_string(name)))
fmtID = run_sql("SELECT id FROM format WHERE code='%s'" % MySQLdb.escape_string(code))
res = run_sql("INSERT INTO formatname(id_format, type, ln, value) VALUES (%s,'%s','%s','%s')" % (fmtID[0][0], rtype, cdslang, MySQLdb.escape_string(name)))
return fmtID
except StandardError, e:
return ""
def add_pbx(title, body):
try:
res = run_sql("INSERT INTO portalbox (title, body) values ('%s','%s')" % (MySQLdb.escape_string(title), MySQLdb.escape_string(body)))
res = run_sql("SELECT id FROM portalbox WHERE title='%s' AND body='%s'" % (MySQLdb.escape_string(title), MySQLdb.escape_string(body)))
return res
except StandardError, e:
return ""
def add_col(colNAME, dbquery, rest):
"""Adds a new collection to collection table
colNAME - the default name for the collection, saved to collection and collectionname
dbquery - query related to the collection
rest - name of apache group allowed to access collection"""
try:
rtype = get_col_nametypes()[0][0]
sql = "INSERT INTO collection(name,dbquery,restricted) VALUES('%s'" % MySQLdb.escape_string(colNAME)
if dbquery:
sql += ",'%s'" % MySQLdb.escape_string(dbquery)
else:
sql += ",null"
if rest:
sql += ",'%s'" % MySQLdb.escape_string(rest)
else:
sql += ",null"
sql += ")"
res = run_sql(sql)
colID = run_sql("SELECT id FROM collection WHERE name='%s'" % MySQLdb.escape_string(colNAME))
res = run_sql("INSERT INTO collectionname(id_collection, type, ln, value) VALUES (%s,'%s','%s','%s')" % (colID[0][0], rtype, cdslang, MySQLdb.escape_string(colNAME)))
return colID
except StandardError, e:
return ""
def add_col_pbx(colID, pbxID, ln, position, score=''):
"""add a portalbox to the collection.
colID - the id of the collection involved
pbxID - the portalbox to add
ln - which language the portalbox is for
score - decides which portalbox is the most important
position - position on page the portalbox should appear."""
try:
if score:
res = run_sql("INSERT INTO collection_portalbox(id_portalbox, id_collection, ln, score, position) values (%s,%s,'%s',%s,'%s')" % (pbxID, colID, ln, score, position))
else:
res = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and ln='%s' and position='%s' ORDER BY score desc, ln, position" % (colID, ln, position))
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_portalbox(id_portalbox, id_collection, ln, score, position) values (%s,%s,'%s',%s,'%s')" % (pbxID, colID, ln, (score + 1), position))
return "true"
except StandardError, e:
return ""
def add_col_fmt(colID, fmtID, score=''):
"""Add a output format to the collection.
colID - the id of the collection involved
fmtID - the id of the format.
score - the score of the format, decides sorting, if not given, place the format on top"""
try:
if score:
res = run_sql("INSERT INTO collection_format(id_format, id_collection, score) values (%s,%s,%s)" % (fmtID, colID, score))
else:
res = run_sql("SELECT score FROM collection_format WHERE id_collection=%s ORDER BY score desc" % colID)
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_format(id_format, id_collection, score) values (%s,%s,%s)" % (fmtID, colID, (score + 1)))
return "true"
except StandardError, e:
return ""
def add_col_fld(colID, fldID, type, fldvID=''):
"""Add a sort/search/field to the collection.
colID - the id of the collection involved
fmtID - the id of the format.
score - the score of the format, decides sorting, if not given, place the format on top"""
try:
if fldvID and fldvID not in [-1, "-1"]:
res = run_sql("SELECT score, score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s ORDER BY score desc, score_fieldvalue desc" % (colID, fldID))
if res:
score = int(res[0][0])
v_score = int(res[0][1])
else:
score = 0
v_score = 0
res = run_sql("SELECT * FROM collection_field_fieldvalue where id_field=%s and id_collection=%s and type='%s' and id_fieldvalue=%s" % (fldID, colID, type, fldvID))
if not res:
res = run_sql("INSERT INTO collection_field_fieldvalue(id_field, id_fieldvalue, id_collection, type, score, score_fieldvalue) values (%s,%s,%s,'%s',%s,%s)" % (fldID, fldvID, colID, type, score, (v_score + 1)))
else:
raise StandardError
else:
res = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s ORDER BY score desc" % (colID, fldID))
if res:
score = int(res[0][0])
else:
score = 0
res = run_sql("INSERT INTO collection_field_fieldvalue(id_field, id_collection, type, score) values (%s,%s,'%s',%s)" % (fldID, colID, type, (score + 1)))
return "true"
except StandardError, e:
return ""
def modify_restricted(colID, rest):
"""Modify the dwhich apache group is allowed to use the collection.
colID - the id of the collection involved
restricted - the new group"""
try:
sql = "UPDATE collection SET restricted="
if rest:
sql += "'%s'" % MySQLdb.escape_string(rest)
else:
sql += "null"
sql += " WHERE id=%s" % colID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def modify_dbquery(colID, dbquery):
"""Modify the dbquery of an collection.
colID - the id of the collection involved
dbquery - the new dbquery"""
try:
sql = "UPDATE collection SET dbquery="
if dbquery:
sql += "'%s'" % MySQLdb.escape_string(dbquery)
else:
sql += "null"
sql += " WHERE id=%s" % colID
res = run_sql(sql)
return "true"
except StandardError, e:
return ""
def modify_pbx(colID, pbxID, sel_ln, score='', position='', title='', body=''):
"""Modify a portalbox
colID - the id of the collection involved
pbxID - the id of the portalbox that should be modified
sel_ln - the language of the portalbox that should be modified
title - the title
body - the content
score - if several portalboxes in one position, who should appear on top.
position - position on page"""
try:
if title:
res = run_sql("UPDATE portalbox SET title='%s' WHERE id=%s" % (MySQLdb.escape_string(title), pbxID))
if body:
res = run_sql("UPDATE portalbox SET body='%s' WHERE id=%s" % (MySQLdb.escape_string(body), pbxID))
if score:
res = run_sql("UPDATE collection_portalbox SET score='%s' WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (score, colID, pbxID, sel_ln))
if position:
res = run_sql("UPDATE collection_portalbox SET position='%s' WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (position, colID, pbxID, sel_ln))
return "true"
except StandardError, e:
return ""
def switch_fld_score(colID, id_1, id_2):
"""Switch the scores of id_1 and id_2 in collection_field_fieldvalue
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s" % (colID, id_1))
res2 = run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s" % (colID, id_2))
res = run_sql("UPDATE collection_field_fieldvalue SET score=%s WHERE id_collection=%s and id_field=%s" % (res2[0][0], colID, id_1))
res = run_sql("UPDATE collection_field_fieldvalue SET score=%s WHERE id_collection=%s and id_field=%s" % (res1[0][0], colID, id_2))
return "true"
except StandardError, e:
return ()
def switch_fld_value_score(colID, id_1, fldvID_1, fldvID_2):
"""Switch the scores of two field_value
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (colID, id_1, fldvID_1))
res2 = run_sql("SELECT score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (colID, id_1, fldvID_2))
res = run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=%s WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (res2[0][0], colID, id_1, fldvID_1))
res = run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=%s WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s" % (res1[0][0], colID, id_1, fldvID_2))
return "true"
except StandardError, e:
return ()
def switch_pbx_score(colID, id_1, id_2, sel_ln):
"""Switch the scores of id_1 and id_2 in the table given by the argument.
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (colID, id_1, sel_ln))
res2 = run_sql("SELECT score FROM collection_portalbox WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (colID, id_2, sel_ln))
res = run_sql("UPDATE collection_portalbox SET score=%s WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (res2[0][0], colID, id_1, sel_ln))
res = run_sql("UPDATE collection_portalbox SET score=%s WHERE id_collection=%s and id_portalbox=%s and ln='%s'" % (res1[0][0], colID, id_2, sel_ln))
return "true"
except StandardError, e:
return ()
def switch_score(colID, id_1, id_2, table):
"""Switch the scores of id_1 and id_2 in the table given by the argument.
colID - collection the id_1 or id_2 is connected to
id_1/id_2 - id field from tables like format..portalbox...
table - name of the table"""
try:
res1 = run_sql("SELECT score FROM collection_%s WHERE id_collection=%s and id_%s=%s" % (table, colID, table, id_1))
res2 = run_sql("SELECT score FROM collection_%s WHERE id_collection=%s and id_%s=%s" % (table, colID, table, id_2))
res = run_sql("UPDATE collection_%s SET score=%s WHERE id_collection=%s and id_%s=%s" % (table, res2[0][0], colID, table, id_1))
res = run_sql("UPDATE collection_%s SET score=%s WHERE id_collection=%s and id_%s=%s" % (table, res1[0][0], colID, table, id_2))
return "true"
except StandardError, e:
return ()
diff --git a/modules/websearch/web/admin/websearchadmin.py b/modules/websearch/web/admin/websearchadmin.py
index aa7d68a55..6056ea588 100644
--- a/modules/websearch/web/admin/websearchadmin.py
+++ b/modules/websearch/web/admin/websearchadmin.py
@@ -1,804 +1,824 @@
## Administrator interface for WebSearch
## 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"
## $Id$## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
"""CDSware WebSearch Administrator Interface."""
__lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>"""
## fill config variables:
pylibdir = "/python"
import sys
sys.path.append('%s' % pylibdir)
import cdsware.websearchadminlib as wsc
#reload(wsc)
from cdsware.webpage import page, create_error_box
from cdsware.config import weburl,cdslang
from cdsware.webuser import getUid
__version__ = "$Id$"
def switchfmtscore(req, colID, type, id_1, id_2, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfmtscore(colID=colID,
ln=ln,
type=type,
id_1=id_1,
id_2=id_2),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchfldscore(req, colID, id_1, id_2, fmeth, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfldscore(colID=colID,
ln=ln,
id_1=id_1,
id_2=id_2,
fmeth=fmeth),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchfldvaluescore(req, colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfldvaluescore(colID=colID,
ln=ln,
id_1=id_1,
id_fldvalue_1=id_fldvalue_1,
id_fldvalue_2=id_fldvalue_2),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchpbxscore(req, colID, id_1, id_2, sel_ln,ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchpbxscore(colID=colID,
ln=ln,
id_1=id_1,
id_2=id_2,
sel_ln=sel_ln),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifydbquery(req, colID, ln=cdslang, dbquery='', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifydbquery(colID=colID,
ln=ln,
dbquery=dbquery,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
+def showtree(req, colID, ln=cdslang):
+ navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
+
+ try:
+ uid = getUid(req)
+ except MySQLdb.Error, e:
+ return error_page(req)
+
+ if not wsc.check_user(uid, 'cfgwebsearch'):
+ return page(title="Edit Collection",
+ body=wsc.perform_showtree(colID=colID,
+ ln=ln),
+ uid=uid,
+ language=ln,
+ urlargs=req.args,
+ navtrail = navtrail_previous_links,
+ lastupdated=__lastupdated__)
+ else:
+ return auth_failed(uid, navtrail_previous_links)
+
def modifyrestricted(req, colID, ln=cdslang, rest='', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyrestricted(colID=colID,
ln=ln,
rest=rest,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifytranslations(req, colID, ln=cdslang, sel_type='', trans = [], confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifytranslations(colID=colID,
ln=ln,
sel_type=sel_type,
trans=trans,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addcollectiontotree(req, colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_addcollectiontotree(colID=colID,
ln=cdslang,
add_dad=add_dad,
add_son=add_son,
rtype=rtype,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
navtrail = navtrail_previous_links,
urlargs=req.args,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addcollection(req, colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_addcollection(colID=colID,
ln=cdslang,
colNAME=colNAME,
dbquery=dbquery,
rest=rest,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
navtrail = navtrail_previous_links,
urlargs=req.args,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyrankmethods(req, colID, ln=cdslang, func='', rnkID='', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyrankmethods(colID=colID,
ln=ln,
func=func,
rnkID=rnkID,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def deletecollection(req, colID, ln=cdslang, confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deletecollection(colID=colID,
ln=ln,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def editcollection(req, colID=1, ln=cdslang, mtype=''):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_editcollection(colID=colID,
ln=ln,
mtype=mtype),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addoutputformat(req, colID, ln=cdslang, code='', name='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addoutputformat(colID=colID,
ln=ln,
code=code,
name=name,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showoutputformats(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showoutputformats(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def deleteoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deleteoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removeoutputformat(req, colID, ln=cdslang, fmtID='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removeoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removefield(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removefield(colID=colID,
ln=ln,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyoutputformat(req, colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
sel_type=sel_type,
trans=trans,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showsearchoptions(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsearchoptions(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingfield(req, colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingfield(colID=colID,
ln=ln,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)
def showsearchfields(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsearchfields(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showsortoptions(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsortoptions(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyportalbox(req, colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
score=score,
position=position,
sel_ln=sel_ln,
title=title,
body=body,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removeportalbox(req, colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removeportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
sel_ln=sel_ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingportalbox(req, colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
score=score,
position=position,
sel_ln=sel_ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)
def deleteportalbox(req, colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deleteportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showportalboxes(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showportalboxes(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addportalbox(req, colID, ln=cdslang, title='', body='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addportalbox(colID=colID,
ln=ln,
title=title,
body=body,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifycollectiontree(req, colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_modifycollectiontree(colID=colID,
ln=ln,
move_up=move_up,
move_down=move_down,
move_from=move_from,
move_to=move_to,
delete=delete,
rtype=rtype,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def index(req, colID=1, ln=cdslang, mtype='', content='', confirm=0):
navtrail_previous_links = wsc.getnavtrail()
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_index(colID=colID,
ln=ln,
mtype=mtype,
content=content,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def error_page(req):
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)
def auth_failed(uid, navtrail_previous_links):
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)
diff --git a/modules/websearch/web/admin/websearchadmin.py.wml b/modules/websearch/web/admin/websearchadmin.py.wml
index aa7d68a55..6056ea588 100644
--- a/modules/websearch/web/admin/websearchadmin.py.wml
+++ b/modules/websearch/web/admin/websearchadmin.py.wml
@@ -1,804 +1,824 @@
## Administrator interface for WebSearch
## 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"
## $Id$## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
"""CDSware WebSearch Administrator Interface."""
__lastupdated__ = """<: print `date +"%d %b %Y %H:%M:%S %Z"`; :>"""
## fill config variables:
pylibdir = "/python"
import sys
sys.path.append('%s' % pylibdir)
import cdsware.websearchadminlib as wsc
#reload(wsc)
from cdsware.webpage import page, create_error_box
from cdsware.config import weburl,cdslang
from cdsware.webuser import getUid
__version__ = "$Id$"
def switchfmtscore(req, colID, type, id_1, id_2, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfmtscore(colID=colID,
ln=ln,
type=type,
id_1=id_1,
id_2=id_2),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchfldscore(req, colID, id_1, id_2, fmeth, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfldscore(colID=colID,
ln=ln,
id_1=id_1,
id_2=id_2,
fmeth=fmeth),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchfldvaluescore(req, colID, id_1, id_fldvalue_1, id_fldvalue_2, ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchfldvaluescore(colID=colID,
ln=ln,
id_1=id_1,
id_fldvalue_1=id_fldvalue_1,
id_fldvalue_2=id_fldvalue_2),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def switchpbxscore(req, colID, id_1, id_2, sel_ln,ln=cdslang):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_switchpbxscore(colID=colID,
ln=ln,
id_1=id_1,
id_2=id_2,
sel_ln=sel_ln),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifydbquery(req, colID, ln=cdslang, dbquery='', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifydbquery(colID=colID,
ln=ln,
dbquery=dbquery,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
+def showtree(req, colID, ln=cdslang):
+ navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
+
+ try:
+ uid = getUid(req)
+ except MySQLdb.Error, e:
+ return error_page(req)
+
+ if not wsc.check_user(uid, 'cfgwebsearch'):
+ return page(title="Edit Collection",
+ body=wsc.perform_showtree(colID=colID,
+ ln=ln),
+ uid=uid,
+ language=ln,
+ urlargs=req.args,
+ navtrail = navtrail_previous_links,
+ lastupdated=__lastupdated__)
+ else:
+ return auth_failed(uid, navtrail_previous_links)
+
def modifyrestricted(req, colID, ln=cdslang, rest='', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyrestricted(colID=colID,
ln=ln,
rest=rest,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifytranslations(req, colID, ln=cdslang, sel_type='', trans = [], confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifytranslations(colID=colID,
ln=ln,
sel_type=sel_type,
trans=trans,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addcollectiontotree(req, colID, ln=cdslang, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_addcollectiontotree(colID=colID,
ln=cdslang,
add_dad=add_dad,
add_son=add_son,
rtype=rtype,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
navtrail = navtrail_previous_links,
urlargs=req.args,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addcollection(req, colID, ln=cdslang, colNAME='', dbquery='', rest='', callback="yes", confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_addcollection(colID=colID,
ln=cdslang,
colNAME=colNAME,
dbquery=dbquery,
rest=rest,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
navtrail = navtrail_previous_links,
urlargs=req.args,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyrankmethods(req, colID, ln=cdslang, func='', rnkID='', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyrankmethods(colID=colID,
ln=ln,
func=func,
rnkID=rnkID,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def deletecollection(req, colID, ln=cdslang, confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deletecollection(colID=colID,
ln=ln,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def editcollection(req, colID=1, ln=cdslang, mtype=''):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_editcollection(colID=colID,
ln=ln,
mtype=mtype),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addoutputformat(req, colID, ln=cdslang, code='', name='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addoutputformat(colID=colID,
ln=ln,
code=code,
name=name,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showoutputformats(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showoutputformats(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def deleteoutputformat(req, colID, ln=cdslang, fmtID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deleteoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removeoutputformat(req, colID, ln=cdslang, fmtID='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removeoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removefield(req, colID, ln=cdslang, fldID='', fldvID='', fmeth='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removefield(colID=colID,
ln=ln,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyoutputformat(req, colID, ln=cdslang, fmtID=-1, sel_type='', trans=[], confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyoutputformat(colID=colID,
ln=ln,
fmtID=fmtID,
sel_type=sel_type,
trans=trans,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showsearchoptions(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsearchoptions(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingfield(req, colID, ln=cdslang, fldID=-1, fldvID=-1, fmeth='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingfield(colID=colID,
ln=ln,
fldID=fldID,
fldvID=fldvID,
fmeth=fmeth,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)
def showsearchfields(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsearchfields(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showsortoptions(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showsortoptions(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifyportalbox(req, colID, ln=cdslang, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_modifyportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
score=score,
position=position,
sel_ln=sel_ln,
title=title,
body=body,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def removeportalbox(req, colID, ln=cdslang, pbxID='', sel_ln='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_removeportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
sel_ln=sel_ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addexistingportalbox(req, colID, ln=cdslang, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addexistingportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
score=score,
position=position,
sel_ln=sel_ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)
def deleteportalbox(req, colID, ln=cdslang, pbxID=-1, callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_deleteportalbox(colID=colID,
ln=ln,
pbxID=pbxID,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def showportalboxes(req, colID, ln=cdslang, callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_showportalboxes(colID=colID,
ln=ln,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def addportalbox(req, colID, ln=cdslang, title='', body='', callback='yes', confirm=-1):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection",
body=wsc.perform_addportalbox(colID=colID,
ln=ln,
title=title,
body=body,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def modifycollectiontree(req, colID, ln=cdslang, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0):
navtrail_previous_links = wsc.getnavtrail() + """> Edit Collection Tree """ % (weburl)
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_modifycollectiontree(colID=colID,
ln=ln,
move_up=move_up,
move_down=move_down,
move_from=move_from,
move_to=move_to,
delete=delete,
rtype=rtype,
callback=callback,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def index(req, colID=1, ln=cdslang, mtype='', content='', confirm=0):
navtrail_previous_links = wsc.getnavtrail()
try:
uid = getUid(req)
except MySQLdb.Error, e:
return error_page(req)
if not wsc.check_user(uid, 'cfgwebsearch'):
return page(title="Edit Collection Tree",
body=wsc.perform_index(colID=colID,
ln=ln,
mtype=mtype,
content=content,
confirm=confirm),
uid=uid,
language=ln,
urlargs=req.args,
navtrail = navtrail_previous_links,
lastupdated=__lastupdated__)
else:
return auth_failed(uid, navtrail_previous_links)
def error_page(req):
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)
def auth_failed(uid, navtrail_previous_links):
return page(title='Authorization failure',
uid=uid,
body=wsc.adderrorbox('try to login first',
datalist=["""You are not a user authorized to perform admin tasks, try to
login with another account.""" % (weburl, weburl)]),
navtrail= navtrail_previous_links,
lastupdated=__lastupdated__)