def scripts(self): """Returns the scripts that should be imported.""" scripts = ["json2.js", "bibeditmulti.js"] result = "" for script in scripts: result += '<script type="text/javascript" src="%s/%s">' \ '</script>\n' % (CFG_SITE_URL, auto_version_url("js/" + script)) return result
def index(self, req, form): """Handle all BibMerge requests. The responsibilities of this functions are: * JSON decoding and encoding. * Redirection, if necessary. * Authorization. * Calling the appropriate function from the engine. """ # If it is an Ajax request, extract any JSON data. ajax_request, recid1, recid2 = False, None, None argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)}) if form.has_key('jsondata'): json_data = json.loads(str(form['jsondata'])) # Deunicode all strings (Invenio doesn't have unicode # support). json_data = json_unicode_to_utf8(json_data) ajax_request = True json_response = {} try: if json_data.has_key('recID1'): recid1 = int(json_data['recID1']) json_data['recID1'] = recid1 if json_data.has_key('recID2'): if json_data.get('record2Mode') == "recid": recid2 = int(json_data['recID2']) json_data['recID2'] = recid2 except ValueError: json_response.update({ 'resultCode': 1, 'resultText': 'Invalid record ID!' }) return json.dumps(json_response) if json_data.has_key("duplicate"): if json_data.get('record2Mode') == "recid": json_data["duplicate"] = int(json_data["duplicate"]) # Authorization. user_info = collect_user_info(req) if user_info['email'] == 'guest': # User is not logged in. if not ajax_request: # Do not display the introductory recID selection box to guest # users (as it used to be with v0.99.0): auth_code, auth_message = acc_authorize_action( req, 'runbibmerge') referer = '/merge/' return page_not_authorized(req=req, referer=referer, text=auth_message, navtrail=navtrail) else: # Session has most likely timed out. json_response.update({ 'resultCode': 1, 'resultText': 'Error: Not logged in' }) return json.dumps(json_response) elif self.recid: # Handle RESTful call by storing recid and redirecting to # generic URL. redirect_to_url( req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL, CFG_SITE_RECORD)) if recid1 is not None: # Authorize access to record 1. auth_code, auth_message = acc_authorize_action( req, 'runbibmerge', collection=guess_primary_collection_of_a_record(recid1)) if auth_code != 0: json_response.update({ 'resultCode': 1, 'resultText': 'No access to record %s' % recid1 }) return json.dumps(json_response) if recid2 is not None: # Authorize access to record 2. auth_code, auth_message = acc_authorize_action( req, 'runbibmerge', collection=guess_primary_collection_of_a_record(recid2)) if auth_code != 0: json_response.update({ 'resultCode': 1, 'resultText': 'No access to record %s' % recid2 }) return json.dumps(json_response) # Handle request. uid = getUid(req) if not ajax_request: # Show BibEdit start page. body, errors, warnings = perform_request_init() scripts = ["json2.js", "bibmerge_engine.js"] metaheaderadd = "" for script in scripts: metaheaderadd += '<script type="text/javascript" src="%s/%s"></script>' % ( CFG_SITE_URL, auto_version_url("js/" + script)) return page(title='Record Merger', metaheaderadd=metaheaderadd, body=body, errors=errors, warnings=warnings, uid=uid, language=argd['ln'], navtrail=navtrail, lastupdated=__lastupdated__, req=req) else: # Handle AJAX request. json_response = perform_request_ajax(req, uid, json_data) return json.dumps(json_response)
def tmpl_pageheader(self, req, ln=CFG_SITE_LANG, headertitle="", description="", keywords="", userinfobox="", useractivities_menu="", adminactivities_menu="", navtrailbox="", pageheaderadd="", uid=0, secure_page_p=0, navmenuid="admin", metaheaderadd="", rssurl=CFG_BASE_URL + "/rss", body_css_classes=None): """Creates a page header Parameters: - 'ln' *string* - The language to display - 'headertitle' *string* - the second part of the page HTML title - 'description' *string* - description goes to the metadata in the header of the HTML page - 'keywords' *string* - keywords goes to the metadata in the header of the HTML page - 'userinfobox' *string* - the HTML code for the user information box - 'useractivities_menu' *string* - the HTML code for the user activities menu - 'adminactivities_menu' *string* - the HTML code for the admin activities menu - 'navtrailbox' *string* - the HTML code for the navigation trail box - 'pageheaderadd' *string* - additional page header HTML code - 'uid' *int* - user ID - 'secure_page_p' *int* (0 or 1) - are we to use HTTPS friendly page elements or not? - 'navmenuid' *string* - the id of the navigation item to highlight for this page - 'metaheaderadd' *string* - list of further tags to add to the <HEAD></HEAD> part of the page - 'rssurl' *string* - the url of the RSS feed for this page - 'body_css_classes' *list* - list of classes to add to the body tag Output: - HTML code of the page headers """ hepDataAdditions = """<script type="text/javascript" src="%s/js/hepdata.js"></script>""" \ % (CFG_BASE_URL, ) hepDataAdditions += """<link rel="stylesheet" href="%s/img/hepdata.css" type="text/css" />""" \ % (CFG_BASE_URL, ) # load the right message language _ = gettext_set_language(ln) if body_css_classes is None: body_css_classes = [] body_css_classes.append(navmenuid) uri = req.unparsed_uri cssskin = CFG_WEBSTYLE_TEMPLATE_SKIN != 'default' and '_' + CFG_WEBSTYLE_TEMPLATE_SKIN or '', if CFG_WEBSTYLE_INSPECT_TEMPLATES: inspect_templates_message = ''' <table width="100%%" cellspacing="0" cellpadding="2" border="0"> <tr bgcolor="#aa0000"> <td width="100%%"> <font color="#ffffff"> <strong> <small> CFG_WEBSTYLE_INSPECT_TEMPLATES debugging mode is enabled. Please hover your mouse pointer over any region on the page to see which template function generated it. </small> </strong> </font> </td> </tr> </table> ''' else: inspect_templates_message = "" #FIXME: Hack to include datepicker for submissions using WebSubmit submission_js = "" if navmenuid == "submit": # src taken from batchuploader form submission_js = """ <script type="text/javascript" src="%(site_url)s/js/jquery-ui.min.js"></script> <link type="text/css" href="%(site_url)s/img/jquery-ui.css" rel="stylesheet" /> <link type="text/css" href="%(site_url)s/img/jobsubmit.css" rel="stylesheet" /> <script type="text/javascript"> //<![CDATA[ function clearText(field){ if (field.value == field.defaultValue){ field.value = ''; } } function defText(field){ if (field.value == ''){ field.value = field.defaultValue; } } $(function() { $(".datepicker").datepicker({dateFormat: 'yy-mm-dd'}); $('.datepicker[name="CONFSUBMIT_SDAT"]').datepicker("destroy"); $('.datepicker[name="CONFSUBMIT_SDAT"]').datepicker({ dateFormat: 'yy-mm-dd', altField: '.datepicker[name="CONFSUBMIT_FDAT"]' }); }); function split(val) { return val.split( /;\s*/ ); } function extractLast( term ) { return split( term ).pop(); } function autocomplete_kb(that, kb_name) { $.getJSON("/kb/export", {kbname: kb_name, format: 'jquery'}) .done(function(json) { that.autocomplete({ minLength: 2, source: function (request, response) { // delegate back to autocomplete, but extract the last term response($.ui.autocomplete.filter(json, extractLast(request.term))); }, focus: function() { // prevent value inserted on focus return false; }, select: function(event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push( ui.item.value ); // add placeholder to get the semicolon-and-space at the end terms.push(""); this.value = terms.join("; "); return false; } }); }) } $(function () { $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); autocomplete_kb($("#jobsubmitAffil"), "InstitutionsCollection"); autocomplete_kb($("#jobsubmitExp"), "ExperimentsCollection"); }) //]]> </script> """ % { 'site_url': CFG_BASE_URL } # Hack to add jobs filter JS to Jobs collection pages if "Jobs" in body_css_classes: metaheaderadd += '<script type="text/javascript" src="%s/js/jobs_filter.js"></script>' % \ (CFG_BASE_URL,) out = """\ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="%(ln_iso_639_a)s" xml:lang="%(ln_iso_639_a)s"> <head> <title>%(headertitle)s - INSPIRE-HEP</title> <link rev="made" href="mailto:%(sitesupportemail)s" /> <link rel="stylesheet" href="%(inspire_css)s" type="text/css" /> %(canonical_and_alternate_urls)s <link rel="alternate" type="application/rss+xml" title="%(sitename)s RSS" href="%(rssurl)s" /> <link rel="search" type="application/opensearchdescription+xml" href="%(siteurl)s/opensearchdescription" title="%(sitename)s" /> <link rel="unapi-server" type="application/xml" title="unAPI" href="%(unAPIurl)s" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="%(ln)s" /> <meta name="description" content="%(description)s" /> <meta name="keywords" content="%(keywords)s" /> <meta name="msvalidate.01" content="EA9805F0F62E4FF22B98853713964B28" /> <script type="text/javascript" src="%(cssurl)s/js/jquery.min.js"></script> <script type="text/javascript"> //<![CDATA[ $(document).ready(function() { if ((document.search) && ('baseURI' in document) && (document.baseURI.indexOf('/search?') == -1)) { $('#mainlightsearchfield').focus(); } }); //]]> </script> %(submissionjs)s %(metaheaderadd)s %(hepDataAdditions)s </head> <body%(body_css_classes)s lang="%(ln_iso_639_a)s"> <div class="pageheader"> %(inspect_templates_message)s <!-- replaced page header --> <table class="headerbox" cellspacing="0"> <tr> <td align="left"> <div> <a class="img" href="%(siteurl)s/?ln=%(ln)s"> <img border="0" src="%(cssurl)s/img/inspire_logo_hep.png" alt="INSPIRE" /> </a> </div> </td> <td class="feedbackbox"> <div class="feedbackboxbody"> Welcome to <a href="http://www.projecthepinspire.net">INSPIRE</a>, the High Energy Physics information system. Please direct questions, comments or concerns to <a href="mailto:[email protected]">[email protected]</a>. </div> </td> </tr> </table> <div class="navbar"> <a id="nav-hep" href="%(siteurl)s/?ln=%(ln)s">Hep</a> :: <a id="nav-hepnames" href="%(siteurl)s/collection/HepNames">HepNames</a> :: <a id="nav-inst" href="%(siteurl)s/collection/Institutions">Institutions</a> :: <a id="nav-conf" href="%(siteurl)s/collection/Conferences">Conferences</a> :: <a id="nav-jobs" href="%(siteurl)s/collection/Jobs">Jobs</a> :: <a id="nav-exp" href="%(siteurl)s/collection/Experiments">Experiments</a> :: <a id="nav-journals" href="%(siteurl)s/collection/Journals">Journals</a> :: <a id="nav-help" href="%(siteurl)s/help/?ln=%(ln)s">%(msg_help)s</a> </div> <table class="navtrailbox"> <tr> <td class="navtrailboxbody"> %(navtrailbox)s </td> </tr> </table> <!-- end replaced page header --> %(pageheaderadd)s </div> """ % { 'siteurl' : CFG_BASE_URL, 'sitesecureurl' : CFG_SITE_SECURE_URL, 'cssurl' : CFG_BASE_URL, 'canonical_and_alternate_urls' : self.tmpl_canonical_and_alternate_urls(uri), 'inspire_css' : "%s/" % CFG_BASE_URL + auto_version_url("img/" + 'invenio%s.css' % cssskin), 'rssurl': rssurl, 'ln' : ln, 'ln_iso_639_a' : ln.split('_', 1)[0], 'langlink': '?ln=' + ln, 'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME), 'headertitle' : cgi.escape(headertitle), 'sitesupportemail' : CFG_SITE_SUPPORT_EMAIL, 'description' : cgi.escape(description), 'keywords' : cgi.escape(keywords), 'metaheaderadd' : metaheaderadd, 'submissionjs' : submission_js, 'userinfobox' : userinfobox, 'navtrailbox' : navtrailbox, 'useractivities': useractivities_menu, 'adminactivities': adminactivities_menu and ('<td class="headermoduleboxbodyblank"> </td><td class="headermoduleboxbody%(personalize_selected)s">%(adminactivities)s</td>' % \ {'personalize_selected': navmenuid.startswith('admin') and "selected" or "", 'adminactivities': adminactivities_menu}) or '<td class="headermoduleboxbodyblank"> </td>', 'pageheaderadd' : pageheaderadd, 'body_css_classes' : body_css_classes and ' class="%s"' % ' '.join(body_css_classes) or '', 'search_selected': navmenuid == 'search' and "selected" or "", 'submit_selected': navmenuid == 'submit' and "selected" or "", 'personalize_selected': navmenuid.startswith('your') and "selected" or "", 'help_selected': navmenuid == 'help' and "selected" or "", 'msg_submit' : _("Submit"), 'msg_personalize' : _("Personalize"), 'msg_help' : _("Help"), 'languagebox' : self.tmpl_language_selection_box(req, ln), 'feedback' : self.tmpl_feedback_box(ln), 'unAPIurl' : cgi.escape('%s/unapi' % CFG_BASE_URL), 'inspect_templates_message' : inspect_templates_message, 'hepDataAdditions' : hepDataAdditions } return out
def tmpl_styles(self): """Defines the local CSS styles and javascript used in the plugin""" styles = """ <style type="text/css"> .mandatory_field{ color:#ff0000 } .italics{ font-style:italic } .italics_small{ font-style:italic; font-size: 0.9em; } .clean_ok{ border:solid 1px #349534; background:#C9FFCA; color:#008000; font-size:14px; font-weight:bold; padding:4px; text-align:center; width: 650px; } .clean_error{ border:solid 1px #CC0000; background:#F7CBCA; color:#CC0000; font-size:14px; font-weight:bold; padding:4px; text-align:center; width: 650px; } #content {width:750px; font:90.1% arial, sans-serif;} .uploadform {margin:0 0 1em 0} .uploadform div {margin:0.5em 0} .uploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px} #docuploadform {margin:0 0 1em 0} #docuploadform div {margin:0.5em 0} #docuploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px} #error_div {color: red; font-style: bold; } div.ui-datepicker{ font-size:12px; } span.red{ color:#df0000; } span.green{ color:#060; background: transparent; } span.yellow{ color:#9f9b00; } #info_box{ border: 3px black solid; border-width: thin; width: 750px; } img.img_link { border-style: none; } fieldset label { float: left; width: 150px; } label.nowidth { width: auto; } .batchuploader_error { max-width: 650px; max-height: 326px; border:solid 1px #CC0000; background:#F7CBCA; overflow: auto; } #batchuploader_error_list{ list-style-type: none; padding-left: 10px; } #batchuploader_error_list li{ margin-bottom: 10px; } </style> """ styles += """ <link type="text/css" href="%(site_url)s/img/jquery-ui.css" rel="stylesheet" /> <script type="text/javascript"> function clearText(field){ if (field.value == field.defaultValue){ field.value = ''; } } function defText(field){ if (field.value == ''){ field.value = field.defaultValue; } } </script> <script type="text/javascript" src="%(site_url)s/js/jquery-ui.min.js"></script> <script type="text/javascript" src="%(site_url)s/%(script)s"></script> """ % { 'site_url': CFG_SITE_URL, 'script': auto_version_url("js/batchuploader.js") } return styles
def tmpl_pageheader(self, req, ln=CFG_SITE_LANG, headertitle="", description="", keywords="", userinfobox="", useractivities_menu="", adminactivities_menu="", navtrailbox="", pageheaderadd="", uid=0, secure_page_p=0, navmenuid="admin", metaheaderadd="", rssurl=CFG_BASE_URL+"/rss", body_css_classes=None): """Creates a page header Parameters: - 'ln' *string* - The language to display - 'headertitle' *string* - the second part of the page HTML title - 'description' *string* - description goes to the metadata in the header of the HTML page - 'keywords' *string* - keywords goes to the metadata in the header of the HTML page - 'userinfobox' *string* - the HTML code for the user information box - 'useractivities_menu' *string* - the HTML code for the user activities menu - 'adminactivities_menu' *string* - the HTML code for the admin activities menu - 'navtrailbox' *string* - the HTML code for the navigation trail box - 'pageheaderadd' *string* - additional page header HTML code - 'uid' *int* - user ID - 'secure_page_p' *int* (0 or 1) - are we to use HTTPS friendly page elements or not? - 'navmenuid' *string* - the id of the navigation item to highlight for this page - 'metaheaderadd' *string* - list of further tags to add to the <HEAD></HEAD> part of the page - 'rssurl' *string* - the url of the RSS feed for this page - 'body_css_classes' *list* - list of classes to add to the body tag Output: - HTML code of the page headers """ hepDataAdditions = """<script type="text/javascript" src="%s/js/hepdata.js"></script>""" \ % (CFG_BASE_URL, ) hepDataAdditions += """<link rel="stylesheet" href="%s/img/hepdata.css" type="text/css" />""" \ % (CFG_BASE_URL, ) # load the right message language _ = gettext_set_language(ln) if body_css_classes is None: body_css_classes = [] body_css_classes.append(navmenuid) uri = req.unparsed_uri cssskin = CFG_WEBSTYLE_TEMPLATE_SKIN != 'default' and '_' + CFG_WEBSTYLE_TEMPLATE_SKIN or '', if CFG_WEBSTYLE_INSPECT_TEMPLATES: inspect_templates_message = ''' <table width="100%%" cellspacing="0" cellpadding="2" border="0"> <tr bgcolor="#aa0000"> <td width="100%%"> <font color="#ffffff"> <strong> <small> CFG_WEBSTYLE_INSPECT_TEMPLATES debugging mode is enabled. Please hover your mouse pointer over any region on the page to see which template function generated it. </small> </strong> </font> </td> </tr> </table> ''' else: inspect_templates_message = "" #FIXME: Hack to include datepicker for submissions using WebSubmit submission_js = "" if navmenuid == "submit": # src taken from batchuploader form submission_js = """ <script type="text/javascript" src="%(site_url)s/js/jquery-ui.min.js"></script> <link type="text/css" href="%(site_url)s/img/jquery-ui.css" rel="stylesheet" /> <link type="text/css" href="%(site_url)s/img/jobsubmit.css" rel="stylesheet" /> <script type="text/javascript"> //<![CDATA[ function clearText(field){ if (field.value == field.defaultValue){ field.value = ''; } } function defText(field){ if (field.value == ''){ field.value = field.defaultValue; } } $(function() { $(".datepicker").datepicker({dateFormat: 'yy-mm-dd'}); $('.datepicker[name="CONFSUBMIT_SDAT"]').datepicker("destroy"); $('.datepicker[name="CONFSUBMIT_SDAT"]').datepicker({ dateFormat: 'yy-mm-dd', altField: '.datepicker[name="CONFSUBMIT_FDAT"]' }); }); function split(val) { return val.split( /;\s*/ ); } function extractLast( term ) { return split( term ).pop(); } function autocomplete_kb(that, kb_name) { $.getJSON("/kb/export", {kbname: kb_name, format: 'jquery'}) .done(function(json) { that.autocomplete({ minLength: 2, source: function (request, response) { // delegate back to autocomplete, but extract the last term response($.ui.autocomplete.filter(json, extractLast(request.term))); }, focus: function() { // prevent value inserted on focus return false; }, select: function(event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push( ui.item.value ); // add placeholder to get the semicolon-and-space at the end terms.push(""); this.value = terms.join("; "); return false; } }); }) } $(function () { $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); autocomplete_kb($("#jobsubmitAffil"), "InstitutionsCollection"); autocomplete_kb($("#jobsubmitExp"), "ExperimentsCollection"); }) //]]> </script> """ % {'site_url': CFG_BASE_URL} # Hack to add jobs filter JS to Jobs collection pages if "Jobs" in body_css_classes: metaheaderadd += '<script type="text/javascript" src="%s/js/jobs_filter.js"></script>' % \ (CFG_BASE_URL,) out = """\ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="%(ln_iso_639_a)s" xml:lang="%(ln_iso_639_a)s"> <head> <title>%(headertitle)s - INSPIRE-HEP</title> <link rev="made" href="mailto:%(sitesupportemail)s" /> <link rel="stylesheet" href="%(inspire_css)s" type="text/css" /> %(canonical_and_alternate_urls)s <link rel="alternate" type="application/rss+xml" title="%(sitename)s RSS" href="%(rssurl)s" /> <link rel="search" type="application/opensearchdescription+xml" href="%(siteurl)s/opensearchdescription" title="%(sitename)s" /> <link rel="unapi-server" type="application/xml" title="unAPI" href="%(unAPIurl)s" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="%(ln)s" /> <meta name="description" content="%(description)s" /> <meta name="keywords" content="%(keywords)s" /> <meta name="msvalidate.01" content="EA9805F0F62E4FF22B98853713964B28" /> <script type="text/javascript" src="%(cssurl)s/js/jquery.min.js"></script> <script type="text/javascript"> //<![CDATA[ $(document).ready(function() { if ((document.search) && ('baseURI' in document) && (document.baseURI.indexOf('/search?') == -1)) { $('#mainlightsearchfield').focus(); } }); //]]> </script> %(submissionjs)s %(metaheaderadd)s %(hepDataAdditions)s </head> <body%(body_css_classes)s lang="%(ln_iso_639_a)s"> <div class="pageheader"> %(inspect_templates_message)s <!-- replaced page header --> <table class="headerbox" cellspacing="0"> <tr> <td align="left"> <div> <a class="img" href="%(siteurl)s/?ln=%(ln)s"> <img border="0" src="%(cssurl)s/img/inspire_logo_hep.png" alt="INSPIRE" /> </a> </div> </td> <td class="feedbackbox"> <div class="feedbackboxbody"> Welcome to <a href="http://www.projecthepinspire.net">INSPIRE</a>, the High Energy Physics information system. Please direct questions, comments or concerns to <a href="mailto:[email protected]">[email protected]</a>. </div> </td> </tr> </table> <div class="navbar"> <a id="nav-hep" href="%(siteurl)s/?ln=%(ln)s">Hep</a> :: <a id="nav-hepnames" href="%(siteurl)s/collection/HepNames">HepNames</a> :: <a id="nav-inst" href="%(siteurl)s/collection/Institutions">Institutions</a> :: <a id="nav-conf" href="%(siteurl)s/collection/Conferences">Conferences</a> :: <a id="nav-jobs" href="%(siteurl)s/collection/Jobs">Jobs</a> :: <a id="nav-exp" href="%(siteurl)s/collection/Experiments">Experiments</a> :: <a id="nav-journals" href="%(siteurl)s/collection/Journals">Journals</a> :: <a id="nav-help" href="%(siteurl)s/help/?ln=%(ln)s">%(msg_help)s</a> </div> <table class="navtrailbox"> <tr> <td class="navtrailboxbody"> %(navtrailbox)s </td> </tr> </table> <!-- end replaced page header --> %(pageheaderadd)s </div> """ % { 'siteurl' : CFG_BASE_URL, 'sitesecureurl' : CFG_SITE_SECURE_URL, 'cssurl' : CFG_BASE_URL, 'canonical_and_alternate_urls' : self.tmpl_canonical_and_alternate_urls(uri), 'inspire_css' : "%s/" % CFG_BASE_URL + auto_version_url("img/" + 'invenio%s.css' % cssskin), 'rssurl': rssurl, 'ln' : ln, 'ln_iso_639_a' : ln.split('_', 1)[0], 'langlink': '?ln=' + ln, 'sitename' : CFG_SITE_NAME_INTL.get(ln, CFG_SITE_NAME), 'headertitle' : cgi.escape(headertitle), 'sitesupportemail' : CFG_SITE_SUPPORT_EMAIL, 'description' : cgi.escape(description), 'keywords' : cgi.escape(keywords), 'metaheaderadd' : metaheaderadd, 'submissionjs' : submission_js, 'userinfobox' : userinfobox, 'navtrailbox' : navtrailbox, 'useractivities': useractivities_menu, 'adminactivities': adminactivities_menu and ('<td class="headermoduleboxbodyblank"> </td><td class="headermoduleboxbody%(personalize_selected)s">%(adminactivities)s</td>' % \ {'personalize_selected': navmenuid.startswith('admin') and "selected" or "", 'adminactivities': adminactivities_menu}) or '<td class="headermoduleboxbodyblank"> </td>', 'pageheaderadd' : pageheaderadd, 'body_css_classes' : body_css_classes and ' class="%s"' % ' '.join(body_css_classes) or '', 'search_selected': navmenuid == 'search' and "selected" or "", 'submit_selected': navmenuid == 'submit' and "selected" or "", 'personalize_selected': navmenuid.startswith('your') and "selected" or "", 'help_selected': navmenuid == 'help' and "selected" or "", 'msg_submit' : _("Submit"), 'msg_personalize' : _("Personalize"), 'msg_help' : _("Help"), 'languagebox' : self.tmpl_language_selection_box(req, ln), 'feedback' : self.tmpl_feedback_box(ln), 'unAPIurl' : cgi.escape('%s/unapi' % CFG_BASE_URL), 'inspect_templates_message' : inspect_templates_message, 'hepDataAdditions' : hepDataAdditions } return out
def index(self, req, form): """Handle all BibMerge requests. The responsibilities of this functions are: * JSON decoding and encoding. * Redirection, if necessary. * Authorization. * Calling the appropriate function from the engine. """ # If it is an Ajax request, extract any JSON data. ajax_request, recid1, recid2 = False, None, None argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)}) if form.has_key('jsondata'): json_data = json.loads(str(form['jsondata'])) # Deunicode all strings (Invenio doesn't have unicode # support). json_data = json_unicode_to_utf8(json_data) ajax_request = True json_response = {} try: if json_data.has_key('recID1'): recid1 = int(json_data['recID1']) json_data['recID1'] = recid1 if json_data.has_key('recID2'): if json_data.get('record2Mode') == "recid": recid2 = int(json_data['recID2']) json_data['recID2'] = recid2 except ValueError: json_response.update({'resultCode': 1, 'resultText': 'Invalid record ID!'}) return json.dumps(json_response) if json_data.has_key("duplicate"): if json_data.get('record2Mode') == "recid": json_data["duplicate"] = int(json_data["duplicate"]) # Authorization. user_info = collect_user_info(req) if user_info['email'] == 'guest': # User is not logged in. if not ajax_request: # Do not display the introductory recID selection box to guest # users (as it used to be with v0.99.0): auth_code, auth_message = acc_authorize_action(req, 'runbibmerge') referer = '/merge/' return page_not_authorized(req=req, referer=referer, text=auth_message, navtrail=navtrail) else: # Session has most likely timed out. json_response.update({'resultCode': 1, 'resultText': 'Error: Not logged in'}) return json.dumps(json_response) elif self.recid: # Handle RESTful call by storing recid and redirecting to # generic URL. redirect_to_url(req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL, CFG_SITE_RECORD)) if recid1 is not None: # Authorize access to record 1. auth_code, auth_message = acc_authorize_action(req, 'runbibmerge', collection=guess_primary_collection_of_a_record(recid1)) if auth_code != 0: json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid1}) return json.dumps(json_response) if recid2 is not None: # Authorize access to record 2. auth_code, auth_message = acc_authorize_action(req, 'runbibmerge', collection=guess_primary_collection_of_a_record(recid2)) if auth_code != 0: json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid2}) return json.dumps(json_response) # Handle request. uid = getUid(req) if not ajax_request: # Show BibEdit start page. body, errors, warnings = perform_request_init() scripts = ["json2.js", "bibmerge_engine.js"] metaheaderadd = "" for script in scripts: metaheaderadd += '<script type="text/javascript" src="%s/%s"></script>' % (CFG_SITE_URL, auto_version_url("js/" + script)) return page(title = 'Record Merger', metaheaderadd = metaheaderadd, body = body, errors = errors, warnings = warnings, uid = uid, language = argd['ln'], navtrail = navtrail, lastupdated = __lastupdated__, req = req) else: # Handle AJAX request. json_response = perform_request_ajax(req, uid, json_data) return json.dumps(json_response)
def tmpl_styles(self): """Defines the local CSS styles and javascript used in the plugin""" styles = """ <style type="text/css"> .mandatory_field{ color:#ff0000 } .italics{ font-style:italic } .italics_small{ font-style:italic; font-size: 0.9em; } .clean_ok{ border:solid 1px #349534; background:#C9FFCA; color:#008000; font-size:14px; font-weight:bold; padding:4px; text-align:center; width: 650px; } .clean_error{ border:solid 1px #CC0000; background:#F7CBCA; color:#CC0000; font-size:14px; font-weight:bold; padding:4px; text-align:center; width: 650px; } #content {width:750px; font:90.1% arial, sans-serif;} .uploadform {margin:0 0 1em 0} .uploadform div {margin:0.5em 0} .uploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px} #docuploadform {margin:0 0 1em 0} #docuploadform div {margin:0.5em 0} #docuploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px} #error_div {color: red; font-style: bold; } div.ui-datepicker{ font-size:12px; } span.red{ color:#df0000; } span.green{ color:#060; background: transparent; } span.yellow{ color:#9f9b00; } #info_box{ border: 3px black solid; border-width: thin; width: 750px; } img.img_link { border-style: none; } fieldset label { float: left; width: 150px; } label.nowidth { width: auto; } .batchuploader_error { max-width: 650px; max-height: 326px; border:solid 1px #CC0000; background:#F7CBCA; overflow: auto; } #batchuploader_error_list{ list-style-type: none; padding-left: 10px; } #batchuploader_error_list li{ margin-bottom: 10px; } </style> """ styles += """ <link type="text/css" href="%(site_url)s/img/jquery-ui.css" rel="stylesheet" /> <script type="text/javascript"> function clearText(field){ if (field.value == field.defaultValue){ field.value = ''; } } function defText(field){ if (field.value == ''){ field.value = field.defaultValue; } } </script> <script type="text/javascript" src="%(site_url)s/js/jquery-ui.min.js"></script> <script type="text/javascript" src="%(site_url)s/%(script)s"></script> """ % {'site_url':CFG_SITE_URL, 'script': auto_version_url("js/batchuploader.js")} return styles