<dd>To make the rank method visible in the search interface for a collection,
choose the wanted collection and press the "Enable" button.</dd>
<dt>Disable for:</dt>
<dd>To hide the rank method from the search interface for a collection,
choose the wanted collection and press the "Disable" button.</dd>
<dt>'%s' is currently enabled for the following collections:</dt>
""" % rnkname
coll = get_rnkmethod_collections(rnkid)
output += """<dd>"""
if not coll:
output += """No collections"""
else:
for id, name in coll:
output += """%s, """ % name
output += """</dd>"""
output += """
</dl>
"""
coll = get_collections()
coll2 = dict(get_rnkmethod_collections(rnkid))
coll = filter(lambda x: not coll2.has_key(x[0]), coll)
if coll:
text = """
<span class="adminlabel">Enable for:</span>
<select name="collid" class="admin_w200">
"""
for id, name in coll:
text += """<option value="%s" %s>%s</option>""" % (id, (func in ["0", 0] and confirm in ["0", 0] and int(collid) == int(id)) and 'selected="selected"' or '' , name)
output += """<span class="info">Rank method '%s' could not be enabled for collection '%s'</span>""" % (rnkname[0], get_collections(collid)[0][1])
coll = get_rnkmethod_collections(rnkid)
if coll:
text = """
<span class="adminlabel">Disable for:</span>
<select name="collid" class="admin_w200">
"""
for id, name in coll:
text += """<option value="%s" %s>%s</option>""" % (id, (func in ["1", 1] and confirm in ["0", 0] and int(collid) == int(id)) and 'selected="selected"' or '' , name)
"""form to add a new rank method with these values:
"""
subtitle = 'Step 1 - Create new rank method'
output = """
<dl>
<dt>BibRank code:</dt>
<dd>A unique code that identifies a rank method, is used when running the bibrank daemon and used to name the configuration file for the method.
</br>The template files includes the necessary parameters for the chosen rank method, and only needs to be edited with the correct tags and paths.
</br>For more information, please go to the <a href="%s/admin/bibrank/guide.html">BibRank guide</a> and read the section about adding a rank method</dd>
text += """<span class="info"></br>Configuration file created using '%s' as template.</span>""" % template
else:
text += """<span class="info"></br>Empty configuration file created.</span>"""
except StandardError, e:
text += """<span class="info"></br>Sorry, could not create configuration file: '%s/bibrank/%s.cfg', either because it already exists, or not enough rights to create file. </span>""" % (etcdir, get_rnkmethodcode(rnkid)[0][0])
text += """</br><span class="info">Please create the file in the path given.</span>"""
else:
text = """<span class="info">Sorry, could not add rank method, rank method with the same BibRank code probably exists.</span>"""
output += text
elif not rnkcode and confirm in ["0", 0]:
output += """<span class="info">Sorry, could not add rank method, not enough data submitted.</span>"""
<dd>When changing the BibRank code of a rank method, you must also change any scheduled tasks using the old value.
</br>For more information, please go to the <a href="%s/admin/bibrank/guide.html">BibRank guide</a> and read the section about modifying a rank method's BibRank code.</dd>
text += """<span class="info">Cannot load file, either it does not exist, or not enough rights to read it: '%s/bibrank/%s.cfg'</span>""" % (etcdir, get_rnkmethodcode(rnkid)[0][0])
text += """</br><span class="info">Please create the file in the path given.</span>"""
output += createhiddenform(action="modifyrank",
text=text,
rnkid=rnkid,
button="Modify",
confirm=0)
text = ""
if rnkcode and confirm in ["0", 0] and get_rnkmethodcode(rnkid)[0][0] != rnkcode:
subtitle = 'Step 2 - Confirm modification of configuration'
text += "Modify rank method '%s' with old code '%s' and set new code '%s'." % (get_rnkmethodname(rnkid, ln)[0][0], get_rnkmethodcode(rnkid)[0][0], rnkcode)
if cfgfile and confirm in ["0", 0]:
subtitle = 'Step 2 - Confirm modification of configuration'
text += "</br>Modify configuration file"
if (rnkcode or cfgfile) and confirm in ["0", 0] and not template:
output += createhiddenform(action="modifyrank",
text=text,
rnkid=rnkid,
rnkcode=rnkcode,
cfgfile=cfgfile,
button="Confirm",
confirm=1)
if rnkcode and confirm in ["1", 1] and get_rnkmethodcode(rnkid)[0][0] != rnkcode:
oldcode = get_rnkmethodcode(rnkid)[0][0]
result = modify_rankmethod(rnkid, rnkcode)
subtitle = "Step 3 - Result"
if result:
text = """<span class="info">Rank method '%s' modified, new code is '%s'.</span>""" % (get_rnkmethodname(rnkid, ln)[0][0], rnkcode)
text = """<span class="info"></br>Configuration file modified: '%s/bibrank/%s.cfg'</span>""" % (etcdir, get_rnkmethodcode(rnkid)[0][0])
except StandardError, e:
text = """<span class="info"></br>Sorry, could not modify configuration file, please check for rights to do so: '%s/bibrank/%s.cfg'</span>""" % (etcdir, get_rnkmethodcode(rnkid)[0][0])
text += """</br><span class="info">Please modify the file manually.</span>"""
output += text
finoutput = addadminbox(subtitle, [output])
output = ""
text = """
<span class="adminlabel">Select</span>
<select name="template" class="admin_w200">
"""
templates = get_templates()
for templ in templates:
text += """<option value="%s" %s>%s</option>""" % (templ, template == templ and 'selected="selected"' or '', templ[9:len(templ)-4])
text += """</select></br>"""
output += createhiddenform(action="modifyrank",
text=text,
rnkid=rnkid,
button="Show template",
confirm=0)
try:
if template:
textarea = ""
text = """<span class="adminlabel">Content:</span>"""
<dd>When deleting a rank method, you also deletes all data related to the rank method, like translations, which collections
it was attached to and the data necessary to rank the searchresults. Any scheduled tasks using the deleted rank method will also stop working.
</br></br>For more information, please go to the <a href="%s/admin/bibrank/guide.html">BibRank guide</a> and read the section regarding deleting a rank method.</dd>
</dl>
</strong>
</span>
""" % weburl
if rnkid:
if confirm in ["0", 0]:
rnkname = get_rnkmethodname(rnkid, ln)[0]
subtitle = 'Step 1 - Confirm deletion'
text = """Delete rank method '%s'.""" % (rnkname)
output += createhiddenform(action="deleterank",
text=text,
rnkid=rnkid,
confirm=1)
elif confirm in ["1", 1]:
try:
rnkname = get_rnkmethodname(rnkid, ln)[0]
rnkcode = get_rnkmethodcode(rnkid)[0][0]
result = delete_rankmethod(rnkid)
subtitle = "Step 2 - Result"
if result:
text = """<span class="info">Rank method '%s' deleted</span>""" % rnkname
text = """Cannot load file, either it does not exist, or not enough rights to read it."""
output += addadminbox(subtitle, [text])
return output
def get_rnkmethods(ln=cdslang, type=''):
"""Returns a list of all rank methods, either with the name in the current language, the default language, or just the 'code'
ln - a language supported by cdsware
type - the type of value wanted, like 'ln', 'sn'"""
if not type:
type = getmainnametype()
try:
res = run_sql("SELECT id_rnkMETHOD,value FROM rnkMETHODNAME where type='%s' and ln='%s'" % (type,ln))
if ln != cdslang:
res1 = run_sql("SELECT id_rnkMETHOD,value FROM rnkMETHODNAME WHERE ln='%s' and type='%s'" % (cdslang, type))
res2 = dict(res)
result = filter(lambda x: not res2.has_key(x[0]), res1)
res = res + result
res1 = run_sql("SELECT id,name FROM rnkMETHOD")
res2 = dict(res)
result = filter(lambda x: not res2.has_key(x[0]), res1)
res = res + result
return res
except StandardError, e:
raise StandardError
def get_rnkmethodname(rnkid,ln=cdslang, type=''):
"""Returns a name for the rankmethod. If a translation in the current language does not exist, the default language will be tried, and if not, the name from rnkMETHOD
will be returned.
rnkid - id from rnkMETHOD
ln - a language supported by cdsware
type - the type of value wanted, like 'ln', 'sn'"""
if not type:
type = getmainnametype()
try:
res = run_sql("SELECT value FROM rnkMETHODNAME where type='%s' and ln='%s' and id_rnkMETHOD=%s" % (type, ln, rnkid))
if not res:
res = run_sql("SELECT value FROM rnkMETHODNAME WHERE ln='%s' and id_rnkMETHOD=%s and type='%s'" % (cdslang, rnkid, type))
if not res:
res = run_sql("SELECT name FROM rnkMETHOD where id=%s" % rnkid)
return res
except StandardError, e:
raise StandardError
def get_rnkmethodnames(rnkid, ln, type=''):
"""Returns the value from rnkMETHODNAME based on arguments
rnkid - id from rnkMETHOD
ln - a language supported by cdsware
type - the type of value wanted, like 'ln', 'sn'"""
if not type:
type = getmainnametype()
try:
res = run_sql("SELECT value FROM rnkMETHODNAME where type='%s' and ln='%s' and id_rnkMETHOD=%s" % (type, ln, rnkid))
return res
except StandardError, e:
return ()
def get_rnkmethodcode(rnkid):
"""Returns the name from rnkMETHOD based on argument
rnkid - id from rnkMETHOD"""
try:
res = run_sql("SELECT name FROM rnkMETHOD where id=%s" % (rnkid))
return res
except StandardError, e:
return ()
def get_rnkmethod(rnkid=''):
"""Return one or all rank methods
rnkid - return the rank method given, or all if not given"""
try:
if rnkid:
res = run_sql("SELECT id,name,last_updated,star_category_ranges from rnkMETHOD WHERE id=%s" % rnkid)
else:
res = run_sql("SELECT id,name,last_updated,star_category_ranges from rnkMETHOD")
return res
except StandardError, e:
return ()
def get_translations(rnkid):
"""Returns the translations in rnkMETHODNAME for a rankmethod
rnkid - the id of the rankmethod from rnkMETHOD """
try:
res = run_sql("SELECT ln, type, value FROM rnkMETHODNAME where id_rnkMETHOD=%s ORDER BY ln,type" % (rnkid))
return res
except StandardError, e:
return ()
def getnametypes():
"""Return a list of the various translationnames for the rank methods"""
"""add or modify translations for a given rank method
rnkid - the id of the rank method from rnkMETHOD table
sel_lang - the languge to be changed
types - the language types
trans - the translations, in same order as in types """
try:
for nr in range(0,len(trans)):
res = run_sql("SELECT value FROM rnkMETHODNAME WHERE id_rnkMETHOD=%s AND type='%s' AND ln='%s'" % (rnkid, types[nr][0][0] , sel_lang))
if res:
res = run_sql("UPDATE rnkMETHODNAME SET value='%s' WHERE id_rnkMETHOD=%s AND type='%s' AND ln='%s'" % (MySQLdb.escape_string(trans[nr]), rnkid, types[nr][0][0] , sel_lang))
else:
res = run_sql("INSERT INTO rnkMETHODNAME(id_rnkMETHOD, type, ln, value) VALUES (%s,'%s','%s','%s')" % (rnkid, types[nr][0][0] , sel_lang, MySQLdb.escape_string(trans[nr])))