def format_element(bfo): """ Creates a navigation for comments. """ # get variables this_recid = bfo.control_field('001') try: this_content = bfo.fields('520__a')[0] except: return "" try: this_author = bfo.fields('100__a')[0] except: return "" this_limit_content = get_contextual_content(this_content, [], max_lines=2)[0] menu_recids = [] current_language = bfo.lang post_recid = get_parent_post(this_recid) menu_recids = get_comments(post_recid, newest_first=True) try: menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"][current_language] except: menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"]['en'] for recid in menu_recids: if str(this_recid) == str(recid): menu_out += '<div class="active"><div class="litem"><b>%s</b>: %s [...]</div></div>' % (this_author, this_limit_content) else: temp_rec = BibFormatObject(recid) content = temp_rec.fields('520__a')[0] limit_content = get_contextual_content(content, [], max_lines=1)[0] try: author = temp_rec.fields('100__a')[0] except: author = 'Anonymous' menu_out += '<div class="litem"><a href="%s/record/%s%s"><b>%s</b>: %s [...]</a></div>' % (CFG_SITE_URL, recid, (bfo.lang=="fr") and "?ln=fr" or "?ln=en", author, limit_content) return menu_out
escape_mode_int = int(escape) except ValueError, e: escape_mode_int = 0 abstract_en = bfo.fields('520__a', escape=escape_mode_int) abstract_en.extend(bfo.fields('520__b', escape=escape_mode_int)) abstract_en = separator_en.join(abstract_en) abstract_fr = bfo.fields('590__a', escape=escape_mode_int) abstract_fr.extend(bfo.fields('590__b', escape=escape_mode_int)) abstract_fr = separator_fr.join(abstract_fr) if contextual == 'yes' and limit != "" and \ limit.isdigit() and int(limit) > 0: context_en = bibformat_utils.get_contextual_content(abstract_en, bfo.search_pattern, max_lines=int(limit)) #FIXME add something like [...] before and after #contextual sentences when not at beginning/end of abstract #if not abstract_en.strip().startswith(context_en[0].strip()): # out += '[...]' abstract_en = "<br/>".join(context_en) context_fr = bibformat_utils.get_contextual_content(abstract_fr, bfo.search_pattern, max_lines=int(limit)) abstract_fr = "<br/>".join(context_fr) if len(abstract_en) > 0 and 'en' in languages: out += prefix_en
def format(bfo, limit, max_chars, extension="[...] ", languages='en', latex="no"): """ Prints the abstract of a record in HTML. By default prints English and French versions. @param prefix_en a prefix for english abstract (printed only if english abstract exists) @param prefix_fr a prefix for french abstract (printed only if french abstract exists) @param limit the maximum number of sentences of the abstract to display (for each language) @param max_chars the maximum number of chars of the abstract to display (for each language) @param extension a text printed after abstracts longer than parameter 'limit' @param suffix_en a suffix for english abstract(printed only if english abstract exists) @param suffix_fr a suffix for french abstract(printed only if french abstract exists) @parmm contextual if 'yes' prints sentences the most relative to user search keyword (if limit < abstract) @param highlight if 'yes' highlights words from user search keyword """ out = '' abstract_en = [] abstract_fr = [] for abstract in bfo.fields('520__', escape=2): lang = abstract.get('9', 'eng') if lang == 'eng': abstract_en.append(abstract.get('a', '')) else: abstract_fr.append(abstract.get('a', '')) #abstract_en = bfo.fields('520__a', escape=2) #abstract_en.extend(bfo.fields('520__b', escape=2)) abstract_en = "<br />".join(abstract_en) #abstract_fr = bfo.fields('590__a', escape=2) #abstract_fr.extend(bfo.fields('590__b', escape=2)) abstract_fr = "<br />".join(abstract_fr) if limit != "" and limit.isdigit() and int(limit) > 0: context_en = bibformat_utils.get_contextual_content( abstract_en, bfo.search_pattern, max_lines=int(limit)) #FIXME add something like [...] before and after #contextual sentences when not at beginning/end of abstract #if not abstract_en.strip().startswith(context_en[0].strip()): # out += '[...]' abstract_en = "<br/>".join(context_en) context_fr = bibformat_utils.get_contextual_content( abstract_fr, bfo.search_pattern, max_lines=int(limit)) abstract_fr = "<br/>".join(context_fr) if len(abstract_en) > 0 and 'en' in languages: print_extension = False if max_chars != "" and max_chars.isdigit( ) and int(max_chars) < len(abstract_en): print_extension = True abstract_en = abstract_en[:int(max_chars)] if limit != "" and limit.isdigit(): s_abstract = abstract_en.split(".") if int(limit) < len(s_abstract): print_extension = True s_abstract = s_abstract[:int(limit)] #for sentence in s_abstract: # out += sentence + "." out = '.'.join(s_abstract) # Add final dot if needed if abstract_en.endswith('.'): out += '.' if print_extension: out += " " + extension else: out += abstract_en if len(abstract_fr) > 0 and 'fr' in languages: print_extension = False if max_chars != "" and max_chars.isdigit() and \ int(max_chars) < len(abstract_fr): print_extension = True abstract_fr = abstract_fr[:int(max_chars)] if limit != "" and limit.isdigit(): s_abstract = abstract_fr.split(".") if int(limit) < len(s_abstract): print_extension = True s_abstract = s_abstract[:int(limit)] #for sentence in s_abstract: # out += sentence + "." out = '.'.join(s_abstract) # Add final dot if needed if abstract_fr.endswith('.'): out += '.' if print_extension: out += " " + extension else: out += abstract_fr if latex == "yes": return fix_latex_formulas(out) else: return out
try: escape_mode_int = int(escape) except ValueError, e: escape_mode_int = 0 abstract_en = bfo.fields('520__a', escape=escape_mode_int) abstract_en.extend(bfo.fields('520__b', escape=escape_mode_int)) abstract_en = separator_en.join(abstract_en) abstract_fr = bfo.fields('590__a', escape=escape_mode_int) abstract_fr.extend(bfo.fields('590__b', escape=escape_mode_int)) abstract_fr = separator_fr.join(abstract_fr) if contextual == 'yes' and limit != "" and \ limit.isdigit() and int(limit) > 0: context_en = bibformat_utils.get_contextual_content( abstract_en, bfo.search_pattern, max_lines=int(limit)) #FIXME add something like [...] before and after #contextual sentences when not at beginning/end of abstract #if not abstract_en.strip().startswith(context_en[0].strip()): # out += '[...]' abstract_en = "<br/>".join(context_en) context_fr = bibformat_utils.get_contextual_content( abstract_fr, bfo.search_pattern, max_lines=int(limit)) abstract_fr = "<br/>".join(context_fr) if len(abstract_en) > 0 and 'en' in languages: out += prefix_en print_extension = False
out = "" try: escape_mode_int = int(escape) except ValueError, e: escape_mode_int = 0 abstract = bfo.fields('520__a', escape=escape_mode_int) # abstract.extend(bfo.fields('520__b', escape=escape_mode_int)) abstract = separator.join(abstract) if contextual == 'yes' and limit != "" and \ limit.isdigit() and int(limit) > 0: context = bibformat_utils.get_contextual_content(abstract, bfo.search_pattern, max_lines=int(limit)) abstract = "<br/>".join(context) if abstract: out += prefix print_extension = False if max_chars != "" and max_chars.isdigit() and \ int(max_chars) < len(abstract): print_extension = True abstract = abstract[:int(max_chars)] if limit != "" and limit.isdigit(): s_abstract = abstract.split(". ")