Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tmpl_draw_titlebar(self, ln, title, guideurl, extraname="", extraurl=""):
"""Draws an html title bar
- 'title' *string* - The name of the titlebar
- 'guideurl' *string* - The relative url of the guide relative to this section
- 'extraname' *string* - The name of an extra function
- 'extraurl' *string* - The relative url to an extra function
"""
_ = gettext_set_language(ln)
guidetitle = _("See Guide")
titlebar = """ <table class="table"><tbody><tr><th>"""
titlebar += """%s<small>[<a href="%s/%s" title="%s">?</a>]</small>""" % (title, guidetitle, CFG_SITE_URL, guideurl)
if extraname and extraurl:
titlebar += self.tmpl_button_link(extraname, CFG_SITE_URL + extraurl)
titlebar += """</th></tr></tbody></table>"""
return titlebar
@param cmtid: id of comment (int)
@param category: category (see webbasket_config) (str)
@param topic: nb of topic currently displayed (int)
@param group: id of group baskets currently displayed (int)
@param ln: language"""
argd = wash_urlargd(form, {'category': (str, cfg['CFG_WEBBASKET_CATEGORIES']['PRIVATE']),
'topic': (str, ""),
'group': (int, 0),
'bskid': (int, 0),
'recid': (int, 0),
'cmtid': (int, 0),
'of' : (str, ''),
'ln': (str, CFG_SITE_LANG)})
_ = gettext_set_language(argd['ln'])
uid = getUid(req)
if uid == -1 or CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
return page_not_authorized(req, "../yourbaskets/delete_note",
navmenuid = 'yourbaskets')
if isGuestUser(uid):
return redirect_to_url(req, "%s/youraccount/delete_note%s" % (
CFG_SITE_SECURE_URL,
make_canonical_urlargd({
'referer' : "%s/yourbaskets/display%s" % (
CFG_SITE_SECURE_URL,
make_canonical_urlargd(argd, {})),
"ln" : argd['ln']}, {})))
user_info = collect_user_info(req)
def external_collection_overview(self, lang=CFG_SITE_LANG, engine_list=()):
"""Prints results overview box with links to particular collections below.
lang: The language to display
engine_list: The external engines to be used"""
if len(engine_list) < 1:
return ""
_ = gettext_set_language(lang)
out = """
<table class="externalcollectionsresultsbox">
<thead>
<tr>
<th class="externalcollectionsresultsboxheader"><strong>%s</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td class="externalcollectionsresultsboxbody"> """ % _("External collections results overview:")
for engine in engine_list:
internal_name = get_link_name(engine.name)
name = _(engine.name)
out += """<strong><a href="#%(internal_name)s">%(name)s</a></strong><br>""" % locals()</td></tr></tbody></table>
def perform_request_groups_display(uid, infos=[], warnings = [], \
ln=CFG_SITE_LANG):
"""Display all the groups the user belongs to.
@param uid: user id
@param info: info about last user action
@param ln: language
@return: body with warnings
"""
_ = gettext_set_language(ln)
body = ""
body_admin = display_admin_groups(uid, ln)
body_member = display_member_groups(uid, ln)
body_external = display_external_groups(uid, ln)
body = websession_templates.tmpl_display_all_groups(infos=infos,
admin_group_html=body_admin,
member_group_html=body_member,
external_group_html=body_external,
warnings=warnings,
ln=ln)
return body
def answer(self, req, user_info, of, cc, colls_to_search, p, f, search_units, ln):
"""
Answer question given by context.
Return (relevance, html_string) where relevance is integer
from 0 to 100 indicating how relevant to the question the
answer is (see C{CFG_WEBSEARCH_SERVICE_MAX_SERVICE_ANSWER_RELEVANCE} for details) ,
and html_string being a formatted answer.
"""
from invenio.legacy.search_engine import \
get_permitted_restricted_collections, \
get_coll_i18nname, \
collection_i18nname_cache, \
collection_restricted_p
_ = gettext_set_language(ln)
# stem search units. remove those with field
# TODO: search in hosted collection names too
# TODO: ignore unattached trees
# TODO: use synonyms
if f or (CFG_WEBSEARCH_COLLECTION_NAMES_SEARCH < 0) or \
(CFG_WEBSEARCH_COLLECTION_NAMES_SEARCH == 0 and cc != CFG_SITE_NAME):
return (0, '')
words = [stem(unit[1], ln) for unit in search_units if unit[2] in ('', 'collection')] # Stemming
if not words:
return (0, '')
permitted_restricted_collections = get_permitted_restricted_collections(user_info)
cache = self.get_data_cache()
def not_authorized(self, req, form):
"""Displays page telling the user that
he is not authorised to access the resource"""
argd = wash_urlargd(form, {})
# load the right message language
language = argd["ln"]
_ = gettext_set_language(language)
text = _("You are not authorised to access this resource.")
return page_not_authorized(req = req, ln = language, text = text)
def get_users_by_status(grpID, status, ln=CFG_SITE_LANG):
"""Get the list of users with the given status.
@return: ((id, nickname),) nickname= user # uid if
the user has no nickname
"""
_ = gettext_set_language(ln)
res = run_sql("""SELECT ug.id_user, u.nickname
FROM user_usergroup ug, "user" u
WHERE ug.id_usergroup = %s
AND ug.id_user=u.id
AND user_status = %s""",
(grpID, status))
users = []
if res:
for (mid, nickname) in res:
nn = nickname
if not nickname:
nn = _("user") + "#%i" % mid
users.append((mid, nn))
return tuple(users)
action='',
ln=CFG_SITE_LANG):
"""
Interface to feature a record
Used to list, add and remove featured records of the journal.
Parameters:
journal_name - the journal for which the article is featured
recid - the record affected by 'action'
img_url - the URL to image displayed with given record
(only when action == 'add')
action - One of ['', 'add', 'askremove', _('Remove'), _('Cancel')]
ln - language
"""
_ = gettext_set_language(ln)
if action == 'add':
result = add_featured_record(journal_name, recid, img_url)
if result == 0:
msg ='''<span style="color:#0f0">Successfully featured
<a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a>.
Go to the <a href="%(CFG_SITE_URL)s/journal/%(name)s">%(name)s journal</a> to
see the result.</span>''' % {'CFG_SITE_URL': CFG_SITE_URL,
'CFG_SITE_RECORD': CFG_SITE_RECORD,
'name': journal_name,
'recid': recid}
elif result == 1:
msg = '''<span style="color:#f00"><a href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/%(recid)s">record %(recid)s</a> is already featured. Choose another one or remove it first.</span>''' % \
{'CFG_SITE_URL': CFG_SITE_URL,
'CFG_SITE_RECORD': CFG_SITE_RECORD,
'recid': recid}
def perform_request_edit_group(uid,
grpID,
warnings=[],
ln=CFG_SITE_LANG):
"""Return html for group editing.
@param uid: user ID
@param grpID: ID of the group
@param warnings: warnings
@param ln: language
@return: body with warnings
"""
body = ""
_ = gettext_set_language(ln)
user_status = db.get_user_status(uid, grpID)
if not len(user_status):
try:
raise InvenioWebSessionError(_('Sorry, there was an error with the database.'))
except InvenioWebSessionError as exc:
register_exception()
body = websession_templates.tmpl_error(exc.message, ln)
return body
elif user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS['ADMIN']:
try:
raise InvenioWebSessionError(_('Sorry, you do not have sufficient rights on this group.'))
except InvenioWebSessionError as exc:
register_exception()
body = websession_templates.tmpl_error(exc.message, ln)
return body
group_infos = db.get_group_infos(grpID)[0]
def perform_request_harvest_record(oai_src_id=None, ln=CFG_SITE_LANG, record_id=None, uid=None, confirm=0, enable_reporting=True):
""" Request for harvesting a new record """
_ = gettext_set_language(ln)
if oai_src_id is None:
return oaiharvest_templates.tmpl_print_warning(ln, _("No OAI source ID selected."))
result = ""
guideurl = "help/admin/oaiharvest-admin-guide"
result += oaiharvest_templates.tmpl_output_menu(ln, oai_src_id, guideurl)
result += oaiharvest_templates.tmpl_draw_titlebar(ln=ln,
title=_(
"Record OAI IDs ( as recognized by the data source )"),
guideurl=guideurl)
record_str = ""
if record_id:
record_str = str(record_id)
# We enable reporting by default, unless user specifies otherwise.
if confirm in (1, "1") and not enable_reporting:
enable_reporting = False