output2+="""<b><span class="info">All fields must be filled.</span></b><br><br>
"""
elifadd_sonandadd_dadandrtype:
add_son=int(add_son)
add_dad=int(add_dad)
ifconfirmnotin[-1,"-1"]:
ifadd_son==add_dad:
output2+="""<b><span class="info">Cannot add a collection as a pointer to itself.</span></b><br><br>
"""
elifcheck_col(add_dad,add_son):
res=add_col_dad_son(add_dad,add_son,rtype)
output2+=write_outcome(res)
ifres[0]==1:
output2+="""<b><span class="info"><br> The collection will appear on your website after the next webcoll run. You can either run it manually or wait until bibsched does it for you.</span></b><br><br>
"""
else:
output2+="""<b><span class="info">Cannot add the collection '%s' as a %s subcollection of '%s' since it will either create a loop, or the association already exists.</span></b><br><br>
res=run_sql("SELECT dbquery FROM collection WHERE id=%s"%colID)
dbquery=res[0][0]
ifnotdbquery:
dbquery=''
reg_sons=len(get_col_tree(colID,'r'))
vir_sons=len(get_col_tree(colID,'v'))
ifreg_sons>1:
ifdbquery:
output+="Warning: This collection got subcollections, and should because of this not have a collection query, for further explanation, check the WebSearch Guide<br>"
elifreg_sons<=1:
ifnotdbquery:
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<br>"
text="""Do you want to remove the %s '%s' %s from the collection '%s'."""%(field,fld_dict[fldID],(fldvIDnotin["","None"]and"with value '%s'"%fldv_dict[fldvID]or''),col_dict[colID])
run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=%s WHERE id_collection=%s and id_field=%s and id_fieldvalue=%s"%(vscore,colID,fldID,fldvID))
vscore-=1
output+=write_outcome((1,""))
else:
output+=write_outcome((0,(0,"No values to order")))
ifcdsname!=run_sql("SELECT name from collection WHERE id=1")[0][0]:
res=run_sql("update collection set name='%s' where id=1"%cdsname)
ifres:
fin_output+="""<b><span class="info">The name of the root collection has been modified to be the same as the %(cdsname)s installation name given prior to installing %(cdsname)s.</span><b><br>"""%{'cdsname':cdsname}
<td>1. <small><a href="%s/admin/websearch/websearchadmin.py?colID=%s&ln=%s&mtype=perform_addcollection">Create new collection</a></small></td>
<td>2. <small><a href="%s/admin/websearch/websearchadmin.py?colID=%s&ln=%s&mtype=perform_addcollectiontotree">Attach collection to tree</a></small></td>
text+="""<a href="%s/admin/websearch/websearchadmin.py/modifycollectiontree?colID=%s&ln=%s&move_from=%s%s&rtype=%s#%s"><img border="0" src="%s/img/move_from.gif" title="Move '%s' from this location."></a>"""%(weburl,colID,ln,rtype,i,rtype,tree[i][0],weburl,col_dict[tree[i][0]])
<dd>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.
<br>For more information, please go to the <a title="See guide" href="%s/help/admin/websearch-admin-guide">WebSearch guide</a> and read the section regarding deleting a collection.</dd>
output="""<b><span class="info">Can not delete a collection that is a part of the collection tree, remove collection from the tree and try again.</span></b>"""
else:
subtitle="""4. Delete collection"""
output="""<b><span class="info">Not possible to delete the root collection</span></b>"""
<td>11. <small><a href="editcollection?colID=%s&ln=%s&mtype=perform_manage_external_collections#11">Configuration of related external collections</a></small></td>
<td>12. <small><a href="editcollection?colID=%s&ln=%s&mtype=perform_showdetailedrecordoptions#12">Detailed record page options</a></small></td>
output+="""<br><b><span class="info">Warning: The collections has been modified since last time Webcoll was executed, to process the changes, Webcoll must be executed.</span></b><br>"""
header=['ID','Name','Time','Status','Progress']
actions=[]
output+="""<br><b>Last BibSched tasks:</b><br>"""
res=run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='webcoll' and runtime< now() ORDER by runtime")
res=run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='bibindex' and runtime< now() ORDER by runtime")
res=run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='webcoll' and runtime > now() ORDER by runtime")
res=run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='bibindex' and runtime > now() ORDER by runtime")
output+="""<br><b><span class="info">Warning: Webcoll is not scheduled for a future run by bibsched, any updates to the collection will not be processed.</span></b><br>"""
ifbibindex_future=="":
output+="""<br><b><span class="info">Warning: Bibindex is not scheduled for a future run by bibsched, any updates to the records will not be processed.</span></b><br>"""
"""Returns a presentation of the tree as a list. TODO: Add loop detection
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')]
whilelen(stack)>0:
ccolID=stack.pop()
ifccolID==colIDandrtype:
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=[]
foriinrange(0,len(res)):
id_son=res[i][0]
score=res[i][1]
rtype=res[i][2]
stack.append(id_son)
ifi==(len(res)-1):
up=0
else:
up=1
ifi==0:
down=0
else:
down=1
ntree.insert(0,(id_son,up,down,ccolID,rtype))
tree=tree[0:ssize]+ntree+tree[ssize:len(tree)]
returntree
exceptStandardError,e:
return()
defadd_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
forscoreinres:
ifint(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(1,highscore)
exceptStandardError,e:
return(0,e)
defcompare_on_val(first,second):
"""Compare the two values"""
returncmp(first[1],second[1])
defget_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:
ifcolID>-1:
sql+=" AND id_collection=%s"%colID
ifid_field:
sql+=" AND id_field=%s"%id_field
iftype:
sql+=" AND type='%s'"%type
sql+=" ORDER BY type, score desc, score_fieldvalue desc"
res=run_sql(sql)
returnres
exceptStandardError,e:
return""
defget_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:
ifcolID>-1:
sql+=" AND id_collection=%s"%colID
ifln:
sql+=" AND ln='%s'"%ln
ifposition:
sql+=" AND position='%s'"%position
sql+=" ORDER BY position, ln, score desc"
res=run_sql(sql)
returnres
exceptStandardError,e:
return""
defget_col_fmt(colID=-1):
"""Returns all formats currently associated with a collection, or for one specific collection
colID - the id of the collection"""
try:
ifcolIDnotin[-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")
returnres
exceptStandardError,e:
return""
defget_col_rnk(colID,ln):
""" 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_def_name('',"rnkMETHOD")
result=filter(lambdax:res1.has_key(x[0]),res2)
returnresult
exceptStandardError,e:
return()
defget_pbx():
"""Returns all portalboxes"""
try:
res=run_sql("SELECT id, title, body FROM portalbox ORDER by title,body")
returnres
exceptStandardError,e:
return""
defget_fld_value(fldvID=''):
"""Returns fieldvalue"""
try:
sql="SELECT id, name, value FROM fieldvalue"
iffldvID:
sql+=" WHERE id=%s"%fldvID
sql+=" ORDER BY name"
res=run_sql(sql)
returnres
exceptStandardError,e:
return""
defget_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"
returnposition
defget_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'
returntype
defget_fmt_nametypes():
"""Return a list of the various translationnames for the output formats"""
type=[]
type.append(('ln','Long name'))
returntype
defget_fld_nametypes():
"""Return a list of the various translationnames for the fields"""
type=[]
type.append(('ln','Long name'))
returntype
defget_col_nametypes():
"""Return a list of the various translationnames for the collections"""
type=[]
type.append(('ln','Long name'))
returntype
deffind_last(tree,start_son):
"""Find the previous collection in the tree with the same father as start_son"""
id_dad=tree[start_son][3]
whilestart_son>0:
start_son-=1
iftree[start_son][3]==id_dad:
returnstart_son
deffind_next(tree,start_son):
"""Find the next collection in the tree with the same father as start_son"""
id_dad=tree[start_son][3]
whilestart_son<len(tree):
start_son+=1
iftree[start_son][3]==id_dad:
returnstart_son
defremove_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:
ifid_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))
ifnotrun_sql("SELECT * from collection_collection WHERE id_son=%s and type='%s'"%(id_son,type)):
for(id,up,down,dad,rtype)intree:
res=run_sql("DELETE FROM collection_collection WHERE id_son=%s and id_dad=%s"%(id,dad))
return(1,"")
exceptStandardError,e:
return(0,e)
defcheck_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))
ifres:
raiseStandardError
whilelen(stack)>0:
colID=stack.pop()
res=run_sql("SELECT id_dad FROM collection_collection WHERE id_son=%s"%colID)
foridinres:
ifint(id[0])==int(add_son):
raiseStandardError
else:
stack.append(id[0])
return(1,"")
exceptStandardError,e:
return(0,e)
defattach_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(1,"")
exceptStandardError,e:
return(0,e)
defdetach_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))
return(1,"")
exceptStandardError,e:
return(0,e)
defswitch_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]))
"""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
forscoreinres:
ifint(score[0])>highscore:
highscore=int(score[0])
highscore+=1
ifnotmove_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(1,"")
exceptStandardError,e:
return(0,e)
defremove_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(1,"")
exceptStandardError,e:
return(0,e)
defremove_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(1,"")
exceptStandardError,e:
return(0,e)
defremove_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)
iffldvID:
iffldvID!="None":
sql+=" AND id_fieldvalue=%s"%fldvID
else:
sql+=" AND id_fieldvalue is NULL"
res=run_sql(sql)
return(1,"")
exceptStandardError,e:
return(0,e)
defdelete_fldv(fldvID):
"""Deletes all data for the given fieldvalue
fldvID - delete all data in the tables associated with fieldvalue and this id"""
try:
res=run_sql("DELETE FROM collection_field_fieldvalue WHERE id_fieldvalue=%s"%fldvID)
res=run_sql("DELETE FROM fieldvalue WHERE id=%s"%fldvID)
return(1,"")
exceptStandardError,e:
return(0,e)
defdelete_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(1,"")
exceptStandardError,e:
return(0,e)
defdelete_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(1,"")
exceptStandardError,e:
return(0,e)
defdelete_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(1,"")
exceptStandardError,e:
return(0,e)
defadd_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)",(code,name))
fmtID=run_sql("SELECT id FROM format WHERE code=%s",(code,))
res=run_sql("INSERT INTO formatname(id_format, type, ln, value) VALUES (%s,%s,%s,%s)",
(fmtID[0][0],rtype,cdslang,name))
return(1,fmtID)
exceptStandardError,e:
return(0,e)
defupdate_fldv(fldvID,name,value):
"""Modify existing fieldvalue
fldvID - id of fieldvalue to modify
value - the value of the fieldvalue
name - the name of the fieldvalue."""
try:
res=run_sql("UPDATE fieldvalue set name=%s where id=%s",(name,fldvID))
res=run_sql("UPDATE fieldvalue set value=%s where id=%s",(value,fldvID))
return(1,"")
exceptStandardError,e:
return(0,e)
defadd_fldv(name,value):
"""Add a new fieldvalue, returns id of fieldvalue
value - the value of the fieldvalue
name - the name of the fieldvalue."""
try:
res=run_sql("SELECT id FROM fieldvalue WHERE name=%s and value=%s",(name,value))
ifnotres:
res=run_sql("INSERT INTO fieldvalue (name, value) values (%s,%s)",(name,value))
res=run_sql("SELECT id FROM fieldvalue WHERE name=%s and value=%s",(name,value))
ifres:
return(1,res[0][0])
else:
raiseStandardError
exceptStandardError,e:
return(0,e)
defadd_pbx(title,body):
try:
res=run_sql("INSERT INTO portalbox (title, body) values (%s,%s)",(title,body))
res=run_sql("SELECT id FROM portalbox WHERE title=%s AND body=%s",(title,body))
ifres:
return(1,res[0][0])
else:
raiseStandardError
exceptStandardError,e:
return(0,e)
defadd_col(colNAME,dbquery=None):
"""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"""
# BTW, sometimes '' are passed instead of None, so change them to None
ifnotdbquery:
dbquery=None
try:
rtype=get_col_nametypes()[0][0]
colID=run_sql("SELECT id FROM collection WHERE id=1")
ifcolID:
res=run_sql("INSERT INTO collection (name,dbquery) VALUES (%s,%s)",
(colNAME,dbquery))
else:
res=run_sql("INSERT INTO collection (id,name,dbquery) VALUES (1,%s,%s)",
(colNAME,dbquery))
colID=run_sql("SELECT id FROM collection WHERE name=%s",(colNAME,))
res=run_sql("INSERT INTO collectionname(id_collection, type, ln, value) VALUES (%s,%s,%s,%s)"%(colID[0][0],rtype,cdslang,colNAME))
ifcolID:
return(1,colID[0][0])
else:
raiseStandardError
exceptStandardError,e:
return(0,e)
defadd_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:
ifscore:
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))
ifres:
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(1,"")
exceptStandardError,e:
return(0,e)
defadd_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:
ifscore:
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)
ifres:
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(1,"")
exceptStandardError,e:
return(0,e)
defadd_col_fld(colID,fldID,type,fldvID=''):
"""Add a sort/search/field to the collection.
colID - the id of the collection involved
fldID - the id of the field.
fldvID - the id of the fieldvalue.
type - which type, seo, sew...
score - the score of the format, decides sorting, if not given, place the format on top"""
try:
iffldvIDandfldvIDnotin[-1,"-1"]:
run_sql("DELETE FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s and type='%s' and id_fieldvalue is NULL"%(colID,fldID,type))
res=run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s and type='%s' ORDER BY score desc"%(colID,fldID,type))
ifres:
score=int(res[0][0])
res=run_sql("SELECT score_fieldvalue FROM collection_field_fieldvalue WHERE id_collection=%s AND id_field=%s and type='%s' ORDER BY score_fieldvalue desc"%(colID,fldID,type))
else:
res=run_sql("SELECT score FROM collection_field_fieldvalue WHERE id_collection=%s and type='%s' ORDER BY score desc"%(colID,type))
ifres:
score=int(res[0][0])+1
else:
score=1
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))
ifnotres:
run_sql("UPDATE collection_field_fieldvalue SET score_fieldvalue=score_fieldvalue+1 WHERE id_field=%s AND id_collection=%s and type='%s'"%(fldID,colID,type))
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,1))
else:
return(0,(1,"Already exists"))
else:
res=run_sql("SELECT * FROM collection_field_fieldvalue WHERE id_collection=%s AND type='%s' and id_field=%s and id_fieldvalue is NULL"%(colID,type,fldID))
ifres:
return(0,(1,"Already exists"))
else:
run_sql("UPDATE collection_field_fieldvalue SET score=score+1")
res=run_sql("INSERT INTO collection_field_fieldvalue(id_field, id_collection, type, score,score_fieldvalue) values (%s,%s,'%s',%s, 0)"%(fldID,colID,type,1))
return(1,"")
exceptStandardError,e:
return(0,e)
defmodify_dbquery(colID,dbquery=None):
"""Modify the dbquery of an collection.
colID - the id of the collection involved
dbquery - the new dbquery"""
# BTW, sometimes '' is passed instead of None, so change it to None
ifnotdbquery:
dbquery=None
try:
res=run_sql("UPDATE collection SET dbquery=%s WHERE id=%s",(dbquery,colID))
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))
ifres1[0][0]==res2[0][0]:
return(0,(1,"Cannot rearrange the selected fields, either rearrange by name or use the mySQL client to fix the problem."))
else:
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(1,"")
exceptException,e:
return(0,e)
defswitch_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))
ifres1[0][0]==res2[0][0]:
return(0,(1,"Cannot rearrange the selected fields, either rearrange by name or use the mySQL client to fix the problem."))
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(1,"")
exceptException,e:
return(0,e)
defswitch_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))
ifres1[0][0]==res2[0][0]:
return(0,(1,"Cannot rearrange the selected fields, either rearrange by name or use the mySQL client to fix the problem."))
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))