def tmpl_daemon_content(self, ln=CFG_SITE_LANG, docs=None, metadata=None): """ Displays all information related with batch uploader daemon mode """ _ = gettext_set_language(ln) body_content = "<br/><div id=\"info_box\">" body_content += "<ul>" body_content += "<li>" + _("Using %(x_fmt_open)sweb interface upload%(x_fmt_close)s, actions are executed a single time.") % \ {'x_fmt_open': '<b>', 'x_fmt_close':'</b>'} + "</li>" body_content += "<li>" + _("Check the %(x_url_open)sBatch Uploader daemon help page%(x_url_close)s for executing these actions periodically.") % \ {'x_url_open': '<a href="%s/help/admin/bibupload-admin-guide#4.2">' % CFG_SITE_URL, 'x_url_close': "</a>"} + \ "</li>" body_content += "</div><br/>" body_content += "<h3>%s</h3>" % _("Metadata folders") body_content += "<ul>" for folder in metadata.keys(): body_content += "<li><b>" + folder + "</b></li>" for filename, info in metadata[folder]: body_content += " " for stat in info: body_content += "%s " % stat body_content += filename + "<br />" body_content += "</ul>" body_content += "<h3> Document folders </h3>" body_content += "<ul>" for folder in docs.keys(): body_content += "<li><b>" + folder + "</b></li>" body_content += " " for filename, info in docs[folder]: for stat in info: body_content += "%s " % stat body_content += filename + "<br />" body_content += "</ul>" header = [_("ID"), _("Name"), _("Time"), _("Status"), _("Progress")] actions = [] body_content += """<br /><b>%s</b><br />""" % _("Last BibSched tasks:") res = run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='batchuploader' and runtime< now() ORDER by runtime") if len(res) > 0: (tsk_id, proc, host, user, runtime, sleeptime, arguments, status, progress) = res[len(res) - 1] actions.append([tsk_id, proc, runtime, (status !="" and status or ''), (progress !="" and progress or '')]) else: actions.append(['', 'batchuploader', '', '', 'Not executed yet']) body_content += tupletotable(header=header, tuple=actions) body_content += """<br /><b>%s</b><br />""" % _("Next scheduled BibSched run:") actions = [] res = run_sql("select id, proc, host, user, runtime, sleeptime, arguments, status, progress from schTASK where proc='batchuploader' and runtime > now() ORDER by runtime") if len(res) > 0: (tskid, proc, host, user, runtime, sleeptime, arguments, status, progress) = res[0] actions.append([tskid, proc, runtime, (status !="" and status or ''), (progress !="" and progress or '')]) else: actions.append(['', 'batchuploader', '', '', 'Not scheduled']) body_content += tupletotable(header=header, tuple=actions) return body_content
def perform_modifytranslations(ln, bsrID, trans=None, confirm=0): """Modify the translations of a sort method""" _ = gettext_set_language(ln) output = create_important_box( '<p>If you have questions, please see the %s.</p>' % get_admin_guide_link(ln), '#66CCFF') sel_type = 'ln' #Long name table_name = 'bsrMETHOD' sitelangs = get_languages() if not trans: trans = [] if type(trans) is str: trans = [trans] if confirm == 2 and bsrID: finresult = modify_translations(bsrID, sitelangs, sel_type, trans, table_name) bsr_dict = dict(get_i8n_name(bsrID, ln, sel_type, table_name)) if bsrID and bsrID in bsr_dict: header = ['Language', 'Translation'] actions = [] if not confirm: trans = [] for (key, dummy) in sitelangs: try: trans.append( get_i8n_name(bsrID, key, sel_type, table_name)[0][1]) except StandardError: trans.append('') for i in range(0, len(sitelangs)): actions.append([ "%s %s" % (sitelangs[i][1], (sitelangs[i][0] == CFG_SITE_LANG and '<small>(def)</small>' or '')) ]) actions[-1].append( '<input type="text" name="trans" size="30" value="%s"/>' % trans[i]) text = tupletotable(header=header, tuple=actions) output += createhiddenform(action="modifytranslations", text=text, button="Modify", bsrID=bsrID, ln=ln, confirm=2) if sel_type and len(trans) and confirm == 2: output += write_outcome(finresult) return output
def index(self, req, form): """ Display live BibSched queue """ referer = '/admin2/bibsched/' navtrail = ' <a class="navtrail" href=\"%s/help/admin\">Admin Area</a> ' % CFG_SITE_URL auth_code, auth_message = acc_authorize_action(req, 'cfgbibsched') if auth_code != 0: return page_not_authorized(req=req, referer=referer, text=auth_message, navtrail=navtrail) bibsched_tasks = get_bibsched_tasks() header = ["ID", "Name", "Priority", "User", "Time", "Status", "Progress"] map_status_css = {'WAITING': 'task_waiting', 'RUNNING': 'task_running', 'DONE WITH ERRORS': 'task_error'} bibsched_error = False motd_msg = get_motd_msg() actions = [] body_content = '' if len(motd_msg) > 0: body_content += '<div class="clean_error">' + motd_msg + '</div><br />' if 'jsondata' not in form: body_content = '<div id="bibsched_table">' if bibsched_tasks: for task in bibsched_tasks: tskid, proc, priority, user, runtime, status, progress = task actions.append([tskid, proc, priority, user, runtime, '<span class=%s>' % (status in map_status_css and map_status_css[status] or '') + (status != "" and status or '') + '</span>', (progress != "" and progress or '')]) if 'ERROR' in status: bibsched_error = True body_content += tupletotable(header=header, tuple=actions, alternate_row_colors_p=True) if bibsched_error: body_content += '<br /><img src="%s"><span class="bibsched_status"> The queue contains errors</span><br />' % ("/img/aid_reject.png") else: body_content += '<br /><img src="%s"><span class="bibsched_status"> BibSched is working without errors</span><br />' % ("/img/aid_check.png") body_content += '<br /><span class="mode">Mode: %s</span>' % (get_bibsched_mode()) body_content += '<br /><br /><span class="last_updated">Last updated: %s</span>' % \ (time.strftime("%a %b %d, %Y %-I:%M:%S %p", time.localtime(time.time()))) if 'jsondata' in form: json_response = {} json_response.update({'bibsched': body_content}) return json.dumps(json_response) else: body_content += '</div>' return page(title="BibSched live view", body=body_content, errors=[], warnings=[], metaheaderadd=get_javascript() + get_css(), req=req)
def perform_request_display_linkbacks(status, return_code, ln=CFG_SITE_LANG): """ Display linkbacks @param status: of CFG_WEBLINKBACK_STATUS, currently only CFG_WEBLINKBACK_STATUS['PENDING'] is supported """ _ = gettext_set_language(ln) if status == CFG_WEBLINKBACK_STATUS['PENDING']: linkbacks = get_all_linkbacks(status=status, order=CFG_WEBLINKBACK_ORDER_BY_INSERTION_TIME['DESC']) entries = [] for (linkbackid, origin_url, recid, additional_properties, linkback_type, linkback_status, insert_time) in linkbacks: # pylint: disable=W0612 moderation_prefix = '<a href="moderatelinkback?action=%%s&linkbackid=%s&ln=%s">%%s</a>' % (linkbackid, ln) entries.append((linkback_type, format_record(recID=recid, of='hs', ln=ln), '<a href="%s">%s</a>' % (cgi.escape(origin_url), cgi.escape(get_url_title(origin_url))), convert_datetext_to_dategui(str(insert_time)), moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['APPROVE'], 'Approve') + " / " + moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['REJECT'], 'Reject'))) header = ['Linkback type', 'Record', 'Origin', 'Submitted on', ''] error_message = "" if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']: error_message = _("Unknown error") if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION']: error_message = _("Invalid action") error_message_html = "" if error_message != "": error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>" out = """ <dl> %(error_message)s <dt>%(heading)s</dt> <dd>%(description)s</dd> </dl> """ % {'heading': _("Pending linkbacks"), 'description': _("these linkbacks are not visible to users, they must be approved or rejected."), 'error_message': error_message_html} if entries: out += tupletotable(header=header, tuple=entries, highlight_rows_p=True, alternate_row_colors_p=True) else: out += "<i>There are no %s linkbacks.</i>" % status.lower() return addadminbox('<b>%s</b>'% _("Reduce the amount of currently pending linkback requests"), [out]) else: return "<i>%s</i>" % _('Currently only pending linkbacks are supported.')
def perform_modifytranslations(ln, bsrID, trans=None, confirm=0): """Modify the translations of a sort method""" _ = gettext_set_language(ln) output = create_important_box('<p>If you have questions, please see the %s.</p>' %get_admin_guide_link(ln), '#66CCFF') sel_type = 'ln' #Long name table_name = 'bsrMETHOD' sitelangs = get_languages() if not trans: trans = [] if type(trans) is str: trans = [trans] if confirm == 2 and bsrID: finresult = modify_translations(bsrID, sitelangs, sel_type, trans, table_name) bsr_dict = dict(get_i8n_name(bsrID, ln, sel_type, table_name)) if bsrID and bsrID in bsr_dict: header = ['Language', 'Translation'] actions = [] if not confirm: trans = [] for (key, dummy) in sitelangs: try: trans.append(get_i8n_name(bsrID, key, sel_type, table_name)[0][1]) except StandardError: trans.append('') for i in range(0, len(sitelangs)): actions.append(["%s %s" % (sitelangs[i][1], (sitelangs[i][0]==CFG_SITE_LANG and '<small>(def)</small>' or ''))]) actions[-1].append('<input type="text" name="trans" size="30" value="%s"/>' % trans[i]) text = tupletotable(header=header, tuple=actions) output += createhiddenform(action="modifytranslations", text=text, button="Modify", bsrID=bsrID, ln=ln, confirm=2) if sel_type and len(trans) and confirm == 2: output += write_outcome(finresult) return output
def perform_request_display_list(return_code, url_field_value, ln=CFG_SITE_LANG): """ Display a list @param return_code: might indicate errors from a previous action, of CFG_WEBLINKBACK_ACTION_RETURN_CODE @param url_field_value: value of the url text field """ _ = gettext_set_language(ln) urls = get_urls() entries = [] for url in urls: entries.append(('<a href="%s">%s</a>' % (cgi.escape(url[0]), cgi.escape(url[0])), url[1].lower(), '<a href="moderatelist?url=%s&action=%s&ln=%s">%s</a>' % (urllib.quote(url[0]), CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'], ln, CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'].lower()))) header = ['URL', 'List', ''] error_message = "" if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']: error_message = _("Unknown error") if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE']: error_message = _("The URL already exists in one of the lists") elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION']: error_message = _("Invalid action") elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT']: error_message = _("Invalid URL, might contain spaces") error_message_html = "" if error_message != "": error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>" out = """ <dl> %(error_message)s <dt>%(whitelist)s</dt> <dd>%(whitelistText)s</dd> <dt>%(blacklist)s</dt> <dd>%(blacklistText)s</dd> <dt>%(explanation)s</dt> </dl> <table class="admin_wvar" cellspacing="0"> <tr><td> <form action='moderatelist'> URL: <input type="text" name="url" value="%(url)s" /> <input type="hidden" name="action" value="%(action)s" /> <select name="listtype" size="1"> <option value=whitelist>whitelist</option> <option value=blacklist>blacklist</option> </select> <input type="submit" class="adminbutton" value="%(buttonText)s"> </form> </td></tr></table> """ % {'whitelist': _('Whitelist'), 'whitelistText': _('linkback requests from these URLs will be approved automatically.'), 'blacklist': _('Blacklist'), 'blacklistText': _('linkback requests from these URLs will be refused automatically, no data will be saved.'), 'explanation': _('All URLs in these lists are checked for containment (infix) in any linkback request URL. A whitelist match has precedence over a blacklist match.'), 'url': cgi.escape(url_field_value), 'action': CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'], 'buttonText': _('Add URL'), 'error_message': error_message_html} if entries: out += tupletotable(header=header, tuple=entries, highlight_rows_p=True, alternate_row_colors_p=True) else: out += "<i>%s</i>" % _('There are no URLs in both lists.') return addadminbox('<b>%s</b>'% _("Reduce the amount of future pending linkback requests"), [out])
def index(self, req, form): """ Display live BibSched queue """ referer = '/admin2/bibsched/' navtrail = ' <a class="navtrail" href=\"%s/help/admin\">Admin Area</a> ' % CFG_SITE_URL auth_code, auth_message = acc_authorize_action(req, 'cfgbibsched') if auth_code != 0: return page_not_authorized(req=req, referer=referer, text=auth_message, navtrail=navtrail) bibsched_tasks = get_bibsched_tasks() header = [ "ID", "Name", "Priority", "User", "Time", "Status", "Progress" ] map_status_css = { 'WAITING': 'task_waiting', 'RUNNING': 'task_running', 'DONE WITH ERRORS': 'task_error' } bibsched_error = False motd_msg = get_motd_msg() actions = [] body_content = '' if len(motd_msg) > 0: body_content += '<div class="clean_error">' + motd_msg + '</div><br />' if 'jsondata' not in form: body_content = '<div id="bibsched_table">' if bibsched_tasks: for task in bibsched_tasks: tskid, proc, priority, user, runtime, status, progress = task actions.append([ tskid, proc, priority, user, runtime, '<span class=%s>' % (status in map_status_css and map_status_css[status] or '') + (status != "" and status or '') + '</span>', (progress != "" and progress or '') ]) if 'ERROR' in status: bibsched_error = True body_content += tupletotable(header=header, tuple=actions, alternate_row_colors_p=True) if bibsched_error: body_content += '<br /><img src="%s"><span class="bibsched_status"> The queue contains errors</span><br />' % ( "/img/aid_reject.png") else: body_content += '<br /><img src="%s"><span class="bibsched_status"> BibSched is working without errors</span><br />' % ( "/img/aid_check.png") body_content += '<br /><span class="mode">Mode: %s</span>' % ( get_bibsched_mode()) body_content += '<br /><br /><span class="last_updated">Last updated: %s</span>' % \ (time.strftime("%a %b %d, %Y %-I:%M:%S %p", time.localtime(time.time()))) if 'jsondata' in form: json_response = {} json_response.update({'bibsched': body_content}) return json.dumps(json_response) else: body_content += '</div>' return page(title="BibSched live view", body=body_content, errors=[], warnings=[], metaheaderadd=get_javascript() + get_css(), req=req)
def perform_request_display_list(return_code, url_field_value, ln=CFG_SITE_LANG): """ Display a list @param return_code: might indicate errors from a previous action, of CFG_WEBLINKBACK_ACTION_RETURN_CODE @param url_field_value: value of the url text field """ _ = gettext_set_language(ln) urls = get_urls() entries = [] for url in urls: entries.append( ('<a href="%s">%s</a>' % (cgi.escape(url[0]), cgi.escape(url[0])), url[1].lower(), '<a href="moderatelist?url=%s&action=%s&ln=%s">%s</a>' % (urllib.quote( url[0]), CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'], ln, CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE'].lower()))) header = ['URL', 'List', ''] error_message = "" if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']: error_message = _("Unknown error") if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE']: error_message = _("The URL already exists in one of the lists") elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE[ 'INVALID_ACTION']: error_message = _("Invalid action") elif return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT']: error_message = _("Invalid URL, might contain spaces") error_message_html = "" if error_message != "": error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>" out = """ <dl> %(error_message)s <dt>%(whitelist)s</dt> <dd>%(whitelistText)s</dd> <dt>%(blacklist)s</dt> <dd>%(blacklistText)s</dd> <dt>%(explanation)s</dt> </dl> <table class="admin_wvar" cellspacing="0"> <tr><td> <form action='moderatelist'> URL: <input type="text" name="url" value="%(url)s" /> <input type="hidden" name="action" value="%(action)s" /> <select name="listtype" size="1"> <option value=whitelist>whitelist</option> <option value=blacklist>blacklist</option> </select> <input type="submit" class="adminbutton" value="%(buttonText)s"> </form> </td></tr></table> """ % { 'whitelist': _('Whitelist'), 'whitelistText': _('linkback requests from these URLs will be approved automatically.'), 'blacklist': _('Blacklist'), 'blacklistText': _('linkback requests from these URLs will be refused automatically, no data will be saved.' ), 'explanation': _('All URLs in these lists are checked for containment (infix) in any linkback request URL. A whitelist match has precedence over a blacklist match.' ), 'url': cgi.escape(url_field_value), 'action': CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'], 'buttonText': _('Add URL'), 'error_message': error_message_html } if entries: out += tupletotable(header=header, tuple=entries, highlight_rows_p=True, alternate_row_colors_p=True) else: out += "<i>%s</i>" % _('There are no URLs in both lists.') return addadminbox( '<b>%s</b>' % _("Reduce the amount of future pending linkback requests"), [out])
def perform_request_display_linkbacks(status, return_code, ln=CFG_SITE_LANG): """ Display linkbacks @param status: of CFG_WEBLINKBACK_STATUS, currently only CFG_WEBLINKBACK_STATUS['PENDING'] is supported """ _ = gettext_set_language(ln) if status == CFG_WEBLINKBACK_STATUS['PENDING']: linkbacks = get_all_linkbacks( status=status, order=CFG_WEBLINKBACK_ORDER_BY_INSERTION_TIME['DESC']) entries = [] for (linkbackid, origin_url, recid, additional_properties, linkback_type, linkback_status, insert_time) in linkbacks: # pylint: disable=W0612 moderation_prefix = '<a href="moderatelinkback?action=%%s&linkbackid=%s&ln=%s">%%s</a>' % ( linkbackid, ln) entries.append(( linkback_type, format_record(recID=recid, of='hs', ln=ln), '<a href="%s">%s</a>' % (cgi.escape(origin_url), cgi.escape( get_url_title(origin_url))), convert_datetext_to_dategui(str(insert_time)), moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['APPROVE'], 'Approve') + " / " + moderation_prefix % (CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['REJECT'], 'Reject'))) header = ['Linkback type', 'Record', 'Origin', 'Submitted on', ''] error_message = "" if return_code != CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK']: error_message = _("Unknown error") if return_code == CFG_WEBLINKBACK_ACTION_RETURN_CODE[ 'INVALID_ACTION']: error_message = _("Invalid action") error_message_html = "" if error_message != "": error_message_html = "<dt><b><font color=red>" + error_message + "</font></b></dt>" + "<br>" out = """ <dl> %(error_message)s <dt>%(heading)s</dt> <dd>%(description)s</dd> </dl> """ % { 'heading': _("Pending linkbacks"), 'description': _("these linkbacks are not visible to users, they must be approved or rejected." ), 'error_message': error_message_html } if entries: out += tupletotable(header=header, tuple=entries, highlight_rows_p=True, alternate_row_colors_p=True) else: out += "<i>There are no %s linkbacks.</i>" % status.lower() return addadminbox( '<b>%s</b>' % _("Reduce the amount of currently pending linkback requests"), [out]) else: return "<i>%s</i>" % _( 'Currently only pending linkbacks are supported.')