def getLabelForAttributename(mdt_name, attr_name, maskname_list): res = attr_name try: mdt = tree.getRoot('metadatatypes').getChild(mdt_name) field = [x for x in getFieldsForMeta(mdt_name) if x.name == attr_name][0] masks = [] for maskname in maskname_list: mask = mdt.getChild(maskname) if mask.type == 'mask': masks.append(mask) set_maskitems_for_field = set( [x for x in field.getParents() if x.type == 'maskitem']) for mask in masks: maskitems = list( set_maskitems_for_field.intersection(set(mask.getChildren()))) if maskitems: return maskitems[0].name except: pass return res
def showFieldOverview(req): path = req.path[1:].split("/") fields = getFieldsForMeta(path[1]) fields.sort(lambda x, y: cmp(x.getOrderPos(), y.getOrderPos())) v = {} v["metadatatype"] = getMetaType(path[1]) v["metafields"] = fields v["fieldoptions"] = fieldoption v["fieldtypes"] = getMetaFieldTypeNames() return req.getTAL("web/admin/modules/metatype.html", v, macro="show_fieldoverview")
def showFieldOverview(req): path = req.path[1:].split("/") fields = getFieldsForMeta(path[1]) fields.sort(lambda x, y: cmp(x.orderpos, y.orderpos)) v = {} v["metadatatype"] = getMetaType(path[1]) v["metafields"] = fields v["fieldoptions"] = fieldoption v["fieldtypes"] = getMetaFieldTypeNames() v["csrf"] = req.csrf_token.current_token return req.getTAL("web/admin/modules/metatype.html", v, macro="show_fieldoverview")
def getLabelForAttributename(mdt_name, attr_name, maskname_list): res = attr_name try: mdt = tree.getRoot('metadatatypes').getChild(mdt_name) field = [x for x in getFieldsForMeta(mdt_name) if x.name == attr_name][0] masks = [] for maskname in maskname_list: mask = mdt.getChild(maskname) if mask.type == 'mask': masks.append(mask) set_maskitems_for_field = set([x for x in field.getParents() if x.type == 'maskitem']) for mask in masks: maskitems = list(set_maskitems_for_field.intersection(set(mask.getChildren()))) if maskitems: return maskitems[0].name except: pass return res
def FieldDetail(req, pid, id, err=0): _option = "" for key in req.params.keys(): if key.startswith("option_"): _option += key[7] if err == 0 and id == "": # new field field = Metafield(u"") db.session.commit() elif id != "": # edit field field = q(Metadatatype).get(pid).children.filter_by(name=id, type=u'metafield').scalar() else: # error filling values _fieldvalue = "" if req.params.get('mtype', '') + "_value" in req.params.keys(): _fieldvalue = ustr(req.params[req.params.get('mtype', '') + "_value"]) if (req.params.get("mname") == ""): field = Metafield(req.params.get("orig_name")) else: field = Metafield(req.params.get("mname")) field.setLabel(req.params.get("mlabel")) field.setOrderPos(req.params.get("orderpos")) field.setFieldtype(req.params.get("mtype")) field.setOption(_option) field.setValues(_fieldvalue) field.setDescription(req.params.get("mdescription")) db.session.commit() attr = {} metadatatype = getMetaType(pid) for t in metadatatype.getDatatypes(): content_class = Node.get_class_for_typestring(t) node = content_class(name=u'') try: attr.update(node.getTechnAttributes()) except AttributeError: logg.exception("attribute error in FieldDetail, continue") continue metafields = {} for fields in getFieldsForMeta(pid): if fields.getType() != "union": metafields[fields.name] = fields v = getAdminStdVars(req) v["metadatatype"] = metadatatype v["metafield"] = field v["error"] = err v["fieldtypes"] = getMetaFieldTypeNames() v["dateoptions"] = dateoption v["datatypes"] = attr v["requiredoptions"] = requiredoption v["fieldoptions"] = fieldoption v["metafields"] = metafields v["filtertype"] = req.params.get("filtertype", "") v["actpage"] = req.params.get("actpage") v["icons"] = {"externer Link": "/img/extlink.png", "Email": "/img/email.png"} v["url_targets"] = {"selbes Fenster": "same", "neues Fenster": "_blank"} v["valuelist"] = ("", "", "", "") if field.getFieldtype() == "url": v["valuelist"] = field.getValueList() while len(v["valuelist"]) != 4: v["valuelist"].append("") else: v["valuelist"] = field.getValueList() v["field"] = None if field.id: v["field"] = field v["adminfields"] = [] for t in getMetaFieldTypeNames(): f = getMetadataType(t) if 'attr_dict' in inspect.getargspec(f.getMaskEditorHTML).args: attr_dict = dict(field.attrs.items()) v["adminfields"] .append(f.getMaskEditorHTML(v["field"], metadatatype=metadatatype, language=lang(req), attr_dict=attr_dict)) else: v["adminfields"] .append(f.getMaskEditorHTML(v["field"], metadatatype=metadatatype, language=lang(req))) db.session.commit() return req.getTAL("web/admin/modules/metatype_field.html", v, macro="modify_field")
def FieldDetail(req, pid, id, err=0): _option = "" for key in req.params.keys(): if key.startswith("option_"): _option += key[7] if err == 0 and id == "": # new field field = tree.Node("", type="metafield") elif id != "": # edit field field = getMetaField(pid, id) else: # error filling values _fieldvalue = "" if req.params.get('mtype', '') + "_value" in req.params.keys(): _fieldvalue = str(req.params[req.params.get('mtype', '') + "_value"]) if (req.params.get("mname") == ""): field = tree.Node(req.params.get("orig_name"), type="metafield") else: field = tree.Node(req.params.get("mname"), type="metafield") field.setLabel(req.params.get("mlabel")) field.setOrderPos(req.params.get("orderpos")) field.setFieldtype(req.params.get("mtype")) field.setOption(_option) field.setValues(_fieldvalue) field.setDescription(req.params.get("mdescription")) attr = {} metadatatype = getMetaType(pid) for t in metadatatype.getDatatypes(): node = tree.Node(type=t) try: attr.update(node.getTechnAttributes()) except AttributeError: continue metafields = {} for fields in getFieldsForMeta(pid): if fields.getType() != "union": metafields[fields.getName()] = fields v = getAdminStdVars(req) v["metadatatype"] = metadatatype v["metafield"] = field v["error"] = err v["fieldtypes"] = getMetaFieldTypeNames() v["dateoptions"] = dateoption v["datatypes"] = attr v["requiredoptions"] = requiredoption v["fieldoptions"] = fieldoption v["metafields"] = metafields v["filtertype"] = req.params.get("filtertype", "") v["actpage"] = req.params.get("actpage") v["icons"] = {"externer Link": "/img/extlink.png", "Email": "/img/email.png"} v["url_targets"] = {"selbes Fenster": "same", "neues Fenster": "_blank"} v["valuelist"] = ("", "", "", "") if field.getFieldtype() == "url": v["valuelist"] = field.getValueList() while len(v["valuelist"]) != 4: v["valuelist"].append("") else: v["valuelist"] = field.getValueList() v["field"] = None if field.id: v["field"] = field v["adminfields"] = [] for t in getMetaFieldTypeNames(): f = getMetadataType(t) if 'attr_dict' in inspect.getargspec(f.getMaskEditorHTML).args: attr_dict = dict(field.items()) v["adminfields"] .append(f.getMaskEditorHTML(v["field"], metadatatype=metadatatype, language=lang(req), attr_dict=attr_dict)) else: v["adminfields"] .append(f.getMaskEditorHTML(v["field"], metadatatype=metadatatype, language=lang(req))) return req.getTAL("web/admin/modules/metatype_field.html", v, macro="modify_field")
def getTypeForAttributename(mdt_name, attr_name): field = [x for x in getFieldsForMeta(mdt_name) if x.name == attr_name][0] return field.get('type')
def show_workflow_node(self, node, req): errors = [] steps_of_current_workflow = getNodeWorkflow(node).getSteps() step_children_list = [(wf_step, wf_step.getChildren()) for wf_step in steps_of_current_workflow] step_children_list = [(wf_step, wf_step_children, [x.id for x in wf_step_children]) for (wf_step, wf_step_children) in step_children_list] language = req.params.get('lang', 'de') if "gotrue" in req.params: chosen_id = req.params.get('chosen_id').strip() try: chosen_node = tree.getNode(chosen_id) except tree.NoSuchNodeError: msg = "checkdoublet: no such node as chosen_node: %s" % chosen_id logging.getLogger("workflows").error(msg) all_ids = req.params.get('all_ids') nid_list = [x.strip() for x in all_ids.split(';')] nid_list = [x for x in nid_list if not x == chosen_id] def handleDoublets(nid_list): import core.xmlnode checked_to_remove = self.get("checked_to_remove") for nid in nid_list: try: n = tree.getNode(nid) for wf_step, wf_step_children, wf_step_children_ids in step_children_list: if n.id in wf_step_children_ids: if checked_to_remove: msg_tuple = (nid, chosen_id, wf_step.name, wf_step.id, current_workflow.name, current_workflow.id) msg = "checkdoublet: going to remove node %s (doublette of node %s) from workflowstep '%s' (%s) of workflow '%s' (%s)" % msg_tuple logging.getLogger('workflows').info(msg) wf_step.removeChild(n) except tree.NoSuchNodeError: pass handleDoublets(nid_list) wf_step_of_chosen_node = getNodeWorkflowStep(chosen_node) req.params['key'] = chosen_node.get('key') try: del req.params['gotrue'] except: pass try: del req.params['gofalse'] except: pass return wf_step_of_chosen_node.show_workflow_node(chosen_node, req) if "gofalse" in req.params: return self.forwardAndShow(node, False, req) schema = node.getSchema() attribute_names_string = self.get("attribute_names").strip() attribute_names = [] if attribute_names_string: attribute_names = [x.strip() for x in attribute_names_string.split(';') if x.strip()] exact_field = self.get("exact_field").strip() all_attribute_names = [field.name for field in getFieldsForMeta(schema)] additional_attributes = [] additional_attributes_string = self.get("additional_attribute_to_show").strip() if additional_attributes_string.strip().lower() == "mask:all": additional_attributes = all_attribute_names elif additional_attributes_string.startswith('mask:'): maskname = additional_attributes_string[len('mask:'):] try: additional_attributes = getAttributeNamesForMask(node, language, maskname) except: msg = "checkdoublet: no mask found for %s (from %s)" % (maskname, additional_attributes_string) errors.append(msg) else: additional_attributes = [x.strip() for x in additional_attributes_string.split(';') if x.strip()] additional_attributes = [x for x in additional_attributes if x not in attribute_names] masklist_for_labels = self.get("masklist_for_labels").strip().split(';') masklist_for_labels = [x.strip() for x in masklist_for_labels if x.strip()] dict_labels = dict([(attr_name, getLabelForAttributename(schema, attr_name, masklist_for_labels)) for attr_name in attribute_names + additional_attributes]) additional_attributes_decorated = sorted([(dict_labels[x], x) for x in additional_attributes]) additional_attributes = [x[1] for x in additional_attributes_decorated if not x[1] in attribute_names] if exact_field not in all_attribute_names: msg_tuple = (current_workflow.id, self.id, exact_field, schema, node.id) msg = "checkdoublet: workflow %s, step %s (doubletcheck): exact_field '%s' not in schema '%s' of current node %s: contact administrator" % msg_tuple errors.append(msg) logging.getLogger("workflows").error(msg) if set(attribute_names) - set(all_attribute_names): msg_tuple = (current_workflow.id, self.id, str(set(attribute_names) - set(all_attribute_names)), schema, node.id) msg = "checkdoublet: workflow %s, step %s (doubletcheck): attribute_names '%s' not in schema '%s' of current node %s: contact administrator" % msg_tuple errors.append(msg) logging.getLogger("workflows").error(msg) doublets = [] if exact_field: exact_value = node.get(exact_field) if attribute_names: attribute_values_string = ("#".join([node.get(attr) for attr in attribute_names])).lower() for wf_step, wf_step_children, wf_step_children_ids in step_children_list: for candidate in wf_step_children: if exact_field: if exact_value != candidate.get(exact_field): continue if attribute_names: candidate_values_string = ("#".join([candidate.get(attr) for attr in attribute_names])).lower() try: ratio = Levenshtein.ratio(attribute_values_string, candidate_values_string) except: ratio = int(attribute_values_string == candidate_values_string) if ratio >= RATIO_THRESHOLD: doublets.append([candidate.get('creationtime').replace('T', ' - '), wf_step, candidate, ratio]) else: if exact_field: # when no attribute_names are given, the exacte_filed alone shall decide doublets.append([candidate.get('creationtime').replace('T', ' - '), wf_step, candidate, 1.0]) sorted_doublets = sorted(doublets) doublets = [] for i, t in enumerate(sorted_doublets): doublets.append(t + [i]) context = {"key": req.params.get("key", req.session.get("key", "")), "error": "\n".join(errors), "node": node, "show_attributes": attribute_names + additional_attributes, "doublets": doublets, "ids": ";".join([x[2].id for x in doublets]), "prefix": self.get("prefix"), "suffix": self.get("suffix"), "dict_labels": dict_labels, "getAttr": getAttr, "buttons": self.tableRowButtons(node)} if len(doublets) == 1: if DEBUG: logging.getLogger('workflows').info('checkdoublet: node %s: no doublet found' % node.id) return self.forwardAndShow(node, True, req) atime = time.time() res = req.getTAL("workflow/checkdoublet.html", context, macro="workflow_checkdoublet") etime = time.time() if DEBUG: logging.getLogger('workflows').info('checkdoublet: duration getTAL: %.3f' % (etime - atime)) return res
def show_workflow_node(self, node, req): errors = [] steps_of_current_workflow = getNodeWorkflow(node).getSteps() step_children_list = [(wf_step, wf_step.getChildren()) for wf_step in steps_of_current_workflow] step_children_list = [ (wf_step, wf_step_children, [x.id for x in wf_step_children]) for (wf_step, wf_step_children) in step_children_list ] language = req.params.get('lang', 'de') if "gotrue" in req.params: chosen_id = req.params.get('chosen_id').strip() try: chosen_node = tree.getNode(chosen_id) except tree.NoSuchNodeError: msg = "checkdoublet: no such node as chosen_node: %s" % chosen_id logging.getLogger("workflows").error(msg) all_ids = req.params.get('all_ids') nid_list = [x.strip() for x in all_ids.split(';')] nid_list = [x for x in nid_list if not x == chosen_id] def handleDoublets(nid_list): import core.xmlnode checked_to_remove = self.get("checked_to_remove") for nid in nid_list: try: n = tree.getNode(nid) for wf_step, wf_step_children, wf_step_children_ids in step_children_list: if n.id in wf_step_children_ids: if checked_to_remove: msg_tuple = (nid, chosen_id, wf_step.name, wf_step.id, current_workflow.name, current_workflow.id) msg = "checkdoublet: going to remove node %s (doublette of node %s) from workflowstep '%s' (%s) of workflow '%s' (%s)" % msg_tuple logging.getLogger('workflows').info(msg) wf_step.removeChild(n) except tree.NoSuchNodeError: pass handleDoublets(nid_list) wf_step_of_chosen_node = getNodeWorkflowStep(chosen_node) req.params['key'] = chosen_node.get('key') try: del req.params['gotrue'] except: pass try: del req.params['gofalse'] except: pass return wf_step_of_chosen_node.show_workflow_node(chosen_node, req) if "gofalse" in req.params: return self.forwardAndShow(node, False, req) schema = node.getSchema() attribute_names_string = self.get("attribute_names").strip() attribute_names = [] if attribute_names_string: attribute_names = [ x.strip() for x in attribute_names_string.split(';') if x.strip() ] exact_field = self.get("exact_field").strip() all_attribute_names = [ field.name for field in getFieldsForMeta(schema) ] additional_attributes = [] additional_attributes_string = self.get( "additional_attribute_to_show").strip() if additional_attributes_string.strip().lower() == "mask:all": additional_attributes = all_attribute_names elif additional_attributes_string.startswith('mask:'): maskname = additional_attributes_string[len('mask:'):] try: additional_attributes = getAttributeNamesForMask( node, language, maskname) except: msg = "checkdoublet: no mask found for %s (from %s)" % ( maskname, additional_attributes_string) errors.append(msg) else: additional_attributes = [ x.strip() for x in additional_attributes_string.split(';') if x.strip() ] additional_attributes = [ x for x in additional_attributes if x not in attribute_names ] masklist_for_labels = self.get("masklist_for_labels").strip().split( ';') masklist_for_labels = [ x.strip() for x in masklist_for_labels if x.strip() ] dict_labels = dict([ (attr_name, getLabelForAttributename(schema, attr_name, masklist_for_labels)) for attr_name in attribute_names + additional_attributes ]) additional_attributes_decorated = sorted([ (dict_labels[x], x) for x in additional_attributes ]) additional_attributes = [ x[1] for x in additional_attributes_decorated if not x[1] in attribute_names ] if exact_field not in all_attribute_names: msg_tuple = (current_workflow.id, self.id, exact_field, schema, node.id) msg = "checkdoublet: workflow %s, step %s (doubletcheck): exact_field '%s' not in schema '%s' of current node %s: contact administrator" % msg_tuple errors.append(msg) logging.getLogger("workflows").error(msg) if set(attribute_names) - set(all_attribute_names): msg_tuple = (current_workflow.id, self.id, str(set(attribute_names) - set(all_attribute_names)), schema, node.id) msg = "checkdoublet: workflow %s, step %s (doubletcheck): attribute_names '%s' not in schema '%s' of current node %s: contact administrator" % msg_tuple errors.append(msg) logging.getLogger("workflows").error(msg) doublets = [] if exact_field: exact_value = node.get(exact_field) if attribute_names: attribute_values_string = ("#".join( [node.get(attr) for attr in attribute_names])).lower() for wf_step, wf_step_children, wf_step_children_ids in step_children_list: for candidate in wf_step_children: if exact_field: if exact_value != candidate.get(exact_field): continue if attribute_names: candidate_values_string = ("#".join([ candidate.get(attr) for attr in attribute_names ])).lower() try: ratio = Levenshtein.ratio(attribute_values_string, candidate_values_string) except: ratio = int( attribute_values_string == candidate_values_string) if ratio >= RATIO_THRESHOLD: doublets.append([ candidate.get('creationtime').replace('T', ' - '), wf_step, candidate, ratio ]) else: if exact_field: # when no attribute_names are given, the exacte_filed alone shall decide doublets.append([ candidate.get('creationtime').replace('T', ' - '), wf_step, candidate, 1.0 ]) sorted_doublets = sorted(doublets) doublets = [] for i, t in enumerate(sorted_doublets): doublets.append(t + [i]) context = { "key": req.params.get("key", req.session.get("key", "")), "error": "\n".join(errors), "node": node, "show_attributes": attribute_names + additional_attributes, "doublets": doublets, "ids": ";".join([x[2].id for x in doublets]), "prefix": self.get("prefix"), "suffix": self.get("suffix"), "dict_labels": dict_labels, "getAttr": getAttr, "buttons": self.tableRowButtons(node) } if len(doublets) == 1: if DEBUG: logging.getLogger('workflows').info( 'checkdoublet: node %s: no doublet found' % node.id) return self.forwardAndShow(node, True, req) atime = time.time() res = req.getTAL("workflow/checkdoublet.html", context, macro="workflow_checkdoublet") etime = time.time() if DEBUG: logging.getLogger('workflows').info( 'checkdoublet: duration getTAL: %.3f' % (etime - atime)) return res