def print_record( recID, format="hb", ot="", ln=CFG_SITE_LANG, decompress=zlib.decompress, search_pattern=None, user_info=None, verbose=0, sf="", so="d", sp="", rm="", brief_links=True, ): """ Print record 'recID' formatted according to 'format'. 'sf' is sort field and 'rm' is ranking method that are passed here only for proper linking purposes: e.g. when a certain ranking method or a certain sort field was selected, keep it selected in any dynamic search links that may be printed. """ from invenio_formatter import format_record return ( format_record(recID, of=format, ln=ln, verbose=verbose, search_pattern=search_pattern) if record_exists(recID) != 0 else "" )
def formatter(bwo, **kwargs): """Nicely format the record.""" from pprint import pformat from invenio_records.api import Record try: data = bwo.data except AttributeError: data = bwo.get_data() if not data: return '' formatter = kwargs.get("formatter", None) of = kwargs.get("of", None) if formatter: # A separate formatter is supplied return formatter(data) if isinstance(data, collections.Mapping): # Dicts are cool on its own, but maybe its SmartJson (record) try: data = Record(data.dumps()).legacy_export_as_marc() except (TypeError, KeyError): pass if isinstance(data, string_types): # We can try formatter! # If already XML, format_record does not like it. if of and of != 'xm': try: from invenio_formatter import format_record formatted_data = format_record( recID=None, of=of, xml_record=data ) except TypeError: # Wrong kind of type pass else: # So, XML then from xml.dom.minidom import parseString try: unpretty_data = parseString(data) formatted_data = unpretty_data.toprettyxml() except TypeError: # Probably not proper XML string then return "Data cannot be parsed: %s" % (data,) except Exception: # Just return raw string pass if not formatted_data: formatted_data = data if isinstance(formatted_data, dict): formatted_data = pformat(formatted_data) return formatted_data
def print_record(recID, format='hb', ot='', ln=CFG_SITE_LANG, decompress=zlib.decompress, search_pattern=None, user_info=None, verbose=0, sf='', so='d', sp='', rm='', brief_links=True): """ Print record 'recID' formatted according to 'format'. 'sf' is sort field and 'rm' is ranking method that are passed here only for proper linking purposes: e.g. when a certain ranking method or a certain sort field was selected, keep it selected in any dynamic search links that may be printed. """ from invenio_formatter import format_record return format_record( recID, of=format, ln=ln, verbose=verbose, search_pattern=search_pattern) if record_exists(recID) != 0 else ""
def formatter(bwo, **kwargs): """Nicely format the record.""" from pprint import pformat from invenio_records.api import Record try: data = bwo.data except AttributeError: data = bwo.get_data() if not data: return '' formatter = kwargs.get("formatter", None) of = kwargs.get("of", None) if formatter: # A separate formatter is supplied return formatter(data) if isinstance(data, collections.Mapping): # Dicts are cool on its own, but maybe its SmartJson (record) try: data = Record(data.dumps()).legacy_export_as_marc() except (TypeError, KeyError): pass if isinstance(data, string_types): # We can try formatter! # If already XML, format_record does not like it. if of and of != 'xm': try: from invenio_formatter import format_record formatted_data = format_record(recID=None, of=of, xml_record=data) except TypeError: # Wrong kind of type pass else: # So, XML then from xml.dom.minidom import parseString try: unpretty_data = parseString(data) formatted_data = unpretty_data.toprettyxml() except TypeError: # Probably not proper XML string then return "Data cannot be parsed: %s" % (data, ) except Exception: # Just return raw string pass if not formatted_data: formatted_data = data if isinstance(formatted_data, dict): formatted_data = pformat(formatted_data) return formatted_data
def _format_record(record, of='hd', user_info=current_user, *args, **kwargs): from invenio_formatter import format_record return format_record(record, of, user_info=user_info, *args, **kwargs)
def formatter(cls, obj, **kwargs): """Nicely format the record.""" try: model = cls.model(obj) record = get_record_from_model(model) except TypeError as err: return "Error: {0}".format(err) if not record: return "" if kwargs.get('of'): if "recid" not in record: record['recid'] = None return format_record(record=record, of=kwargs.get('of')) return render_template( 'format/record/Holding_Pen_HTML_detailed.tpl', record=record )
def datacite_register(recid): """Register a DOI for new publication. If it fails, it will retry every 10 minutes for 1 hour. """ record = get_record(recid) if record is None: logger.debug("Record %s not found" % recid) return doi_val = record.get(cfg['PIDSTORE_DATACITE_RECORD_DOI_FIELD'], None) logger.debug("Found DOI %s in record %s" % (doi_val, recid)) pid = PersistentIdentifier.get("doi", doi_val) if not pid: logger.debug("DOI not locally managed.") return else: logger.debug("DOI locally managed.") if not pid.has_object("rec", recid): raise Exception( "DOI %s is not assigned to record %s." % (doi_val, recid)) if pid.is_new() or pid.is_reserved(): logger.info("Registering DOI %s for record %s" % (doi_val, recid)) url = "%s/record/%s" % ( cfg.get('PIDSTORE_DATACITE_SITE_URL', cfg['CFG_SITE_URL']), recid ) doc = format_record(record, cfg['PIDSTORE_DATACITE_OUTPUTFORMAT']) if not pid.register(url=url, doc=doc): m = "Failed to register DOI %s" % doi_val logger.error(m + "\n%s\n%s" % (url, doc)) if not datacite_register.request.is_eager: raise datacite_register.retry(exc=Exception(m)) else: logger.info("Successfully registered DOI %s." % doi_val)
def detailed_record_container_top(self, recid, tabs, ln=CFG_SITE_LANG, show_similar_rec_p=True, creationdate=None, modificationdate=None, show_short_rec_p=True, citationnum=-1, referencenum=-1, discussionnum=-1, include_jquery = False, include_mathjax = False): """Prints the box displayed in detailed records pages, with tabs at the top. Returns content as it is if the number of tabs for this record is smaller than 2 Parameters: @param recid: int - the id of the displayed record @param tabs: ** - the tabs displayed at the top of the box. @param ln: *string* - the language of the page in which the box is displayed @param show_similar_rec_p: *bool* print 'similar records' link in the box @param creationdate: *string* - the creation date of the displayed record @param modificationdate: *string* - the last modification date of the displayed record @param show_short_rec_p: *boolean* - prints a very short version of the record as reminder. @param citationnum: show (this) number of citations in the citations tab @param referencenum: show (this) number of references in the references tab @param discussionnum: show (this) number of comments/reviews in the discussion tab """ # Prepare restriction flag restriction_flag = '' # If no tabs, returns nothing (excepted if restricted) if len(tabs) <= 1: return restriction_flag # Build the tabs at the top of the page out_tabs = '' if len(tabs) > 1: first_tab = True for (label, url, selected, enabled) in tabs: addnum = "" if (citationnum > -1) and url.count("/citation") == 1: addnum = "(" + str(citationnum) + ")" if (referencenum > -1) and url.count("/references") == 1: addnum = "(" + str(referencenum) + ")" if (discussionnum > -1) and url.count("/comments") == 1: addnum = "(" + str(discussionnum) + ")" css_class = [] if selected: css_class.append('on') if first_tab: css_class.append('first') first_tab = False if not enabled: css_class.append('disabled') css_class = ' class="%s"' % ' '.join(css_class) if not enabled: out_tabs += '<li%(class)s><a>%(label)s %(addnum)s</a></li>' % \ {'class':css_class, 'label':label, 'addnum':addnum} else: out_tabs += '<li%(class)s><a href="%(url)s">%(label)s %(addnum)s </a></li>' % \ {'class':css_class, 'url':url, 'label':label, 'addnum':addnum} if out_tabs != '': out_tabs = ''' <div class="detailedrecordtabs"> <div> <ul class="detailedrecordtabs">%s</ul> <div id="tabsSpacer" style="clear:both;height:0px"> </div></div> </div>''' % out_tabs # Add the clip icon and the brief record reminder if necessary record_brief = '' if show_short_rec_p: record_brief = format_record(recID=recid, of='hs', ln=ln) record_brief = '''<div id="detailedrecordshortreminder"> <div id="clip"> </div> <div id="HB"> %(record_brief)s </div> </div> <div style="clear:both;height:1px"> </div> ''' % {'record_brief': record_brief} additional_scripts = "" if include_jquery: additional_scripts += """<script type="text/javascript" src="%s/js/jquery.min.js">' \ '</script>\n""" % (CFG_BASE_URL, ) if include_mathjax: additional_scripts += get_mathjax_header() # Print the content out = """ %(additional_scripts)s<div class="detailedrecordbox"> %(tabs)s <div class="detailedrecordboxcontent"> <div class="top-left-folded"></div> <div class="top-right-folded"></div> <div class="inside"> <!--<div style="height:0.1em;"> </div> <p class="notopgap"> </p>--> %(record_brief)s """ % {'additional_scripts': additional_scripts, 'tabs':out_tabs, 'record_brief':record_brief} out = restriction_flag + out return out
def detailed_record_container_top(self, recid, tabs, ln=CFG_SITE_LANG, show_similar_rec_p=True, creationdate=None, modificationdate=None, show_short_rec_p=True, citationnum=-1, referencenum=-1, discussionnum=-1, include_jquery=False, include_mathjax=False): """Prints the box displayed in detailed records pages, with tabs at the top. Returns content as it is if the number of tabs for this record is smaller than 2 Parameters: @param recid: int - the id of the displayed record @param tabs: ** - the tabs displayed at the top of the box. @param ln: *string* - the language of the page in which the box is displayed @param show_similar_rec_p: *bool* print 'similar records' link in the box @param creationdate: *string* - the creation date of the displayed record @param modificationdate: *string* - the last modification date of the displayed record @param show_short_rec_p: *boolean* - prints a very short version of the record as reminder. @param citationnum: show (this) number of citations in the citations tab @param referencenum: show (this) number of references in the references tab @param discussionnum: show (this) number of comments/reviews in the discussion tab """ # load the right message language _ = gettext_set_language(ln) # Prepare restriction flag restriction_flag = '' # If no tabs, returns nothing (excepted if restricted) if len(tabs) <= 1: return restriction_flag # Build the tabs at the top of the page out_tabs = '' if len(tabs) > 1: first_tab = True for (label, url, selected, enabled) in tabs: addnum = "" if (citationnum > -1) and url.count("/citation") == 1: addnum = "(" + str(citationnum) + ")" if (referencenum > -1) and url.count("/references") == 1: addnum = "(" + str(referencenum) + ")" if (discussionnum > -1) and url.count("/comments") == 1: addnum = "(" + str(discussionnum) + ")" css_class = [] if selected: css_class.append('on') if first_tab: css_class.append('first') first_tab = False if not enabled: css_class.append('disabled') css_class = ' class="%s"' % ' '.join(css_class) if not enabled: out_tabs += '<li%(class)s><a>%(label)s %(addnum)s</a></li>' % \ {'class':css_class, 'label':label, 'addnum':addnum} else: out_tabs += '<li%(class)s><a href="%(url)s">%(label)s %(addnum)s </a></li>' % \ {'class':css_class, 'url':url, 'label':label, 'addnum':addnum} if out_tabs != '': out_tabs = ''' <div class="detailedrecordtabs"> <div> <ul class="detailedrecordtabs">%s</ul> <div id="tabsSpacer" style="clear:both;height:0px"> </div></div> </div>''' % out_tabs # Add the clip icon and the brief record reminder if necessary record_brief = '' if show_short_rec_p: record_brief = format_record(recID=recid, of='hs', ln=ln) record_brief = '''<div id="detailedrecordshortreminder"> <div id="clip"> </div> <div id="HB"> %(record_brief)s </div> </div> <div style="clear:both;height:1px"> </div> ''' % { 'record_brief': record_brief } additional_scripts = "" if include_jquery: additional_scripts += """<script type="text/javascript" src="%s/js/jquery.min.js">' \ '</script>\n""" % (CFG_BASE_URL, ) if include_mathjax: additional_scripts += get_mathjax_header() # Print the content out = """ %(additional_scripts)s<div class="detailedrecordbox"> %(tabs)s <div class="detailedrecordboxcontent"> <div class="top-left-folded"></div> <div class="top-right-folded"></div> <div class="inside"> <!--<div style="height:0.1em;"> </div> <p class="notopgap"> </p>--> %(record_brief)s """ % { 'additional_scripts': additional_scripts, 'tabs': out_tabs, 'record_brief': record_brief } out = restriction_flag + out return out