Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
item = parent.getChildren().sort_by_orderpos()[index]
ptype = parent.get("type")
pitems = len(parent.getChildren())
field = item.getField()
ret = ''
label = ''
description = ''
if field:
f = getMetadataType(field.get("type"))
fieldstring = f.getEditorHTML(field, width=item.getWidth(), value=item.getDefault(), language=language) + ' ' + item.getUnit()
else: # node for export mask
attribute = q(Node).get(item.get("attribute"))
field = item
fieldstring = getMetadataType("mappingfield").getEditorHTML(
field, width=item.getWidth(), value=attribute.getName(), language=language) + ' ' + item.getUnit()
if item.getDescription() != "":
description = '<div id="div_description"><a href="#"> <img border="0" src="/img/tooltip.png"></a></div>' % (
field.id, item.id)
if len(item.getLabel()) > 0 and item.getLabel() != "mapping":
label = item.getLabel() + ': '
required = ""
if item.getRequired():
required = '<span class="required">*</span>'
if ptype in("vgroup", "hgroup") or not sub:
label = '<div class="label">%s %s</div>%s' % (label, required, description)
else:
label += required
fields.append(field)
else:
for m in metadatatype.getMasks():
if ustr(m.id) == ustr(req.params.get("pid")):
for field in m.getChildren():
fields.append(field)
fields.sort(lambda x, y: cmp(x.getOrderPos(), y.getOrderPos()))
add_values = []
val = u""
if item.getField():
val = item.getField().getValues()
db.session.commit()
for t in getMetaFieldTypeNames():
f = getMetadataType(t)
add_values.append(f.getMaskEditorHTML(val, metadatatype=metadatatype, language=lang(req)))
metafields = metadatatype.getMetaFields()
metafields.sort(lambda x, y: cmp(x.getName().lower(), y.getName().lower()))
metafieldtypes = getMetaFieldTypes().values()
metafieldtypes.sort(lambda x, y: cmp(translate(x.getName(), request=req).lower(), translate(y.getName(), request=req).lower()))
add_descriptions = []
for metafield in metafields:
add_descriptions.append('<div name="%s" id="div_%d" style="display:none">' %
(metafield.id, metafield.name, metafield.getDescription()))
v = {}
v["op"] = req.params.get("op", "")
v["pid"] = req.params.get("pid", "")</div>
if len(itemlist) > 0:
# parent still not existing
item = q(Node).get(itemlist[index])
pitems = len(itemlist)
else:
item = parent.getChildren().sort_by_orderpos()[index]
ptype = parent.get("type")
pitems = len(parent.getChildren())
field = item.getField()
ret = ''
label = ''
description = ''
if field:
f = getMetadataType(field.get("type"))
fieldstring = f.getEditorHTML(field, width=item.getWidth(), value=item.getDefault(), language=language) + ' ' + item.getUnit()
else: # node for export mask
attribute = q(Node).get(item.get("attribute"))
field = item
fieldstring = getMetadataType("mappingfield").getEditorHTML(
field, width=item.getWidth(), value=attribute.getName(), language=language) + ' ' + item.getUnit()
if item.getDescription() != "":
description = '<div id="div_description"><a href="#"> <img border="0" src="/img/tooltip.png"></a></div>' % (
field.id, item.id)
if len(item.getLabel()) > 0 and item.getLabel() != "mapping":
label = item.getLabel() + ': '
required = ""
if item.getRequired():
required = '<span class="required">*</span>'
s2 = self.replaceStr(node.get(attrnode.getName()), var[20:])
s = s.replace("[" + var + "]", s2)
elif var.startswith("value|substring"):
s2 = self.subStr(node.get(attrnode.getName()), var[16:])
s = s.replace("[" + var + "]", s2)
elif var.startswith("value|nodename"):
try:
s2 = tree.getNode(node.get(attrnode.getName())).getName()
except:
s2 = node.getName()
s = s.replace("[" + var + "]", s2)
elif var == "value":
v = getMetadataType(attrnode.getFieldtype()).getFormatedValue(attrnode, node)[1]
if v == "":
v = node.get(attrnode.getName())
if v == "" and default != "":
v = default
if "t" in options and not v.isdigit():
v = '"' + v + '"'
s = s.replace("[value]", v)
elif var == "ns":
ns = ""
for mapping in attrnode.get("exportmapping").split(";"):
n = tree.getNode(mapping)
if n.getNamespace() != "" and n.getNamespaceUrl() != "":
ns += 'xmlns:' + n.getNamespace() + '="' + n.getNamespaceUrl() + '" '
s = s.replace("[" + var + "]", ns)
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
for item in field.getChildren().sort_by_orderpos():
f = getMetadataType(item.get("type"))
ret.append(f.getViewHTML(item, nodes, flags, language=language))
return ret
else:
if use_label:
snippets = ['<div class="mask_row hgroup hgroup-%s"><div class="mask_label">%s: </div><div class="mask_value">' % (field.id, field.getLabel())]
else:
snippets = ['<div class="mask_row hgroup hgroup-%s"><div class="mask_value">' % (field.id)]
raw_values = [' ']
sep = ''
has_raw_value = False # skip group display if no item has raw_value
items = field.getChildren().sort_by_orderpos()
len_items = len(items)
for i, item in enumerate(items):
f = getMetadataType(item.get("type"))
raw_value = f.getViewHTML(item, nodes, flags | VIEW_SUB_ELEMENT, language=language)
if raw_value.strip():
raw_values.append(raw_value)
if not raw_value == ' ':
has_raw_value = True
if sep:
snippets.append(sep)
sep = item.get('separator', ' ')
snippets.append('<span class="hgroup_item">%s</span>' % raw_value)
else:
sep = '' # no separator before or after empty sub element
unit = field.get('unit').strip()
if not has_raw_value:
snippets = [] # no value when all sub elements are empty
elif raw_values and unit:</div></div></div></div>
def handle_json_request(req):
s = []
if req.args.get("cmd") == "get_list_smi":
searchmaskitem_id = req.params.get("searchmaskitem_id")
f = None
g = None
if searchmaskitem_id and searchmaskitem_id != "full":
f = q(Node).get(searchmaskitem_id).getFirstField()
if not f: # All Metadata
f = g = getMetadataType("text")
container_id = req.args.get("container_id")
container = q(Container).get(container_id) if container_id else None
if container is None or not container.has_read_access():
container = get_collections_node()
s = [
f.getSearchHTML(
Context(
g,
value=req.args.get("query_field_value"),
width=174,
name="query" + str(req.args.get("fieldno")),
language=lang(req),
def getMetaHTML(self, parent, index, sub=False, language=None, fieldlist={}):
item = parent.getChildren().sort_by_orderpos()[index]
ret = ''
i = 0
if not sub:
ret += '<div class="row" id="' + unicode(item.id) + '">'
ret += '<fieldset style="cursor:hand">'
if item.getLabel() != "":
ret += '<legend>' + item.getLabel() + '</legend>'
for field in item.getChildren().sort_by_orderpos():
f = getMetadataType(field.get("type"))
ret += f.getMetaHTML(item, i, True, language=language, fieldlist=fieldlist) + '<br>'
i += 1
if len(item.getChildren()) == 0:
ret += '<span>- keine Felder definiert -</span>'
ret += '</fieldset>'
if not sub:
ret += '<div style="display:none" id="' + unicode(item.id) + \
'_sub" align="right"><small style="color:silver">(' + (item.get("type")) + ')</small>'
if index > 0:
ret += '<input name="up_' + \
unicode(item.id) + '" src="/img/uparrow.png" type="image">'
else:
ret += ' '</div></div>
def getSearchField(self, pos, width=174):
try:
searchmaskitem_id = self.searchmaskitem_ids[pos]
searchmaskitem = self.searchmask.children.filter_by(id=searchmaskitem_id).scalar() if searchmaskitem_id else None
field = searchmaskitem.children.first() if searchmaskitem else None
g = None
if field is None: # All Metadata
# quick&dirty
field = getMetadataType("text")
return field.getSearchHTML(Context(
field,
value=self.values[pos],
width=width,
name="query" + unicode(pos),
language=self.lang,
container=self.container,
user=current_user,
ip=self.ip))
except:
# workaround for unknown error
logg.exception("exception in getSearchField, return empty string")
return ""
def getFormHTML(self, field, nodes, req):
ret = '<fieldset>'
if field.getLabel() != "":
ret += '<legend>' + field.getLabel() + '</legend>'
for item in field.getChildren().sort_by_orderpos():
if item.get("type") in ("hgroup", "vgroup", "field", "label"):
f = getMetadataType(item.get("type"))
ret += f.getFormHTML(item, nodes, req)
else:
print "...wrong field..."
ret += '</fieldset>'
return ret