def users(req, ln=CFG_SITE_LANG): """ View a list of all the users that have been reported, sorted by most reported @param req: request object to obtain user information @param ln: language """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = getnavtrail() navtrail_previous_links += ' > <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL navtrail_previous_links += _("WebComment Admin") + '</a>' try: uid = getUid(req) except Error: return page(title=_("Internal Error"), body = create_error_box(req, verbose=0, ln=ln), description="%s - Internal Error" % CFG_SITE_NAME, keywords="%s, Internal Error" % CFG_SITE_NAME, language=ln, req=req) (auth_code, auth_msg) = check_user(req,'cfgwebcomment') if (auth_code != 'false'): return page(title=_("View all reported users"), body=perform_request_users(ln=ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def index(req, ln=CFG_SITE_LANG): """ Menu of admin options @param ln: language """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = getnavtrail() navtrail_previous_links +=' > <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL navtrail_previous_links += _("WebComment Admin") + '</a>' try: uid = getUid(req) except Error: return page(title=_("Internal Error"), body = create_error_box(req, verbose=0, ln=ln), description="%s - Internal Error" % CFG_SITE_NAME, keywords="%s, Internal Error" % CFG_SITE_NAME, language=ln, req=req) (auth_code, auth_msg) = check_user(req, 'cfgwebcomment') if (auth_code != 'false'): return page(title=_("WebComment Admin"), body=perform_request_index(ln=ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def addexistingportalbox(req, colID, ln=CFG_SITE_LANG, pbxID=-1, score=0, position='', sel_ln='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = check_user(req,'cfgwebsearch') if not auth[0]: 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, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page(title='Authorization failure', uid=uid, body=adderrorbox('try to login first', datalist=["""You are not a user authorized to perform admin tasks, try to <a href="%s/youraccount/login?referer=%s/admin/websearch/websearchadmin.py/">login</a> with another account.""" % (CFG_SITE_SECURE_URL, CFG_SITE_URL)]), navtrail= navtrail_previous_links, lastupdated=__lastupdated__)
def resolve_doi(req, doi, ln=CFG_SITE_LANG, verbose=0): """ Redirect to given DOI, or display error page when DOI cannot be resolved. """ _ = gettext_set_language(ln) # Fetch user ID: try: uid = getUid(req) except Error: register_exception(req=req, alert_admin=True) return page(title=_("Internal Error"), body=create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % CFG_SITE_NAME, keywords="%s, Internal Error" % CFG_SITE_NAME, language=ln, req=req, navmenuid='search') # Resolve DOI recids = perform_request_search(p='doi:"%s"' % doi, of="id", verbose=verbose) recids = [recid for recid in recids if doi.lower() in \ [doi.lower() for doi in get_record(recid).get('doi', '') if doi]] # Answer if len(recids) == 1: # Found unique matching record return redirect_to_url(req, CFG_SITE_URL + '/' + CFG_SITE_RECORD + '/' + str(recids[0])) elif len(recids) == 0: # No corresponding record found page_body = '<p>' + (_("Sorry, DOI %s could not be resolved.") % \ ('<strong>' + str(doi) + '</strong>')) + '</p>' if req.header_only: raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND return page(title=_('DOI "%s" Not Found') % cgi.escape(doi), body=page_body, description=(CFG_SITE_NAME + ' - ' + _("Not found") + ': ' + cgi.escape(str(doi))), keywords="%s" % CFG_SITE_NAME, uid=uid, language=ln, req=req, navmenuid='search') else: # Found multiple matching records try: raise Exception('DOI "%s" matched multiple records (%s) -- Please check' % (doi, ', '.join([str(recid) for recid in recids]))) except Exception, e: register_exception(req=req, alert_admin=True) page_body = websearch_templates.tmpl_multiple_dois_found_page(doi, recids, ln) return page(title=_('Found multiple records matching DOI %s') % cgi.escape(doi), body=page_body, description=(CFG_SITE_NAME + ' - ' + _("Found multiple records matching DOI") + ': ' + cgi.escape(str(doi))), keywords="%s" % CFG_SITE_NAME, uid=uid, language=ln, req=req, navmenuid='search')
def del_com(req, ln=CFG_SITE_LANG, action="delete", **hidden): """ private function Delete a comment @param req: request object to obtain user information @param ln: language @param **hidden: ids of comments to delete sent as individual variables comidX=on, where X is id """ ln = wash_language(ln) action = wash_url_argument(action, 'str') _ = gettext_set_language(ln) navtrail_previous_links = getnavtrail() navtrail_previous_links += ' > <a class="navtrail" href="%s/admin/webcomment/webcommentadmin.py/">' % CFG_SITE_URL navtrail_previous_links += _("WebComment Admin") + '</a>' try: uid = getUid(req) except Error: return page(title=_("Internal Error"), body = create_error_box(req, verbose=0, ln=ln), description="%s - Internal Error" % CFG_SITE_NAME, keywords="%s, Internal Error" % CFG_SITE_NAME, language=ln, req=req) (auth_code, auth_msg) = check_user(req,'cfgwebcomment') if (auth_code != 'false'): comIDs = [] args = hidden.keys() for var in args: try: comIDs.append(int(var.split('comid')[1])) except: pass if action == 'delete': body = perform_request_del_com(ln=ln, comIDs=comIDs) title = _("Delete comments") elif action == 'unreport': body = suppress_abuse_report(ln=ln, comIDs=comIDs) title = _("Suppress abuse reports") elif action == 'undelete': body = perform_request_undel_com(ln=ln, comIDs=comIDs) title = _("Undelete comments") else: redirect_to_url(req, CFG_SITE_URL + '/admin/webcomment/webcommentadmin.py') return page(title=title, body=body, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def kb_show(req, kb, sortby="to", ln=CFG_SITE_LANG, startat=0, search=""): """ Shows the content of the given knowledge base id. Check for authentication and kb existence. Before displaying the content of the knowledge base, check if a form was submitted asking for adding, editing or removing a value. @param ln language @param kb the kb id to show @param sortby the sorting criteria ('from' or 'to') @param startat the number from which start showing mapping rules in kb @param search search for this string in the kb """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = ''' > <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases")) try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge') if not auth_code: kb_id = wash_url_argument(kb, 'int') kb_name = bibknowledge.get_kb_name(kb_id) if kb_name is None: return page(title=_("Unknown Knowledge Base"), body = "", language=ln, navtrail = navtrail_previous_links, errors = [("ERR_KB_ID_UNKNOWN", kb)], lastupdated=__lastupdated__, req=req) return page(title=_("Knowledge Base %s" % kb_name), body=bibknowledgeadminlib.perform_request_knowledge_base_show(ln=ln, kb_id=kb_id, sortby=sortby, startat=startat, search_term=search), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def format_template_show_attributes(req, bft, ln=CFG_SITE_LANG, new=0): """ Page for template name and descrition attributes edition. This is also the first page shown when a format template has just been added. In that case new is different from False and we can offer specific option to user (for ex let him make a duplicate of existing template). @param req: the request object @param ln: language @param bft: the name of the template to show @param new: if "False", the template has not just been added @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail(''' > <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates"))) try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: format_template = wash_url_argument(bft, 'str') format_name = bibformat_engine.get_format_template_attrs(bft)['name'] is_new = wash_url_argument(new, 'int') if not bibformatadminlib.can_read_format_template(bft): #No read permission try: raise InvenioBibFormatError(_('Format template %s cannot not be read. %s') % (format_template, "")) except InvenioBibFormatError, exc: register_exception(req=req) return page(title=_("Restricted Format Template"), body = """You don't have permission to view this format template.""", language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) return page(title=_("Format Template %s Attributes"%format_name), body=bibformatadminlib.perform_request_format_template_show_attributes(bft, ln=ln, new=is_new), uid=uid, language=ln, navtrail = navtrail_previous_links , lastupdated=__lastupdated__, req=req)
def compare_revisions(self, req, form): """Handle the compare revisions request""" argd = wash_urlargd(form, { \ 'ln': (str, CFG_SITE_LANG), \ 'rev1' : (str, ''), \ 'rev2' : (str, ''), \ 'recid': (int, 0)}) ln = argd['ln'] uid = getUid(req) _ = gettext_set_language(ln) # Checking if currently logged user has permission to perform this request auth_code, auth_message = acc_authorize_action(req, 'runbibedit') if auth_code != 0: return page_not_authorized(req=req, referer="/edit", text=auth_message, navtrail=navtrail) recid = argd['recid'] rev1 = argd['rev1'] rev2 = argd['rev2'] ln = argd['ln'] body, errors, warnings = perform_request_compare(ln, recid, rev1, rev2) return page(title = _("Comparing two record revisions"), body = body, errors = errors, warnings = warnings, uid = uid, language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req)
def new_ticket(self, req, form): """handle a edit/new_ticket request""" argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG), 'recid': (int, 0)}) ln = argd['ln'] _ = gettext_set_language(ln) auth_code, auth_message = acc_authorize_action(req, 'runbibedit') if auth_code != 0: return page_not_authorized(req=req, referer="/edit", text=auth_message, navtrail=navtrail) uid = getUid(req) if argd['recid']: (errmsg, url) = perform_request_newticket(argd['recid'], uid) if errmsg: return page(title = _("Failed to create a ticket"), body = _("Error")+": "+errmsg, errors = [], warnings = [], uid = uid, language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req) else: #redirect.. redirect_to_url(req, url)
def index(self, req, form): """ The function called by default""" argd = wash_urlargd(form, { self._JSON_DATA_KEY: (str, ""), }) # load the right message language language = argd["ln"] _ = gettext_set_language(language) # check user credentials (auth_code, auth_msg) = acc_authorize_action(req, "runbibeditmulti") if 0 != auth_code: return page_not_authorized(req = req, ln = language, text = auth_msg) if argd[self._JSON_DATA_KEY]: return self._process_json_request(form, req) body = multi_edit_engine.perform_request_index(language) title = _("Multi-Record Editor") metaheaderadd = multi_edit_engine.get_scripts() metaheaderadd = metaheaderadd + multi_edit_engine.get_css() return page(title = title, metaheaderadd = metaheaderadd, body = body, req = req, language = language)
def display_job_result(self, req, form): """Displays the results of a job""" argd = wash_urlargd(form, { "result_id": (int, JobResult.ID_MISSING), "output_format" : (int, Job.OUTPUT_FORMAT_MISSING) }) # load the right message language language = argd["ln"] _ = gettext_set_language(language) self._check_user_credentials(req, language) user_id = self._get_user_id(req) job_result_id = argd["result_id"] output_format = argd["output_format"] title = _("Export Job Result") try: body = perform_request_display_job_result(job_result_id = job_result_id, output_format = output_format, user_id = user_id, language = language) except AccessDeniedError: self._redirect_to_not_authorised_page(req, language) return page(title = title, metaheaderadd = get_css(), body = body, req = req, navmenuid = "fieldexporter", titleprologue = get_navigation_menu(language), navtrail = self._NAVTRAIL_EXPORT, language = language)
def modifycollectiontree(req, colID, ln=CFG_SITE_LANG, move_up='', move_down='', move_from='', move_to='', delete='', rtype='', callback='yes', confirm=0): navtrail_previous_links = wsc.getnavtrail() + """> <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = check_user(req,'cfgwebsearch') if not auth[0]: return page(title="WebSearch Admin", 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, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def format_template_show_dependencies(req, bft, ln=CFG_SITE_LANG): """ Show the dependencies (on elements) of the given format. @param req: the request object @param ln: language @param bft: the filename of the template to show @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail(''' > <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates"))) try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: format_template = wash_url_argument(bft, 'str') format_name = bibformat_engine.get_format_template_attrs(bft)['name'] return page(title=_("Format Template %s Dependencies" % format_name), body=bibformatadminlib.perform_request_format_template_show_dependencies(bft, ln=ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg)
def error_page(req, ln=CFG_SITE_LANG, verbose=1): return page(title="Internal Error", body = create_error_box(req, verbose=verbose, ln=ln), description="%s - Internal Error" % CFG_SITE_NAME, keywords="%s, Internal Error" % CFG_SITE_NAME, language=ln, req=req)
def modifyfieldvalue(req, colID, fldID, fldvID, ln=CFG_SITE_LANG, name='', value='', callback="yes", confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = check_user(req,'cfgwebsearch') if not auth[0]: return page(title="Edit Collection", body=wsc.perform_modifyfieldvalue(colID=colID, fldID=fldID, fldvID=fldvID, ln=ln, name=name, value=value, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, req=req, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def dialog_box(req, url="", ln=CFG_SITE_LANG, navtrail="", title="", message="", options=None): """ Returns a dialog box with a given title, message and options. Used for asking confirmation on actions. The page that will receive the result must take 'chosen_option' as parameter. @param url the url used to submit the options chosen by the user @param options the list of labels for the buttons given as choice to user """ import invenio bibformat_templates = invenio.template.load('bibformat') if not options: options = [] return page(title="", body = bibformat_templates.tmpl_admin_dialog_box(url, ln, title, message, options), language=ln, lastupdated=__lastupdated__, navtrail=navtrail, req=req)
def format_element_show_dependencies(req, bfe, ln=CFG_SITE_LANG): """ Shows format element dependencies @param req: the request object @param req: the request object @param bfe: the name of the bfe to show @param ln: language @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail(''' > <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln , _("Format Elements Documentation"))) try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: bfe = wash_url_argument(bfe, 'str') return page(title=_("Format Element %s Dependencies" % bfe), body=bibformatadminlib.perform_request_format_element_show_dependencies(bfe=bfe, ln=ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def modifysynonymkb(req, idxID, ln=CFG_SITE_LANG, idxKB='', idxMATCH='', callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() navtrail_previous_links += """> <a class="navtrail" href="%s/admin/bibindex/bibindexadmin.py/index">Manage Indexes</a>""" % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req,'cfgbibindex') if not auth[0]: return page(title="Edit Index", body=bic.perform_modifysynonymkb(idxID=idxID, ln=ln, idxKB=idxKB, idxMATCH=idxMATCH, callback=callback, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def dialog_box(req, url="", ln=CFG_SITE_LANG, navtrail="", title="", message="", options=[]): """ Returns a dialog box with a given title, message and options. Used for asking confirmation on actions. The page that will receive the result must take 'chosen_option' as parameter. @param req: the request object @param url: the url used to submit the options chosen by the user @param ln: language @param navtrail: navigation trail @param title: title of the page/dialog @param message: message to display in the dialog box @param options: the list of labels for the buttons given as choice to user @return: a dialog page """ import invenio bibformat_templates = invenio.template.load("bibformat") return page( title="", body=bibformat_templates.tmpl_admin_dialog_box(url, ln, title, message, options), language=ln, lastupdated=__lastupdated__, navtrail=navtrail, req=req, )
def addtag(req, fldID, ln=CFG_SITE_LANG, name='', value='', recjson_value='', existing_tag=-1, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> <a class="navtrail" href="%s/admin/bibindex/bibindexadmin.py/field">Manage logical fields</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_addtag(fldID=fldID, ln=ln, existing_tag=existing_tag, value=value, recjson_value=recjson_value, name=name, callback=callback, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def metadata(self, req, form): """ Display Metadata file upload form """ argd = wash_urlargd(form, {'error': (int, 0), 'mode': (str, ""), 'submit_date': (str, "yyyy-mm-dd"), 'submit_time': (str, "hh:mm:ss")}) _ = gettext_set_language(argd['ln']) not_authorized = user_authorization(req) if not_authorized: return not_authorized uid = getUid(req) body = batchuploader_templates.tmpl_display_menu(argd['ln'], ref="metadata") body += batchuploader_templates.tmpl_display_web_metaupload_form(argd['ln'], argd['error'], argd['mode'], argd['submit_date'], argd['submit_time']) title = _("Metadata batch upload") return page(title = title, body = body, metaheaderadd = batchuploader_templates.tmpl_styles(), uid = uid, lastupdated = __lastupdated__, req = req, language = argd['ln'], navmenuid = "batchuploader")
def modifyportalbox(req, colID, ln=CFG_SITE_LANG, pbxID=-1, score='', position='', sel_ln='', title='', body='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = check_user(req,'cfgwebsearch') if not auth[0]: 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, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def format_elements_doc(req, ln=CFG_SITE_LANG): """ Main page for format elements documentation. Check for authentication and print format elements list. @param req: the request object @param ln: language @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail() try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: return page(title=_("Format Elements Documentation"), body=bibformatadminlib.perform_request_format_elements_documentation(ln=ln), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def index(req, p=""): auth_code, auth_message = acc_authorize_action(req, 'runsearchuser') if auth_code != 0: return page_not_authorized(req=req, text=auth_message) users = [] if p: users = run_sql( "SELECT id, nickname, email, last_login FROM user WHERE email<>'' AND nickname LIKE %s OR email LIKE %s OR id=%s ORDER BY email LIMIT 100", ('%%%s%%' % p, '%%%s%%' % p, p)) body = """ <form> <label for="searchuser">Search user:</label> <input name="p" id="searchuser" value="%s" /></input><input type="submit" value="Search" /> </form> """ % escape(p, True) if users: body += """<h2>Users found</h2> <p>This is the list of the first 100 users found matching the criteria.</p> <table border="1"> <thead><tr><th>ID</th><th>Nickname</th><th>Email</th><th>Last login</th><th>Profile info</th></tr></thead> <tbody> """ for user in users: body += """<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>""" % ( user[0], escape(user[1]), escape(user[2]), escape(str(user[3])), _get_personid_info(user[0])) body += """ </tbody> </table> """ return page(req=req, title="Search users", body=body)
def output_format_add(req, ln=CFG_SITE_LANG): """ Adds a new output format @param req: the request object @param ln: language @return: a web page (or redirection to a web page) """ ln = wash_language(ln) _ = gettext_set_language(ln) try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: bfo = bibformatadminlib.add_output_format() if bfo == None: return page(title=_("Cannot create output format"), body = """BibFormat cannot add an output format. Check output formats directory permissions.""", language=ln, lastupdated=__lastupdated__, req=req) redirect_to_url(req, "output_format_show_attributes?ln=%(ln)s&bfo=%(bfo)s" % {'ln':ln, 'bfo':bfo}) else: return page_not_authorized(req=req, text=auth_msg)
def output_formats_manage(req, ln=CFG_SITE_LANG, sortby="code"): """ Main page for output formats management. Check for authentication and print output formats list. @param req: the request object @param ln: language @param sortby: the sorting crieteria (can be 'code' or 'name') @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail() try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: sortby = wash_url_argument(sortby, 'str') return page(title=_("Manage Output Formats"), body=bibformatadminlib.perform_request_output_formats_management(ln=ln, sortby=sortby), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def format_templates_manage(req, ln=CFG_SITE_LANG, checking='0'): """ Main page for formats templates management. Check for authentication and print formats list. @param req: the request object @param ln: language @param checking: if 0, basic checking. Else perform extensive checking (time-consuming) @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail() try: uid = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: checking_level = wash_url_argument(checking, 'int') return page(title=_("Manage Format Templates"), body=bibformatadminlib.perform_request_format_templates_management(ln=ln, checking=checking_level), uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def tmpl_webjournal_error_box(self, ln, title, title_msg, msg): """ returns an error box for webjournal errors. """ _ = gettext_set_language(ln) title = _(title) title_msg = _(title_msg) msg = _(msg) mail_msg = _("Contact %(x_url_open)sthe administrator%(x_url_close)s") % { "x_url_open": '<a href="mailto:%s">' % CFG_SITE_SUPPORT_EMAIL, "x_url_close": "</a>", } box = """ <div style="text-align: center;"> <fieldset style="width:400px; margin-left: auto; margin-right: auto;"> <legend style="color:#a70509;background-color:#fff;"> <i>%s</i> </legend> <p style="text-align:center;">%s</p> <br/> <div style="text-align:right;"> %s </div> </fieldset> </div> """ % ( title_msg, msg, mail_msg, ) return page(title=title, body=box)
def unlinked(req): """ Return an id-ordered list of citation log entries of at most 10000 rows. """ from invenio.dbquery import run_sql from invenio.search_engine import get_fieldvalues, get_collection_reclist useful_personids1 = intbitset(run_sql("SELECT distinct personid FROM aidPERSONIDDATA WHERE tag LIKE 'extid:%'")) useful_personids2 = intbitset(run_sql("SELECT distinct personid from aidPERSONIDPAPERS where flag=2")) linked_personids = intbitset(run_sql("SELECT personid FROM aidPERSONIDDATA WHERE tag='extid:INSPIREID'")) names = dict(run_sql("SELECT personid, data FROM aidPERSONIDDATA WHERE tag='canonical_name'")) matched_names = [name.lower().strip() for name in get_fieldvalues(get_collection_reclist('HepNames'), '035__a')] personid_to_match = (useful_personids1 | useful_personids2) - linked_personids body = ['<ol>'] for personid in personid_to_match: name = names.get(personid, str(personid)) if name.lower().strip() in matched_names: continue body.append('<li><a href="%(siteurl)s/author/profile/%(bai)s" target="_blank">%(bai)s</a></li>' % { 'siteurl': escape(CFG_SITE_SECURE_URL, True), 'bai': escape(name, True)}) body.append('</ol>') body = '\n'.join(body) return page(req=req, body=body, title="Unlinked useful BAIs")
def addcollectiontotree(req, colID, ln=CFG_SITE_LANG, add_dad='', add_son='', rtype='', mtype='', callback='yes', confirm=-1): navtrail_previous_links = wsc.getnavtrail() + """> <a class="navtrail" href="%s/admin/websearch/websearchadmin.py/">WebSearch Admin</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = check_user(req,'cfgwebsearch') if not auth[0]: return page(title="WebSearch Admin", body=wsc.perform_addcollectiontotree(colID=colID, ln=CFG_SITE_LANG, add_dad=add_dad, add_son=add_son, rtype=rtype, callback=callback, confirm=confirm), uid=uid, language=ln, navtrail = navtrail_previous_links, req=req, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def display(self, req, form): """ Displays the Inbox of a given user @param ln: language @return: the page for inbox """ argd = wash_urlargd(form, {}) # Check if user is logged uid = getUid(req) if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1: return page_not_authorized(req, "%s/yourmessages/display" % \ (CFG_SITE_URL,), navmenuid="yourmessages") elif uid == -1 or isGuestUser(uid): return redirect_to_url( req, "%s/youraccount/login%s" % (CFG_SITE_SECURE_URL, make_canonical_urlargd( { 'referer': "%s/yourmessages/display%s" % (CFG_SITE_URL, make_canonical_urlargd(argd, {})), "ln": argd['ln'] }, {}))) _ = gettext_set_language(argd['ln']) user_info = collect_user_info(req) if not user_info['precached_usemessages']: return page_not_authorized(req, "../", \ text = _("You are not authorized to use messages.")) body = perform_request_display(uid=uid, ln=argd['ln']) return page(title=_("Your Messages"), body=body, navtrail=get_navtrail(argd['ln']), uid=uid, lastupdated=__lastupdated__, req=req, language=argd['ln'], navmenuid="yourmessages", secure_page_p=1)
def articles(req, i, mode='html'): try: i = int(i) assert 0 <= i < len(_AFFILIATIONS) except: raise SERVER_RETURN(HTTP_BAD_REQUEST) nation = _AFFILIATIONS[i] ret = [] page_title = "SCOAP3 Articles by authors from %s" % nation if mode == 'text': req.content_type = "text/plain; charset=utf8" req.headers_out['content-disposition'] = ( 'attachment; filename=%s.txt' % nation) else: req.content_type = "text/html" if mode == 'text': print >> req, page_title print >> req, "-" * len(page_title) query = _build_query(nation) for journal in CFG_JOURNALS: results = perform_request_search(p=query, cc=journal, of='intbitset') if not results: continue ret.append("<h2>%s (%s)</h2" % (escape(get_coll_i18nname(journal)), len(results))) ret.append("<p><ul>") if mode == 'text': print >> req, "" print >> req, get_coll_i18nname(journal) for recid in results: record = get_record(recid) title = record_get_field_value(record, '245', code='a') doi = record_get_field_value(record, '024', '7', code='a') if mode == 'text': print >> req, "http://dx.doi.org/%s" % doi li = ("<li><a href='http://dx.doi.org/{0}' " "target='_blank'>{1}</a>: {2}</li>") ret.append(li.format(escape(doi, True), escape(doi), title)) ret.append("</ul></p>") body = '\n'.join(ret) if mode == 'text': return "" return page(req=req, title=page_title, body=body)
def elementedit(req, elname, elmarccode=None, eltype=None, elsize=None, elrows=None, elcols=None, elmaxlength=None, \ elval=None, elfidesc=None, elmodifytext=None, elcommit="", ln=CFG_SITE_LANG): """Display the details of a WebSubmit ELEMENT in a Web form so that it can be viewed and/or edited. @param elname: unique name/ID for new check (if empty, Web form will be displayed) @param elmarccode: MARC Code for element @param eltype: type of element. @param elsize: size of element. @param elrows: number of rows in element. @param elcols: number of columns in element. @param elmaxlength: element maximum length. @param elval: element value. @param elfidesc: element description. @param elmodifytext: Modification text for the element. @param elcommit: flag variable used to determine whether to commit element modifications or whether to simply display a form containing element details. @param ln: language @return: page """ ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) (auth_code, auth_msg) = check_user(req, 'cfgwebsubmit') if not auth_code: ## user is authorised to use WebSubmit Admin: # Generate content (title, body, errors, warnings) = perform_request_edit_element(elname, elmarccode, eltype, \ elsize, elrows, elcols, elmaxlength, \ elval, elfidesc, elmodifytext, \ elcommit) return page(title = title, body = body, navtrail = get_navtrail(ln), uid = uid, lastupdated = __lastupdated__, req = req, language = ln, errors = errors, warnings = warnings) else: ## user is not authorised to use WebSubmit Admin: return page_not_authorized(req=req, text=auth_msg, navtrail=get_navtrail(ln))
def tmpl_webjournal_missing_info_box(self, req, ln, title, msg_title, msg): """ returns a box indicating that the given journal was not found on the server, leaving the opportunity to select an existing journal from a list. """ _ = gettext_set_language(ln) box_title = msg_title box_text = msg box_list_title = _("Available Journals") # todo: move to DB call find_journals = lambda path: [entry for entry in os.listdir(str(path)) \ if os.path.isdir(str(path)+str(entry))] try: all_journals = find_journals('%s/webjournal/' % CFG_ETCDIR) except: all_journals = [] mail_msg = _("Contact %(x_url_open)sthe administrator%(x_url_close)s") % \ {'x_url_open' : '<a href="mailto:%s">' % CFG_SITE_SUPPORT_EMAIL, 'x_url_close' : '</a>'} box = ''' <div style="text-align: center;"> <fieldset style="width:400px; margin-left: auto; margin-right:auto"> <legend style="color:#a70509;background-color:#fff;"> <i>%s</i> </legend> <p style="text-align:center;">%s</p> <h2 style="color:#0D2B88;">%s</h2> <ul class="webjournalBoxList"> %s </ul> <br/> <div style="text-align:right;"> %s </div> </fieldset> </div> ''' % (box_title, box_text, box_list_title, "".join([ '<li><a href="%s/journal/?name=%s">%s</a></li>' % (CFG_SITE_URL, journal, journal) for journal in all_journals ]), mail_msg) return page(req=req, title=title, body=box)
def viewhistoryday(req, oai_src_id=0, ln=CFG_SITE_LANG, confirm=0, year = None, month = None, day = None, start = 0): navtrail_previous_links = oha.getnavtrail(' > <a class="navtrail" href="%s/admin/bibharvest/oaiharvestadmin.py?ln=%s">OAI Harvest Admin Interface</a> ' % (CFG_SITE_URL, ln), ln=ln) d_date = datetime.datetime.now() if year == None: year = d_date.year if month == None: month = d_date.month if day == None: day = d_date.day try: uid = getUid(req) except Error, e: return page(title="OAI Harvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req)
def extract_references(self, req, form): """Refrences extraction page This page can be used for authors to test their pdfs against our refrences extraction process""" user_info = collect_user_info(req) # Handle the 3 POST parameters if 'pdf' in form and form['pdf'].value: pdf = form['pdf'].value references_xml = extract_from_pdf_string(pdf) elif 'arxiv' in form and form['arxiv'].value: url = make_arxiv_url(arxiv_id=form['arxiv'].value) references_xml = extract_references_from_url_xml(url) elif 'url' in form and form['url'].value: url = form['url'].value references_xml = extract_references_from_url_xml(url) elif 'txt' in form and form['txt'].value: txt = form['txt'].value references_xml = extract_references_from_string_xml(txt) else: references_xml = None # If we have not uploaded anything yet # Display the form that allows us to do so if not references_xml: out = self.extract_references_template() else: out = """ <style type="text/css"> #referenceinp_link { display: none; } </style> """ out += format_record(0, 'hdref', xml_record=references_xml.encode('utf-8'), user_info=user_info) # Render the page (including header, footer) return page(title='References Extractor', body=out, uid=user_info['uid'], req=req)
def actionadd(req, actid=None, actname=None, working_dir=None, status_text=None, actcommit="", ln=CFG_SITE_LANG): """Add a new action to the WebSubmit database. Web form for action details will be displayed if "actid" and "actname" are empty; else new action will be committed to websubmit. @param actid: unique id for new action (if empty, Web form will be displayed) @param actname: name of new action (if empty, Web form will be displayed) @param working_dir: action working directory for WebSubmit @param status_text: status text displayed at end of WebSubmit action @param ln: language @return: page """ ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) (auth_code, auth_msg) = check_user(req, 'cfgwebsubmit') if not auth_code: ## user is authorised to use WebSubmit Admin: # Generate content (title, body, errors, warnings) = perform_request_add_action(actid, actname, working_dir, status_text, actcommit) return page(title=title, body=body, navtrail=get_navtrail(ln), uid=uid, lastupdated=__lastupdated__, req=req, language=ln, errors=errors, warnings=warnings) else: ## user is not authorised to use WebSubmit Admin: return page_not_authorized(req=req, text=auth_msg, navtrail=get_navtrail(ln))
def customevent(self, req, form): """Custom event statistics page""" arg_format = { 'ids': (list, []), 'timespan': (str, "today"), 's_date': (str, ""), 'f_date': (str, ""), 'format': (str, SUITABLE_GRAPH_FORMAT), 'ln': (str, CFG_SITE_LANG) } for key in form.keys(): if key[:4] == 'cols': i = key[4:] arg_format['cols' + i] = (list, []) arg_format['col_value' + i] = (list, []) arg_format['bool' + i] = (list, []) argd = wash_urlargd(form, arg_format) ln = argd['ln'] user_info = collect_user_info(req) (auth_code, auth_msg) = acc_authorize_action(user_info, 'runwebstatadmin') if auth_code: return page_not_authorized( req, navtrail=self.navtrail % {'ln_link': (ln != CFG_SITE_LANG and '?ln=' + ln) or ''}, text=auth_msg, navmenuid='custom event', ln=ln) body = perform_display_customevent(argd['ids'], argd, req=req, ln=ln) return page(title="Custom event", body=body, navtrail="""<a class="navtrail" href="%s/stats/%s">Statistics</a>""" % \ (CFG_SITE_URL, (ln != CFG_SITE_LANG and '?ln=' + ln) or ''), description="CDS Personalize, Statistics, Custom event", keywords="CDS, statistics, custom event", req=req, lastupdated=__lastupdated__, navmenuid='custom event', language=ln)
def verify(req, fname, ln=CFG_SITE_LANG): """verify syntax by calling an external checking program""" ln = wash_language(ln) _ = gettext_set_language(ln) (admin_ok, uid) = is_admin(req) # sanity check for fname: fname = os.path.basename(fname) navtrail = """<a class="navtrail" href="%s/help/admin">%s</a>""" % \ (CFG_SITE_SECURE_URL, _("Admin Area")) navtrail += """> <a class="navtrail" href="%s/admin/bibcheck/bibcheckadmin.py/">BibCheck Admin</a> """ % CFG_SITE_SECURE_URL errors = "" outstr = "" errstr = "" path_to_bibcheck_cli = CFG_BINDIR + os.sep + 'bibcheck' if not os.path.exists(path_to_bibcheck_cli): errors = _("File %s does not exist.") % path_to_bibcheck_cli if not errors: #first check where we have stderr now so that we can assign it back try: (handle, mystdout, mystderr) = os.popen3(path_to_bibcheck_cli + " --verify" + fname) outstr = str(mystdout.readlines()) errstr = str(mystderr.readlines()) except: #the call failed? errors = _("Calling bibcheck -verify failed.") if not errors: if not errstr: return "OK" else: return errstr else: return page(title=_("Verify BibCheck config file"), body=_("Verify problem") + ":<br/>" + errors, language=ln, uid=uid, navtrail=navtrail, lastupdated=__lastupdated__, req=req, warnings=[])
def loans_lists(self, req, form): """Number of loans lists page.""" argd = wash_urlargd( form, { 'user_address': (str, ""), 'udc': (str, ""), 'loan_period': (str, ""), 'min_loans': (int, 0), 'max_loans': (int, sys.maxint), 'publication_date': (str, ""), 'creation_date': (str, ""), 'timespan': (str, "today"), 's_date': (str, ""), 'f_date': (str, ""), 'format': (str, SUITABLE_GRAPH_FORMAT), 'ln': (str, CFG_SITE_LANG) }) argd['min_loans'] = str(argd['min_loans']) argd['max_loans'] = str(argd['max_loans']) ln = argd['ln'] user_info = collect_user_info(req) (auth_code, auth_msg) = acc_authorize_action(user_info, 'runwebstatadmin') if auth_code: return page_not_authorized( req, navtrail=self.navtrail % {'ln_link': (ln != CFG_SITE_LANG and '?ln=' + ln) or ''}, text=auth_msg, navmenuid='loans lists', ln=ln) return page(title="Loans lists", body=perform_display_keyevent('loans lists', argd, req, ln=ln), navtrail="""<a class="navtrail" href="%s/stats/%s">Statistics</a>""" % \ (CFG_SITE_URL, (ln != CFG_SITE_LANG and '?ln=' + ln) or ''), description="CDS, Statistics, Loans lists", keywords="CDS, statistics, Loans lists", req=req, lastupdated=__lastupdated__, navmenuid='loans lists', language=ln)
def docsubmit(self, req, form): """ Function called after submitting the document upload form. Performs the appropiate action depending on the input parameters """ argd = wash_urlargd(form, {'docfolder': (str, ""), 'matching': (str, ""), 'mode': (str, ""), 'submit_date': (str, ""), 'submit_time': (str, ""), 'priority': (str, ""), 'email_logs_to': (str, "")}) _ = gettext_set_language(argd['ln']) not_authorized = user_authorization(req, argd['ln']) if not_authorized: return not_authorized date = argd['submit_date'] not in ['yyyy-mm-dd', ''] \ and argd['submit_date'] or '' time = argd['submit_time'] not in ['hh:mm:ss', ''] \ and argd['submit_time'] or '' errors, info = document_upload(req, argd['docfolder'], argd['matching'], argd['mode'], date, time, argd['ln'], argd['priority'], argd['email_logs_to']) body = batchuploader_templates.tmpl_display_menu(argd['ln']) uid = getUid(req) navtrail = '''<a class="navtrail" href="%s/batchuploader/documents">%s</a>''' % \ (CFG_SITE_SECURE_URL, _("Document batch upload")) body += batchuploader_templates.tmpl_display_web_docupload_result(argd['ln'], errors, info) title = _("Document batch upload result") return page(title = title, body = body, metaheaderadd = batchuploader_templates.tmpl_styles(), uid = uid, navtrail = navtrail, lastupdated = __lastupdated__, req = req, language = argd['ln'], navmenuid = "batchuploader")
def extract(self, req, form): """Refrences extraction page This page can be used for authors to test their pdfs against our refrences extraction process""" user_info = collect_user_info(req) # Handle the 3 POST parameters if 'pdf' in form and form['pdf'].value: pdf = form['pdf'].value.strip() references_xml = extract_from_pdf_string(pdf) elif 'arxiv' in form and form['arxiv'].value: url = make_arxiv_url(arxiv_id=form['arxiv'].value.strip()) references_xml = extract_references_from_url_xml(url) elif 'url' in form and form['url'].value: url = form['url'].value.strip() try: references_xml = extract_references_from_url_xml(url) except (FullTextNotAvailable, ConnectionError, HTTPError, Timeout): references_xml = None elif 'txt' in form and form['txt'].value: txt = form['txt'].value.decode('utf-8', 'ignore') references_xml = extract_references_from_string_xml(txt) else: references_xml = None # If we have not uploaded anything yet # Display the form that allows us to do so if not references_xml: out = docextract_templates.tmpl_web_form() else: references_html = format_record(0, 'hdref', xml_record=references_xml, user_info=user_info) out = docextract_templates.tmpl_web_result(references_html) # Render the page (including header, footer) return page(title='References Extractor', body=out, uid=user_info['uid'], req=req)
def testsource(req, oai_src_id=None, ln=CFG_SITE_LANG, confirm=0, record_id=None): navtrail_previous_links = oha.getnavtrail( ' > <a class="navtrail" href="%s/admin/bibharvest/oaiharvestadmin.py?ln=%s">OAI Harvest Admin Interface</a> ' % (CFG_SITE_URL, ln), ln=ln) try: uid = getUid(req) except Error, e: return page(title="OAI Harvest Admin Interface - Error", body=e, uid=uid, language=ln, navtrail=navtrail_previous_links, lastupdated=__lastupdated__, req=req)
def doctypeconfiguresubmissionpages(req, doctype="", action="", pagenum="", movepage="", movepagedirection="", deletepage="", deletepageconfirm="", addpage="", ln=CFG_SITE_LANG): ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) (auth_code, auth_msg) = check_user(req, 'cfgwebsubmit') if not auth_code: ## user is authorised to use WebSubmit Admin: (title, body, errors, warnings) = perform_request_configure_doctype_submissionpages( doctype=doctype, action=action, pagenum=pagenum, movepage=movepage, movepagedirection=movepagedirection, deletepage=deletepage, deletepageconfirm=deletepageconfirm, addpage=addpage) return page(title=title, body=body, navtrail=get_navtrail(ln), uid=uid, lastupdated=__lastupdated__, req=req, language=ln, errors=errors, warnings=warnings) else: ## user is not authorised to use WebSubmit Admin: return page_not_authorized(req=req, text=auth_msg, navtrail=get_navtrail(ln))
def index(req, ln=CFG_SITE_LANG, action='', bsrID='', sm_name='', sm_def_type='', sm_def_value='', sm_washer='', sm_locale=''): """ Display the initial(main) page """ navtrail_previous_links = bsc.getnavtrail() try: uid = getUid(req) except: return error_page('Error', req) auth = bsc.check_user(req, 'cfgbibsort') if not auth[0]: action = wash_url_argument(action, 'str') bsrID = wash_url_argument(bsrID, 'int') sm_name = wash_url_argument(sm_name, 'str') sm_def_type = wash_url_argument(sm_def_type, 'str') sm_def_value = wash_url_argument(sm_def_value, 'str') sm_washer = wash_url_argument(sm_washer, 'str') sm_locale = wash_url_argument(sm_locale, 'str') return page(title="BibSort Admin Interface", body=bsc.perform_index(ln, action, bsrID, sm_name, sm_def_type, sm_def_value, sm_washer, sm_locale), uid=uid, language=ln, navtrail=navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def deletevirtualindex(req, idxID, ln=CFG_SITE_LANG, confirm=0): navtrail_previous_links = bic.getnavtrail() + """> <a class="navtrail" href="%s/admin/bibindex/bibindexadmin.py/index">Manage Indexes</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req, 'cfgbibindex') if not auth[0]: return page(title="Manage Indexes", body=bic.perform_deletevirtualindex(idxID=idxID, ln=ln, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def __call__(self, req, form): try: from invenio.webpage import page except ImportError: register_exception() page = lambda *args: args[1] req.status = apache.HTTP_SERVICE_UNAVAILABLE msg = "<p>This functionality is currently unavailable due to a service maintenance.</p>" try: from invenio.config import CFG_SITE_ADMIN_EMAIL msg += """<p>You can contact <code>%s</code> in case of questions.</p>""" % \ CFG_SITE_ADMIN_EMAIL except ImportError: pass msg += """<p>We are going to restore the service soon.</p> <p>Sorry for the inconvenience.</p>""" try: return page('Service unavailable', msg, req=req) except: return msg
def field(req, ln=CFG_SITE_LANG, mtype='', content=''): navtrail_previous_links = bic.getnavtrail() try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req,'cfgbibindex') if not auth[0]: return page(title="Manage logical fields", body=bic.perform_field(ln=ln, mtype=mtype, content=content), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def __call__(self, req, form): try: from invenio.webpage import page except ImportError: page = lambda *args: args[1] req.status = apache.HTTP_INTERNAL_SERVER_ERROR msg = "<p>This functionality is experiencing a temporary failure.</p>" msg += "<p>The administrator has been informed about the problem.</p>" try: from invenio.config import CFG_SITE_ADMIN_EMAIL msg += """<p>You can contact <code>%s</code> in case of questions.</p>""" % \ CFG_SITE_ADMIN_EMAIL except ImportError: pass msg += """<p>We hope to restore the service soon.</p> <p>Sorry for the inconvenience.</p>""" try: return page('Service failure', msg) except: return msg
def actionedit(req, actid, actname=None, working_dir=None, status_text=None, actcommit="", ln=CFG_SITE_LANG): """Display the details of a WebSubmit action in a Web form so that it can be viewed and/or edited. @param actid: The unique action identifier code. @param actname: name of action (if present, action will be updated, else action details will be displayed) @param working_dir: action working directory for websubmit @param status_text: status text displayed at end of websubmit action @param ln: language @return: page """ ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) (auth_code, auth_msg) = check_user(req, 'cfgwebsubmit') if not auth_code: ## user is authorised to use WebSubmit Admin: # Generate content (title, body, errors, warnings) = perform_request_edit_action(actid, actname, working_dir, status_text, actcommit) return page(title=title, body=body, navtrail=get_navtrail(ln), uid=uid, lastupdated=__lastupdated__, req=req, language=ln, errors=errors, warnings=warnings) else: ## user is not authorised to use WebSubmit Admin: return page_not_authorized(req=req, text=auth_msg, navtrail=get_navtrail(ln))
def kb_dynamic_update(req, kb_id, field, expression, collection, ln=CFG_SITE_LANG): """ Updates the configuration of a collection based KB by checking user rights and calling bibknowledgeadminlib.. @param req request @param kb_id knowledge base id @param field configured field for this dynamic kb @param expression search expression @param collection search in this collection @param ln language """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = ''' > <a class="navtrail" href="%s/kb?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Knowledge Bases")) try: dummy = getUid(req) except: return error_page('Error', req) (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge') if not auth_code: #actual config call err = bibknowledgeadminlib.perform_update_kb_config(kb_id, field, expression, collection) if err: return page(title=_("Error"), body = err, language=ln, navtrail = navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: redirect_to_url(req, "kb?ln=%(ln)s&kb=%(kb_id)s" % {'ln':ln, 'kb_id': kb_id }) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def kb_manage(req, ln=CFG_SITE_LANG, search="", descriptiontoo=""): """ Main BibKnowledge administration page. @param ln language @param search search for a substring in kb names @param descriptiontoo .. and descriptions """ ln = wash_language(ln) _ = gettext_set_language(ln) warnings = [] # Check if user is authorized to administer # If not, still display page but offer to log in try: uid = getUid(req) except MySQLdb.Error: return error_page(req) (auth_code, auth_msg) = check_user(req, 'cfgbibknowledge') if not auth_code: is_admin = True else: is_admin = False navtrail = '''<a class="navtrail" href="%s/help/admin">%s</a>''' % \ (CFG_SITE_SECURE_URL, _("Admin Area")) if is_admin: return page(title=_("BibKnowledge Admin"), body=bibknowledgeadminlib. perform_request_knowledge_bases_management( ln=ln, search=search, descriptiontoo=descriptiontoo), language=ln, uid=uid, navtrail=navtrail, lastupdated=__lastupdated__, req=req, warnings=warnings) else: #redirect to login return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail)
def save(req, ln, fname, code, wasnew=0): """saves code into file fname. wasnew is 1 if this is a new file""" ln = wash_language(ln) _ = gettext_set_language(ln) # sanity check for fname: fname = os.path.basename(fname) #check auth (admin_ok, uid) = is_admin(req) navtrail = '''<a class="navtrail" href="%s/help/admin">%s</a>''' % \ (CFG_SITE_SECURE_URL, _("Admin Area")) navtrail += """> <a class="navtrail" href="%s/admin/bibcheck/bibcheckadmin.py/">BibCheck Admin</a> """ % CFG_SITE_SECURE_URL if admin_ok: myfile = CFG_ETCDIR + "/bibcheck/" + fname #check if the file exists if this was new if wasnew and os.path.exists(myfile): msg = _("File %s already exists.") % cgi.escape(fname) else: #write code into file msg = _("File %s: written OK.") % cgi.escape(fname) try: outfile = file(myfile, 'w') outfile.write(code) outfile.close() except IOError: msg = _("File %s: write failed.") % cgi.escape(fname) #print message return page(title=_("Save BibCheck config file"), body=msg, language=ln, uid=uid, navtrail=navtrail, lastupdated=__lastupdated__, req=req, warnings=[]) else: return page_not_authorized(req=req, text=_("Not authorized"), navtrail=navtrail)
def format_element_test(req, bfe, ln=CFG_SITE_LANG, param_values=None): """ Allows user to test element with different parameters and check output 'param_values' is the list of values to pass to 'format' function of the element as parameters, in the order ... If params is None, this means that they have not be defined by user yet. @param req: the request object @param bfe: the name of the element to test @param ln: language @param param_values: the list of parameters to pass to element format function @return: a web page """ ln = wash_language(ln) _ = gettext_set_language(ln) navtrail_previous_links = bibformatadminlib.getnavtrail( ''' > <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Format Elements Documentation"))) (auth_code, auth_msg) = check_user(req, 'cfgbibformat') if not auth_code: bfe = wash_url_argument(bfe, 'str') user_info = collect_user_info(req) uid = user_info['uid'] return page(title=_("Test Format Element %s" % bfe), body=bibformatadminlib.perform_request_format_element_test( bfe=bfe, ln=ln, param_values=param_values, user_info=user_info), uid=uid, language=ln, navtrail=navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth_msg, navtrail=navtrail_previous_links)
def switchtagscore(req, fldID, id_1, id_2, ln=CFG_SITE_LANG): navtrail_previous_links = bic.getnavtrail() + """> <a class="navtrail" href="%s/admin/bibindex/bibindexadmin.py/field">Manage logical fields</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req,'cfgbibindex') if not auth[0]: return page(title="Edit Logical Field", body=bic.perform_switchtagscore(fldID=fldID, id_1=id_1, id_2=id_2, ln=ln), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def index(req, ln=CFG_SITE_LANG): navtrail_previous_links = brc.getnavtrail( ) # + """> <a class="navtrail" href="%s/admin/bibrank/bibrankadmin.py">BibRank Admin Interface</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = brc.check_user(req, 'cfgbibrank') if not auth[0]: return page(title="BibRank Admin Interface", body=brc.perform_index(ln), uid=uid, language=ln, navtrail=navtrail_previous_links, lastupdated=__lastupdated__, req=req) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)
def history(self, req, form): """Displays history of the jobs""" argd = wash_urlargd(form, {}) # load the right message language language = argd["ln"] _ = gettext_set_language(language) self._check_user_credentials(req, language) title = _("Export Job History") user_id = self._get_user_id(req) body = perform_request_job_history(user_id, language) return page(title=title, metaheaderadd=get_css(), body=body, req=req, navmenuid="fieldexporter", titleprologue=get_navigation_menu(language), navtrail=self._NAVTRAIL_EXPORT, language=language)
def documents(self, req, form): """ Display document upload form """ argd = wash_urlargd(form, { }) _ = gettext_set_language(argd['ln']) not_authorized = user_authorization(req, argd['ln']) if not_authorized: return not_authorized uid = getUid(req) body = batchuploader_templates.tmpl_display_menu(argd['ln'], ref="documents") body += batchuploader_templates.tmpl_display_web_docupload_form(argd['ln']) title = _("Document batch upload") return page(title = title, body = body, metaheaderadd = batchuploader_templates.tmpl_styles(), uid = uid, lastupdated = __lastupdated__, req = req, language = argd['ln'], navmenuid = "batchuploader")
def collections(self, req, form): """Collections statistics page""" argd = wash_urlargd(form, { 'coll': (str, "All"), 'ln': (str, CFG_SITE_LANG) }) ln = argd['ln'] user_info = collect_user_info(req) (auth_code, auth_msg) = acc_authorize_action(user_info, 'runwebstatadmin') if auth_code: return page_not_authorized( req, navtrail=self.navtrail % {'ln_link': (ln != CFG_SITE_LANG and '?ln=' + ln) or ''}, navmenuid='collections', text=auth_msg, ln=ln) if collection_restricted_p(argd['coll']): (auth_code_coll, auth_msg_coll) = acc_authorize_action(user_info, VIEWRESTRCOLL, collection=argd['coll']) if auth_code_coll: return page_not_authorized(req, navmenuid='collections', text=auth_msg_coll, ln=ln) return page(title="Statistics of %s" % argd['coll'], body=perform_display_stats_per_coll(argd['coll'], req, ln=ln), navtrail="""<a class="navtrail" href="%s/stats/%s">Statistics</a>""" % \ (CFG_SITE_URL, (ln != CFG_SITE_LANG and '?ln=' + ln) or ''), description="CDS, Statistics, Collection %s" % argd['coll'], keywords="CDS, statistics, %s" % argd['coll'], req=req, lastupdated=__lastupdated__, navmenuid='collections', language=ln)
def editfields(req, ln=CFG_SITE_LANG, callback='yes', confirm=-1): navtrail_previous_links = bic.getnavtrail() + """> <a class="navtrail" href="%s/admin/bibindex/bibindexadmin.py/field">Manage logical fields</a> """ % (CFG_SITE_URL) try: uid = getUid(req) except: return error_page('Error', req) auth = bic.check_user(req,'cfgbibindex') if not auth[0]: return page(title="Manage logical fields", body=bic.perform_editfields(ln=ln, callback=callback, confirm=confirm), uid=uid, language=ln, req=req, navtrail = navtrail_previous_links, lastupdated=__lastupdated__) else: return page_not_authorized(req=req, text=auth[1], navtrail=navtrail_previous_links)