def render_mask_template(node, mfs, words=None, separator=""): mask, fields, labels_data = mfs metatext = list() for field in mask.getViewHTML([node], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f, f_name, f_label in labels_data: if f_name == field[0]: metatext.append("<b>%s:</b> %s" % (f_label, value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) return separator.join(metatext)
def show_node_text_orignal(self, words=None, language=None, separator="", labels=0): if separator == "": separator = "<br/>" metatext = list() mask = self.getMask("nodesmall") for m in self.getMasks("shortview", language=language): mask = m if mask: fields = mask.getMaskFields() for field in mask.getViewHTML([self], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f in fields: if f.getField().getName() == field[0]: metatext.append("<b>%s:</b> %s" % (f.getLabel(), value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) else: metatext.append('<smallview mask not defined>') return separator.join(metatext)
def show_node_text_shallow(self, words=None, language=None, separator="", labels=0): global maskcache_shallow def render_mask_template(node, mfs, words=None, separator=""): mask, fields, labels_data = mfs metatext = list() for field in mask.getViewHTML([node], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f, f_name, f_label in labels_data: if f_name == field[0]: metatext.append("<b>%s:</b> %s" % (f_label, value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) return separator.join(metatext) if not separator: separator = "<br/>" lookup_key = make_lookup_key(self, language, labels) if lookup_key in maskcache_shallow: mfs = maskcache_shallow[lookup_key] return render_mask_template(self, mfs, words=words, separator=separator) else: # this list will be cached to_be_cached = [] metatext = list() mask = self.getMask("nodesmall") for m in self.getMasks("shortview", language=language): mask = m if mask: fields = mask.getMaskFields() ##### def getNodeAttributeName(field): metafields = [ x for x in field.getChildren() if x.type == 'metafield' ] if len(metafields) != 1: logging.getLogger("error").error( "maskfield %s zero or multiple metafield child(s)" % field.id) return metafields[0].name ##### if labels: labels_data = [(f, f.getField().getName(), f.getLabel()) for f in fields] else: pass labels_data = [] for field in mask.getViewHTML([self], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f, f_name, f_label in labels_data: if f_name == field[0]: metatext.append("<b>%s:</b> %s" % (f_label, value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) to_be_cached = [mask, fields, labels_data] maskcache_shallow[lookup_key] = to_be_cached else: metatext.append('<smallview mask not defined>') return separator.join(metatext)
def render_mask_template(node, mfs, words=None, separator="", skip_empty_fields=True): """ mfs: [mask] + list_of_maskfields """ res = [] exception_count = {} mask = mfs[0] for node_attribute, fd in mfs[1:]: metafield_type = fd['metafield_type'] field_type = fd['field_type'] if metafield_type in ['date', 'url', 'hlist']: exception_count[ metafield_type] = exception_count.setdefault( metafield_type, 0) + 1 value = node.get(node_attribute) try: value = fd['metadatatype'].getFormatedValue( fd['element'], node, language=language, mask=mask)[1] except: value = fd['metadatatype'].getFormatedValue( fd['element'], node, language=language)[1] elif metafield_type in ['field']: if field_type in ['hgroup', 'vgroup']: _sep = '' if field_type == 'hgroup': fd['unit'] = '' # unit will be taken from definition of the hgroup use_label = False else: use_label = True value = getMetadataType(field_type).getViewHTML( fd['field'], # field [node], # nodes 0, # flags language=language, mask=mask, use_label=use_label) else: value = node.get(node_attribute) metadatatype = fd['metadatatype'] if hasattr(metadatatype, "language_snipper"): metafield = fd['element'] if (metafield.get("type") == "text" and metafield.get("valuelist") == "multilingual") \ or \ (metafield.get("type") in ['memo', 'htmlmemo'] and metafield.get("multilang") == '1'): value = metadatatype.language_snipper( value, language) if value.find('<') >= 0: # replace variables for var in re.findall(r'<(.+?)>', value): if var == "att:id": value = value.replace("<" + var + ">", node.id) elif var.startswith("att:"): val = node.get(var[4:]) if val == "": val = "____" value = value.replace("<" + var + ">", val) value = value.replace("<", "<").replace(">", ">") if value.find('<') >= 0: # replace variables for var in re.findall(r'\<(.+?)\>', value): if var == "att:id": value = value.replace("<" + var + ">", node.id) elif var.startswith("att:"): val = node.get(var[4:]) if val == "": val = "____" value = value.replace("<" + var + ">", val) value = value.replace("<", "<").replace(">", ">") if value.find('tal:') >= 0: context['node'] = node value = runTALSnippet(value, context) # don't escape before running TAL if (not value) and fd['default']: default = fd['default'] if fd['default_has_tal']: context['node'] = node value = runTALSnippet(default, context) else: value = default if skip_empty_fields and not value: continue if fd["unit"]: value = value + " " + fd["unit"] if fd["format"]: value = fd["format"].replace("<value>", value) if words: value = highlight(value, words, '<font class="hilite">', "</font>") res.append(fd["template"] % value) if exception_count and len(exception_count.keys()) > 1: pass return separator.join(res)
def render_mask_template(node, mask, field_descriptors, language, words=None, separator="", skip_empty_fields=True): res = [] for node_attribute, fd in field_descriptors: metafield_type = fd['metafield_type'] maskitem = fd['maskitem'] metafield = fd["metafield"] metatype = fd["metatype"] maskitem_type = fd["maskitem_type"] if metafield_type in ['date', 'url', 'hlist']: value = metatype.getFormattedValue(metafield, maskitem, mask, node, language)[1] elif metafield_type in ['field']: if maskitem_type in ['hgroup', 'vgroup']: _sep = '' if maskitem_type == 'hgroup': fd['unit'] = '' # unit will be taken from definition of the hgroup use_label = False else: use_label = True value = getMetadataType(maskitem_type).getViewHTML( metafield, [node], # nodes 0, # flags language=language, mask=mask, use_label=use_label) else: value = node.get_special(node_attribute) if hasattr(metatype, "language_snipper"): if (metafield.get("type") == "text" and metafield.get("valuelist") == "multilingual") \ or \ (metafield.get("type") in ['memo', 'htmlmemo'] and metafield.get("multilang") == '1'): value = metatype.language_snipper(value, language) if value.find('<') >= 0: # replace variables value = replace_attribute_variables(value, node.id, node.get_special, r'<(.+?)>', "<", ">") value = value.replace("<", "<").replace(">", ">") if value.find('<') >= 0: # replace variables value = replace_attribute_variables(value, node.id, node.get_special, r'\<(.+?)\>', "<", ">") value = value.replace("<", "<").replace(">", ">") default = fd['default'] if not value and default: value = default if skip_empty_fields and not value: continue if fd["unit"]: value = value + " " + fd["unit"] if fd["format"]: value = fd["format"].replace("<value>", value) if words: value = highlight(value, words, '<font class="hilite">', "</font>") res.append(fd["template"] % value) return separator.join(res)
def show_node_text_shallow(self, words=None, language=None, separator="", labels=0): global maskcache_shallow def render_mask_template(node, mfs, words=None, separator=""): mask, fields, labels_data = mfs metatext = list() for field in mask.getViewHTML([node], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f, f_name, f_label in labels_data: if f_name == field[0]: metatext.append("<b>%s:</b> %s" % (f_label, value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) return separator.join(metatext) if not separator: separator = "<br/>" lookup_key = make_lookup_key(self, language, labels) if lookup_key in maskcache_shallow: mfs = maskcache_shallow[lookup_key] return render_mask_template(self, mfs, words=words, separator=separator) else: # this list will be cached to_be_cached = [] metatext = list() mask = self.getMask("nodesmall") for m in self.getMasks("shortview", language=language): mask = m if mask: fields = mask.getMaskFields() def getNodeAttributeName(field): metafields = [x for x in field.getChildren() if x.type == 'metafield'] if len(metafields) != 1: logging.getLogger("error").error("maskfield %s zero or multiple metafield child(s)" % field.id) return metafields[0].name if labels: labels_data = [(f, f.getField().getName(), f.getLabel()) for f in fields] else: pass labels_data = [] for field in mask.getViewHTML([self], VIEW_DATA_ONLY, language=language, mask=mask): if len(field) >= 2: value = field[1] else: value = "" if words is not None: value = highlight(value, words, '<font class="hilite">', "</font>") if value: if labels: for f, f_name, f_label in labels_data: if f_name == field[0]: metatext.append("<b>%s:</b> %s" % (f_label, value)) break else: if field[0].startswith("author"): value = '<span class="author">%s</span>' % value if field[0].startswith("subject"): value = '<b>%s</b>' % value metatext.append(value) to_be_cached = [mask, fields, labels_data] maskcache_shallow[lookup_key] = to_be_cached else: metatext.append('<smallview mask not defined>') return separator.join(metatext)
def render_mask_template(node, mfs, words=None, separator="", skip_empty_fields=True): """ mfs: [mask] + list_of_maskfields """ res = [] exception_count = {} mask = mfs[0] for node_attribute, fd in mfs[1:]: metafield_type = fd['metafield_type'] field_type = fd['field_type'] if metafield_type in ['date', 'url', 'hlist']: exception_count[metafield_type] = exception_count.setdefault(metafield_type, 0) + 1 value = node.get(node_attribute) try: value = fd['metadatatype'].getFormatedValue(fd['element'], node, language=language, mask=mask)[1] except: value = fd['metadatatype'].getFormatedValue(fd['element'], node, language=language)[1] elif metafield_type in ['field']: if field_type in ['hgroup', 'vgroup']: _sep = '' if field_type == 'hgroup': fd['unit'] = '' # unit will be taken from definition of the hgroup use_label = False else: use_label = True value = getMetadataType(field_type).getViewHTML( fd['field'], # field [node], # nodes 0, # flags language=language, mask=mask, use_label=use_label) else: value = node.get(node_attribute) metadatatype = fd['metadatatype'] if hasattr(metadatatype, "language_snipper"): metafield = fd['element'] if (metafield.get("type") == "text" and metafield.get("valuelist") == "multilingual") \ or \ (metafield.get("type") in ['memo', 'htmlmemo'] and metafield.get("multilang") == '1'): value = metadatatype.language_snipper(value, language) if value.find('<') >= 0: # replace variables for var in re.findall(r'<(.+?)>', value): if var == "att:id": value = value.replace("<" + var + ">", node.id) elif var.startswith("att:"): val = node.get(var[4:]) if val == "": val = "____" value = value.replace("<" + var + ">", val) value = value.replace("<", "<").replace(">", ">") if value.find('<') >= 0: # replace variables for var in re.findall(r'\<(.+?)\>', value): if var == "att:id": value = value.replace("<" + var + ">", node.id) elif var.startswith("att:"): val = node.get(var[4:]) if val == "": val = "____" value = value.replace("<" + var + ">", val) value = value.replace("<", "<").replace(">", ">") if value.find('tal:') >= 0: context['node'] = node value = runTALSnippet(value, context) # don't escape before running TAL if (not value) and fd['default']: default = fd['default'] if fd['default_has_tal']: context['node'] = node value = runTALSnippet(default, context) else: value = default if skip_empty_fields and not value: continue if fd["unit"]: value = value + " " + fd["unit"] if fd["format"]: value = fd["format"].replace("<value>", value) if words: value = highlight(value, words, '<font class="hilite">', "</font>") res.append(fd["template"] % value) if exception_count and len(exception_count.keys()) > 1: pass return separator.join(res)