Example #1
0
def validate(req, op):
    path = req.path[1:].split("/")

    if len(path) == 3 and path[2] == "overview":
        return showFieldOverview(req)

    if len(path) == 4 and path[3] == "editor":
        res = showEditor(req)
        return res

    if len(path) == 5 and path[3] == "editor" and path[4] == "show_testnodes":

        raise NotImplementedError("")

        template = req.params.get('template', '')
        testnodes_list = req.params.get('testnodes', '')
        width = req.params.get('width', '400')
        item_id = req.params.get('item_id', None)

        mdt_name = path[1]
        mask_name = path[2]

        mdt = q(Metadatatypes).one().children.filter_by(name=mdt_name).one()
        mask = mdt.children.filter_by(name=mask_name).one()

        sectionlist = []
        for nid in [x.strip() for x in testnodes_list.split(',') if x.strip()]:
            section_descr = {}
            section_descr['nid'] = nid
            section_descr['error_flag'] = ''  # in case of no error

            node = q(Node).get(nid)
            section_descr['node'] = node
            if node and node.has_data_access():
                try:
                    node_html = mask.getViewHTML(
                        [node],
                        VIEW_DEFAULT,
                        template_from_caller=[template, mdt, mask, item_id])
                    section_descr['node_html'] = node_html
                except:
                    logg.exception("exception while evaluating template")
                    error_text = str(sys.exc_info()[1])
                    template_line = 'for node id ' + ustr(
                        nid) + ': ' + error_text
                    with suppress(Exception, warn=False):
                        m = re.match(
                            r".*line (?P<line>\d*), column (?P<column>\d*)",
                            error_text)
                        if m:
                            mdict = m.groupdict()
                            line = int(mdict.get('line', 0))
                            column = int(mdict.get('column', 0))
                            error_text = error_text.replace(
                                'line %d' % line,
                                'template line %d' % (line - 1))
                            template_line = 'for node id ' + ustr(
                                nid
                            ) + '<br/>' + error_text + '<br/><code>' + esc(
                                template.split("\n")[line - 2][0:column - 1]
                            ) + '<span style="color:red">' + esc(
                                template.split("\n")[line -
                                                     2][column -
                                                        1:]) + '</span></code>'
                    section_descr[
                        'error_flag'] = 'Error while evaluating template:'
                    section_descr['node_html'] = template_line
            elif node and not node.has_data_access():
                section_descr['error_flag'] = 'no access'
                section_descr['node_html'] = ''
            if node is None:
                section_descr['node'] = None
                section_descr['error_flag'] = 'NoSuchNodeError'
                section_descr['node_html'] = 'for node id ' + ustr(nid)
            sectionlist.append(section_descr)

        # remark: error messages will be served untranslated in English
        # because messages from the python interpreter (in English) will be added

        return req.getTAL("web/admin/modules/metatype.html", {
            'sectionlist': sectionlist,
            'csrf': req.csrf_token.current_token
        },
                          macro="view_testnodes")

    if len(path) == 2 and path[1] == "info":
        return showInfo(req)

    if "file" in req.params and hasattr(
            req.params["file"],
            "filesize") and req.params["file"].filesize > 0:
        # import scheme from xml-file
        importfile = req.params.get("file")
        if importfile.tempname != "":
            xmlimport(req, importfile.tempname)

    if req.params.get("acttype", "schema") == "schema":
        # section for schema
        for key in req.params.keys():
            # create new metadatatype
            if key.startswith("new"):
                return MetatypeDetail(req, "")

            # edit metadatatype
            elif key.startswith("edit_"):
                return MetatypeDetail(req, key[5:-2])

            # delete metadata
            elif key.startswith("delete_"):
                deleteMetaType(key[7:-2])
                break

            # show details for given metadatatype
            elif key.startswith("detaillist_"):
                return showDetailList(req, key[11:-2])

            # show masklist for given metadatatype
            elif key.startswith("masks_"):
                return showMaskList(req, key[6:-2])

        # save schema
        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return view(req)

            if req.params.get("mname", "") == "" or req.params.get(
                    "mlongname", "") == "" or req.params.get("mdatatypes",
                                                             "") == "":
                return MetatypeDetail(req, req.params.get("mname_orig", ""),
                                      1)  # no name was given
            elif not checkString(req.params.get("mname", "")):
                return MetatypeDetail(
                    req, req.params.get("mname_orig", ""),
                    4)  # if the name contains wrong characters
            elif req.params.get("mname_orig", "") != req.params.get(
                    "mname", "") and existMetaType(req.params.get("mname")):
                return MetatypeDetail(req, req.params.get("mname_orig", ""),
                                      2)  # metadata still existing

            _active = 0
            if req.params.get("mactive", "") != "":
                _active = 1
            updateMetaType(req.params.get("mname", ""),
                           description=req.params.get("description", ""),
                           longname=req.params.get("mlongname", ""),
                           active=_active,
                           datatypes=req.params.get("mdatatypes",
                                                    "").replace(";", ", "),
                           bibtexmapping=req.params.get("mbibtex", ""),
                           citeprocmapping=req.params.get("mciteproc", ""),
                           orig_name=req.params.get("mname_orig", ""))
            mtype = q(Metadatatype).filter_by(
                name=req.params.get("mname")).scalar()
            if mtype:
                new_ruleset_names = set(req.form.getlist("leftread"))
                add_remove_rulesets_from_metadatatype(mtype, new_ruleset_names)

            db.session.commit()

    elif req.params.get("acttype") == "field":
        # section for fields
        for key in req.params.keys():
            # create new meta field
            if key.startswith("newdetail_"):
                return FieldDetail(req, req.params.get("parent"), "")

            # edit meta field
            elif key.startswith("editdetail_"):
                return FieldDetail(req, req.params.get("parent"), key[11:-2])

            # delete metafield: key[13:-2] = pid | n
            elif key.startswith("deletedetail_"):
                deleteMetaField(req.params.get("parent"), key[13:-2])
                return showDetailList(req, req.params.get("parent"))

            # change field order up
            if key.startswith("updetail_"):
                moveMetaField(req.params.get("parent"), key[9:-2], -1)
                return showDetailList(req, req.params.get("parent"))

            # change field order down
            elif key.startswith("downdetail_"):
                moveMetaField(req.params.get("parent"), key[11:-2], 1)
                return showDetailList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showDetailList(req, req.params.get("parent"))

            if existMetaField(req.params.get("parent"), req.params.get("mname")) and \
                    (req.params.get("form_op", "")  == "save_newdetail" or req.params.get("mname") != req.params.get("mname_orig")):
                return FieldDetail(req, req.params.get("parent"),
                                   req.params.get("orig_name", ""),
                                   3)  # field still existing
            elif req.params.get("mname", "") == "" or req.params.get(
                    "mlabel", "") == "":
                return FieldDetail(req, req.params.get("parent"),
                                   req.params.get("orig_name", ""), 1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return FieldDetail(req, req.params.get("parent"),
                                   req.params.get("orig_name", ""), 4)

            _option = ""
            for o in req.params.keys():
                if o.startswith("option_"):
                    _option += o[7]

            _fieldvalue = ""
            if req.params.get("mtype", "") + "_value" in req.params.keys():
                _fieldvalue = req.params.get(
                    req.params.get("mtype") + "_value")

            _filenode = None
            if "valuesfile" in req.params.keys():
                valuesfile = req.params.pop("valuesfile")
                _filenode = importFileToRealname(valuesfile.filename,
                                                 valuesfile.tempname)

            _attr_dict = {}
            if req.params.get("mtype",
                              "") + "_handle_attrs" in req.params.keys():

                attr_names = [
                    s.strip() for s in req.params.get(
                        req.params.get("mtype", "") +
                        "_handle_attrs").split(",")
                ]
                key_prefix = req.params.get("mtype", "") + "_attr_"

                for attr_name in attr_names:
                    attr_value = req.params.get(key_prefix + attr_name, "")
                    _attr_dict[attr_name] = attr_value

            updateMetaField(req.params.get("parent", ""),
                            req.params.get("mname", ""),
                            req.params.get("mlabel", ""),
                            req.params.get("orderpos", ""),
                            req.params.get("mtype", ""),
                            _option,
                            req.params.get("mdescription", ""),
                            _fieldvalue,
                            fieldid=req.params.get("fieldid", ""),
                            filenode=_filenode,
                            attr_dict=_attr_dict)

        return showDetailList(req, req.params.get("parent"))

    elif req.params.get("acttype") == "mask":

        # section for masks
        for key in req.params.keys():

            # new mask
            if key.startswith("newmask_"):
                return MaskDetails(req, req.params.get("parent"), "")

            # edit metatype masks
            elif key.startswith("editmask_"):
                return MaskDetails(req,
                                   req.params.get("parent"),
                                   key[9:-2],
                                   err=0)

            # delete mask
            elif key.startswith("deletemask_"):
                mtype = getMetaType(req.params.get("parent"))
                mtype.children.remove(q(Node).get(key[11:-2]))
                db.session.commit()
                return showMaskList(req, req.params.get("parent"))

            # create autmatic mask with all fields
            elif key.startswith("automask_"):
                generateMask(getMetaType(req.params.get("parent")))
                return showMaskList(req, req.params.get("parent"))

            # cope selected mask
            if key.startswith("copymask_"):
                k = key[9:-2]
                if k.isdigit():
                    mask = q(Mask).get(k)
                else:
                    mtype = getMetaType(req.params.get("parent"))
                    mask = mtype.getMask(k)
                cloneMask(mask, u"copy_" + mask.name)
                return showMaskList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showMaskList(req, req.params.get("parent"))

            if req.params.get("mname", "") == "":
                return MaskDetails(req,
                                   req.params.get("parent", ""),
                                   req.params.get("morig_name", ""),
                                   err=1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return MaskDetails(req,
                                   req.params.get("parent", ""),
                                   req.params.get("morig_name", ""),
                                   err=4)

            mtype = q(Metadatatype).filter_by(
                name=q(Node).get(req.params.get("parent", "")).name).one()
            if req.params.get("form_op") == "save_editmask":
                mask = mtype.get_mask(req.params.get("mname", ""))
                # in case of renaming a mask the mask cannot be detected via the new mname
                # then detect mask via maskid
                if not mask:
                    mtype = getMetaType(req.params.get("parent"))
                    mask = mtype.children.filter_by(
                        id=req.params.get("maskid", "")).scalar()

            elif req.params.get("form_op") == "save_newmask":
                mask = Mask(req.params.get("mname", ""))
                mtype.children.append(mask)
                db.session.commit()
            mask.name = req.params.get("mname")
            mask.setDescription(req.params.get("mdescription"))
            mask.setMasktype(req.params.get("mtype"))
            mask.setSeparator(req.params.get("mseparator"))
            db.session.commit()

            if req.params.get("mtype") == "export":
                mask.setExportMapping(req.params.get("exportmapping") or "")
                mask.setExportHeader(req.params.get("exportheader"))
                mask.setExportFooter(req.params.get("exportfooter"))
                _opt = ""
                if "types" in req.params.keys():
                    _opt += "t"
                if "notlast" in req.params.keys():
                    _opt += "l"
                mask.setExportOptions(_opt)
                db.session.commit()

            mask.setLanguage(req.params.get("mlanguage", ""))
            mask.setDefaultMask("mdefault" in req.params.keys())

            for r in mask.access_ruleset_assocs.filter_by(ruletype=u'read'):
                db.session.delete(r)

            for key in req.params.keys():
                if key.startswith("left"):
                    for r in req.params.get(key).split(';'):
                        mask.access_ruleset_assocs.append(
                            NodeToAccessRuleset(ruleset_name=r,
                                                ruletype=key[4:]))
                    break
            db.session.commit()
        return showMaskList(req, ustr(req.params.get("parent", "")))
    return view(req)
Example #2
0
def showEditor(req):
    path = req.path[1:].split("/")
    mtype = getMetaType(path[1])
    editor = mtype.getMask(path[2])

    req.params["metadatatype"] = mtype
    for key in req.params.keys():
        if req.params.get("op", "") == "cancel":
            if "savedetail" in req.params.keys():
                del req.params["savedetail"]
            break

        if key.startswith("up_"):
            changeOrder(
                q(Node).get(key[3:-2]).parents[0],
                q(Node).get(key[3:-2]).orderpos, -1)
            break

        if key.startswith("down_"):
            changeOrder(
                q(Node).get(key[5:-2]).parents[0], -1,
                q(Node).get(key[5:-2]).orderpos)
            break

        if key.startswith("delete_"):
            editor.deleteMaskitem(key[7:-2])
            break

        if key.startswith("edit_"):
            op = key[5:-2]
            req.params["edit"] = op
            req.params["op"] = "edit"
            break

        if key.startswith("new_"):
            req.params["edit"] = " "
            break

        if key.startswith("newdetail_"):
            req.params["pid"] = key[10:-2]
            req.params["op"] = "newdetail"
            req.params["edit"] = " "
            if req.params.get("type") in ("vgroup", "hgroup"):
                req.params["type"] = "field"
                req.params["op"] = "new"
            if "savedetail" in req.params.keys():
                del req.params["savedetail"]
            break

    if req.params.get("op", "") == "group":
        # create new group for selected objects
        req.params["op"] = "new"
        req.params["edit"] = " "
        req.params["type"] = req.params.get("group_type")
        req.params["pid"] = q(Node).get(
            req.params.get("sel_id").split(";")[0]).parents[0].id

    if "saveedit" in req.params.keys() and req.params.get("op",
                                                          "") != "cancel":
        # update node
        label = req.params.get("label", "-new-")
        if req.params.get("op", "") == "edit":
            item = q(Node).get(req.params.get("id"))
            item.setLabel(req.params.get("label", ""))
            db.session.commit()
            if "mappingfield" in req.params.keys():
                # field of export mask
                item.set("attribute", req.params.get("attribute"))
                item.set("fieldtype", req.params.get("fieldtype"))
                mf = req.params.get("mappingfield").split(";")
                if req.params.get(
                        "fieldtype"
                ) == "mapping":  # mapping field of mapping definition selected
                    item.set("mappingfield", mf[0])
                else:  # attribute name as object name
                    item.set("mappingfield", ";".join(mf[1:]))
                db.session.commit()
            else:
                f = q(Node).get(long(req.params.get("field")))

            field = item.children
            try:
                field = list(field)[0]
                if ustr(field.id) != req.params.get("field"):
                    item.children.remove(field)
                    item.children.append(f)
                field.setValues(
                    req.params.get(u"{}_value".format(field.get("type")), u""))
                db.session.commit()
            except:
                logg.exception("exception in showEditor / saveedit, ignore")
                pass

        elif req.params.get("op", "") == "new":
            if req.params.get("fieldtype",
                              "") == "common" and req.params.get("field"):
                # existing field used
                fieldid = long(req.params.get("field"))
            elif "mappingfield" in req.params.keys():
                # new mapping field
                fieldid = ""  # long(req.params.get("mappingfield"))
                label = "mapping"

            else:
                # create new metaattribute
                parent = req.params.get("metadatatype").getName()
                fieldvalue = req.params.get(
                    req.params.get("newfieldtype", "") + '_value', "")

                if req.params.get("type") == "label":
                    # new label
                    fieldid = ""
                else:
                    # normal field
                    updateMetaField(parent,
                                    req.params.get("fieldname"),
                                    label,
                                    0,
                                    req.params.get("newfieldtype"),
                                    option="",
                                    description=req.params.get(
                                        "description", ""),
                                    fieldvalues=fieldvalue,
                                    fieldvaluenum="",
                                    fieldid="")
                    fieldid = ustr(
                        getMetaField(parent, req.params.get("fieldname")).id)

            item = editor.addMaskitem(label, req.params.get("type"), fieldid,
                                      req.params.get("pid", "0"))

            if "mappingfield" in req.params.keys():
                item.set("attribute", req.params.get("attribute"))
                item.set("fieldtype", req.params.get("fieldtype"))
                mf = req.params.get("mappingfield").split(";")
                if req.params.get(
                        "fieldtype"
                ) == "mapping":  # mapping field of mapping definition selected
                    item.set("mappingfield", mf[0])
                else:  # attribute name as object name
                    item.set("mappingfield", ";".join(mf[1:]))
                db.session.commit()

            position = req.params.get("insertposition", "end")
            if position == "end":
                # insert at the end of existing mask
                item.orderpos = len(
                    q(Node).get(req.params.get("pid")).children) - 1
                db.session.commit()
            else:
                # insert at special position
                fields = editor.getMaskFields()
                fields.all().sort(lambda x, y: cmp(x.orderpos, y.orderpos))
                for f in fields:
                    if f.orderpos >= q(Node).get(
                            position).orderpos and f.id != item.id:
                        f.orderpos = f.orderpos + 1
                item.orderpos = q(Node).get(position).orderpos - 1
                db.session.commit()

        item.setWidth(req.params.get("width", u'400'))
        item.setUnit(req.params.get("unit", u""))
        item.setDefault(req.params.get("default", u""))
        item.setFormat(req.params.get("format", u""))
        item.setSeparator(req.params.get("separator", u""))
        item.setDescription(req.params.get("description", u""))
        item.setTestNodes(req.params.get("testnodes", u""))
        item.setMultilang(req.params.get("multilang", u""))
        db.session.commit()

        if "required" in req.params.keys():
            item.setRequired(unicode(1))
        else:
            item.setRequired(unicode(0))
        db.session.commit()

    if "savedetail" in req.params.keys():
        label = req.params.get("label", "-new-")
        # save details (used for hgroup)
        if req.params.get("op", "") == "edit":
            item = q(Node).get(req.params.get("id"))
            item.setLabel(req.params.get("label", ""))
        elif req.params.get("op", "") == "new":
            if req.params.get("sel_id", "") != "":
                item = editor.addMaskitem(label, req.params.get("type"),
                                          req.params.get("sel_id", "")[:-1],
                                          long(req.params.get("pid", "0")))
            else:
                item = editor.addMaskitem(label, req.params.get("type"), 0,
                                          long(req.params.get("pid", "0")))
        db.session.commit()

        # move selected elementd to new item-container
        if req.params.get("sel_id", "") != "":
            pos = 0
            for i in req.params.get("sel_id")[:-1].split(";"):
                n = q(Node).get(i)  # node to move
                n.setOrderPos(pos)
                p = q(Node).get(n.parents()[0].id)  # parentnode
                p.children.remove(n)
                item.children.append(n)  # new group
                pos += 1
            db.session.commit()

        # position:
        position = req.params.get("insertposition", "end")
        if position == "end":
            # insert at the end of existing mask
            item.setOrderPos(
                len(q(Node).get(req.params.get("pid")).children) - 1)
            db.session.commit()
        else:
            # insert at special position
            fields = []
            pidnode = q(Node).get(req.params.get("pid"))
            for field in pidnode.getChildren():
                if field.getType().getName(
                ) == "maskitem" and field.id != pidnode.id:
                    fields.append(field)
            fields.sort(lambda x, y: cmp(x.orderpos, y.orderpos))
            for f in fields:
                if f.orderpos >= q(Node).get(
                        position).orderpos and f.id != item.id:
                    f.orderpos = f.orderpos + 1
            item.orderpos = q(Node).get(position).orderpos - 1
            db.session.commit()

        if "edit" not in req.params.keys():
            item.set("type", req.params.get("type", u""))
        item.setWidth(req.params.get("width", u'400'))
        item.setUnit(req.params.get("unit", u""))
        item.setDefault(req.params.get("default", u""))
        item.setFormat(req.params.get("format", u""))
        item.setSeparator(req.params.get("separator", u""))
        item.setDescription(req.params.get("description", u""))
        if "required" in req.params.keys():
            item.setRequired(unicode(1))
        else:
            item.setRequired(unicode(0))
        db.session.commit()

    v = {}
    v["edit"] = req.params.get("edit", "")
    if req.params.get("edit", "") != "":
        v["editor"] = editor.editItem(req)
    else:
        # show metaEditor
        v["editor"] = ""
        try:
            v["editor"] = req.getTALstr(editor.getMetaMask(req), {})
        except:
            logg.exception("exception in showEditor")
            v["editor"] = editor.getMetaMask(req)

    v["title"] = editor.name
    v["csrf"] = req.csrf_token.current_token
    return req.getTAL("web/admin/modules/metatype.html",
                      v,
                      macro="editor_popup")
Example #3
0
def validate(req, op):
    path = req.path[1:].split("/")

    if len(path) == 3 and path[2] == "overview":
        return showFieldOverview(req)

    if len(path) == 4 and path[3] == "editor":
        res = showEditor(req)
        return res

    if len(path) == 5 and path[3] == "editor" and path[4] == "show_testnodes":
        
        raise NotImplementedError("")

        template = req.params.get('template', '')
        testnodes_list = req.params.get('testnodes', '')
        width = req.params.get('width', '400')
        item_id = req.params.get('item_id', None)

        mdt_name = path[1]
        mask_name = path[2]

        mdt = q(Metadatatypes).one().children.filter_by(name=mdt_name).one()
        mask = mdt.children.filter_by(name=mask_name).one()

        sectionlist = []
        for nid in [x.strip() for x in testnodes_list.split(',') if x.strip()]:
            section_descr = {}
            section_descr['nid'] = nid
            section_descr['error_flag'] = ''  # in case of no error

            node = q(Node).get(nid)
            section_descr['node'] = node
            if node and node.has_data_access():
                try:
                    node_html = mask.getViewHTML([node], VIEW_DEFAULT, template_from_caller=[template, mdt, mask, item_id])
                    section_descr['node_html'] = node_html
                except:
                    logg.exception("exception while evaluating template")
                    error_text = str(sys.exc_info()[1])
                    template_line = 'for node id ' + ustr(nid) + ': ' + error_text
                    with suppress(Exception, warn=False):
                        m = re.match(r".*line (?P<line>\d*), column (?P<column>\d*)", error_text)
                        if m:
                            mdict = m.groupdict()
                            line = int(mdict.get('line', 0))
                            column = int(mdict.get('column', 0))
                            error_text = error_text.replace('line %d' % line, 'template line %d' % (line - 1))
                            template_line = 'for node id ' + ustr(nid) + '<br/>' + error_text + '<br/><code>' + esc(
                                template.split(
                                    "\n")[line - 2][0:column - 1]) + '<span style="color:red">' + esc(
                                template.split("\n")[line - 2][column - 1:]) + '</span></code>'
                    section_descr['error_flag'] = 'Error while evaluating template:'
                    section_descr['node_html'] = template_line
            elif node and not node.has_data_access():
                section_descr['error_flag'] = 'no access'
                section_descr['node_html'] = ''
            if node is None:
                section_descr['node'] = None
                section_descr['error_flag'] = 'NoSuchNodeError'
                section_descr['node_html'] = 'for node id ' + ustr(nid)
            sectionlist.append(section_descr)

        # remark: error messages will be served untranslated in English
        # because messages from the python interpreter (in English) will be added

        return req.getTAL("web/admin/modules/metatype.html", {'sectionlist': sectionlist, 'csrf': req.csrf_token.current_token}, macro="view_testnodes")

    if len(path) == 2 and path[1] == "info":
        return showInfo(req)

    if "file" in req.params and hasattr(req.params["file"], "filesize") and req.params["file"].filesize > 0:
        # import scheme from xml-file
        importfile = req.params.get("file")
        if importfile.tempname != "":
            xmlimport(req, importfile.tempname)

    if req.params.get("acttype", "schema") == "schema":
        # section for schema
        for key in req.params.keys():
            # create new metadatatype
            if key.startswith("new"):
                return MetatypeDetail(req, "")

            # edit metadatatype
            elif key.startswith("edit_"):
                return MetatypeDetail(req, key[5:-2])

            # delete metadata
            elif key.startswith("delete_"):
                deleteMetaType(key[7:-2])
                break

            # show details for given metadatatype
            elif key.startswith("detaillist_"):
                return showDetailList(req, key[11:-2])

            # show masklist for given metadatatype
            elif key.startswith("masks_"):
                return showMaskList(req, key[6:-2])

        # save schema
        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return view(req)

            if req.params.get("mname", "") == "" or req.params.get("mlongname", "") == "" or req.params.get("mdatatypes", "") == "":
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 1)  # no name was given
            elif not checkString(req.params.get("mname", "")):
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 4)  # if the name contains wrong characters
            elif req.params.get("mname_orig", "") != req.params.get("mname", "") and existMetaType(req.params.get("mname")):
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 2)  # metadata still existing

            _active = 0
            if req.params.get("mactive", "") != "":
                _active = 1
            updateMetaType(req.params.get("mname", ""),
                           description=req.params.get("description", ""),
                           longname=req.params.get("mlongname", ""), active=_active,
                           datatypes=req.params.get("mdatatypes", "").replace(";", ", "),
                           bibtexmapping=req.params.get("mbibtex", ""),
                           citeprocmapping=req.params.get("mciteproc", ""),
                           orig_name=req.params.get("mname_orig", ""))
            mtype = q(Metadatatype).filter_by(name=req.params.get("mname")).scalar()
            if mtype:
                new_ruleset_names = set(req.form.getlist("leftread"))
                add_remove_rulesets_from_metadatatype(mtype, new_ruleset_names)

            db.session.commit()

    elif req.params.get("acttype") == "field":
        # section for fields
        for key in req.params.keys():
            # create new meta field
            if key.startswith("newdetail_"):
                return FieldDetail(req, req.params.get("parent"), "")

            # edit meta field
            elif key.startswith("editdetail_"):
                return FieldDetail(req, req.params.get("parent"), key[11:-2])

            # delete metafield: key[13:-2] = pid | n
            elif key.startswith("deletedetail_"):
                deleteMetaField(req.params.get("parent"), key[13:-2])
                return showDetailList(req, req.params.get("parent"))

            # change field order up
            if key.startswith("updetail_"):
                moveMetaField(req.params.get("parent"), key[9:-2], -1)
                return showDetailList(req, req.params.get("parent"))

            # change field order down
            elif key.startswith("downdetail_"):
                moveMetaField(req.params.get("parent"), key[11:-2], 1)
                return showDetailList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showDetailList(req, req.params.get("parent"))

            if existMetaField(req.params.get("parent"), req.params.get("mname")) and \
                    (req.params.get("form_op", "")  == "save_newdetail" or req.params.get("mname") != req.params.get("mname_orig")):
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 3)  # field still existing
            elif req.params.get("mname", "") == "" or req.params.get("mlabel", "") == "":
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 4)

            _option = ""
            for o in req.params.keys():
                if o.startswith("option_"):
                    _option += o[7]

            _fieldvalue = ""
            if req.params.get("mtype", "") + "_value" in req.params.keys():
                _fieldvalue = req.params.get(req.params.get("mtype") + "_value")

            _filenode = None
            if "valuesfile" in req.params.keys():
                valuesfile = req.params.pop("valuesfile")
                _filenode = importFileToRealname(valuesfile.filename, valuesfile.tempname)

            _attr_dict = {}
            if req.params.get("mtype", "") + "_handle_attrs" in req.params.keys():

                attr_names = [s.strip() for s in req.params.get(req.params.get("mtype", "") + "_handle_attrs").split(",")]
                key_prefix = req.params.get("mtype", "") + "_attr_"

                for attr_name in attr_names:
                    attr_value = req.params.get(key_prefix + attr_name, "")
                    _attr_dict[attr_name] = attr_value

            updateMetaField(req.params.get("parent", ""), req.params.get("mname", ""),
                            req.params.get("mlabel", ""), req.params.get("orderpos", ""),
                            req.params.get("mtype", ""), _option, req.params.get("mdescription", ""),
                            _fieldvalue, fieldid=req.params.get("fieldid", ""),
                            filenode=_filenode,
                            attr_dict=_attr_dict)

        return showDetailList(req, req.params.get("parent"))

    elif req.params.get("acttype") == "mask":

        # section for masks
        for key in req.params.keys():

            # new mask
            if key.startswith("newmask_"):
                return MaskDetails(req, req.params.get("parent"), "")

            # edit metatype masks
            elif key.startswith("editmask_"):
                return MaskDetails(req, req.params.get("parent"), key[9:-2], err=0)

            # delete mask
            elif key.startswith("deletemask_"):
                mtype = getMetaType(req.params.get("parent"))
                mtype.children.remove(q(Node).get(key[11:-2]))
                db.session.commit()
                return showMaskList(req, req.params.get("parent"))

            # create autmatic mask with all fields
            elif key.startswith("automask_"):
                generateMask(getMetaType(req.params.get("parent")))
                return showMaskList(req, req.params.get("parent"))

            # cope selected mask
            if key.startswith("copymask_"):
                k = key[9:-2]
                if k.isdigit():
                    mask = q(Mask).get(k)
                else:
                    mtype = getMetaType(req.params.get("parent"))
                    mask = mtype.getMask(k)
                cloneMask(mask, u"copy_" + mask.name)
                return showMaskList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showMaskList(req, req.params.get("parent"))

            if req.params.get("mname", "") == "":
                return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=4)

            mtype = q(Metadatatype).filter_by(name=q(Node).get(req.params.get("parent", "")).name).one()
            if req.params.get("form_op") == "save_editmask":
                mask = mtype.get_mask(req.params.get("mname", ""))
                # in case of renaming a mask the mask cannot be detected via the new mname
                # then detect mask via maskid
                if not mask:
                    mtype = getMetaType(req.params.get("parent"))
                    mask = mtype.children.filter_by(id =req.params.get("maskid", "")).scalar()

            elif req.params.get("form_op") == "save_newmask":
                mask = Mask(req.params.get("mname", ""))
                mtype.children.append(mask)
                db.session.commit()
            mask.name = req.params.get("mname")
            mask.setDescription(req.params.get("mdescription"))
            mask.setMasktype(req.params.get("mtype"))
            mask.setSeparator(req.params.get("mseparator"))
            db.session.commit()

            if req.params.get("mtype") == "export":
                mask.setExportMapping(req.params.get("exportmapping") or "")
                mask.setExportHeader(req.params.get("exportheader"))
                mask.setExportFooter(req.params.get("exportfooter"))
                _opt = ""
                if "types" in req.params.keys():
                    _opt += "t"
                if "notlast" in req.params.keys():
                    _opt += "l"
                mask.setExportOptions(_opt)
                db.session.commit()

            mask.setLanguage(req.params.get("mlanguage", ""))
            mask.setDefaultMask("mdefault" in req.params.keys())

            for r in mask.access_ruleset_assocs.filter_by(ruletype=u'read'):
                db.session.delete(r)

            for key in req.params.keys():
                if key.startswith("left"):
                    for r in req.params.get(key).split(';'):
                        mask.access_ruleset_assocs.append(NodeToAccessRuleset(ruleset_name=r, ruletype=key[4:]))
                    break
            db.session.commit()
        return showMaskList(req, ustr(req.params.get("parent", "")))
    return view(req)
Example #4
0
def validate(req, op):
    path = req.path[1:].split("/")

    if len(path) == 3 and path[2] == "overview":
        return showFieldOverview(req)

    if len(path) == 4 and path[3] == "editor":
        res = showEditor(req)
        # mask may have been edited: flush masks cache
        flush_maskcache(req=req)
        return res

    if len(path) == 5 and path[3] == "editor" and path[4] == "show_testnodes":

        template = req.params.get('template', '')
        testnodes_list = req.params.get('testnodes', '')
        width = req.params.get('width', '400')
        item_id = req.params.get('item_id', None)

        mdt_name = path[1]
        mask_name = path[2]

        mdt = tree.getRoot('metadatatypes').getChild(mdt_name)
        mask = mdt.getChild(mask_name)

        access = AccessData(req)

        sectionlist = []
        for nid in [x.strip() for x in testnodes_list.split(',') if x.strip()]:
            section_descr = {}
            section_descr['nid'] = nid
            section_descr['error_flag'] = ''  # in case of no error
            try:
                node = tree.getNode(nid)
                section_descr['node'] = node
                if access.hasAccess(node, "data"):
                    try:
                        node_html = mask.getViewHTML([node], VIEW_DEFAULT, template_from_caller=[template, mdt, mask, item_id], mask=mask)
                        section_descr['node_html'] = node_html
                    except:
                        error_text = str(sys.exc_info()[1])
                        template_line = 'for node id ' + str(nid) + ': ' + error_text
                        try:
                            m = re.match(r".*line (?P<line>\d*), column (?P<column>\d*)", error_text)
                            if m:
                                mdict = m.groupdict()
                                line = int(mdict.get('line', 0))
                                column = int(mdict.get('column', 0))
                                error_text = error_text.replace('line %d' % line, 'template line %d' % (line - 1))
                                template_line = 'for node id ' + str(nid) + '<br/>' + error_text + '<br/><code>' + esc(template.split(
                                    "\n")[line - 2][0:column - 1]) + '<span style="color:red">' + esc(template.split("\n")[line - 2][column - 1:]) + '</span></code>'
                        except:
                            pass
                        section_descr['error_flag'] = 'Error while evaluating template:'
                        section_descr['node_html'] = template_line
                else:
                    section_descr['error_flag'] = 'no access'
                    section_descr['node_html'] = ''
            except tree.NoSuchNodeError:
                section_descr['node'] = None
                section_descr['error_flag'] = 'NoSuchNodeError'
                section_descr['node_html'] = 'for node id ' + str(nid)
            sectionlist.append(section_descr)

        # remark: error messages will be served untranslated in English
        # because messages from the python interpreter (in English) will be added

        return req.getTAL("web/admin/modules/metatype.html", {'sectionlist': sectionlist}, macro="view_testnodes")

    if len(path) == 2 and path[1] == "info":
        return showInfo(req)

    if "file" in req.params and hasattr(req.params["file"], "filesize") and req.params["file"].filesize > 0:
        # import scheme from xml-file
        importfile = req.params.get("file")
        if importfile.tempname != "":
            xmlimport(req, importfile.tempname)

    if req.params.get("acttype", "schema") == "schema":
        # section for schema
        for key in req.params.keys():
            # create new metadatatype
            if key.startswith("new"):
                return MetatypeDetail(req, "")

            # edit metadatatype
            elif key.startswith("edit_"):
                return MetatypeDetail(req, str(key[5:-2]))

            # delete metadata
            elif key.startswith("delete_"):
                deleteMetaType(key[7:-2])
                break

            # show details for given metadatatype
            elif key.startswith("detaillist_"):
                return showDetailList(req, str(key[11:-2]))

            # show masklist for given metadatatype
            elif key.startswith("masks_"):
                return showMaskList(req, str(key[6:-2]))

            # reindex search index for current schema
            elif key.startswith("indexupdate_") and "cancel" not in req.params.keys():
                schema = tree.getNode(key[12:])
                searcher.reindex(schema.getAllItems())
                break

        # save schema
        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return view(req)

            if req.params.get("mname", "") == "" or req.params.get("mlongname", "") == "" or req.params.get("mdatatypes", "") == "":
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 1)  # no name was given
            elif not checkString(req.params.get("mname", "")):
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 4)  # if the name contains wrong characters
            elif req.params.get("mname_orig", "") != req.params.get("mname", "") and existMetaType(req.params.get("mname")):
                return MetatypeDetail(req, req.params.get("mname_orig", ""), 2)  # metadata still existing

            _active = 0
            if req.params.get("mactive", "") != "":
                _active = 1
            updateMetaType(req.params.get("mname", ""),
                           description=req.params.get("description", ""),
                           longname=req.params.get("mlongname", ""), active=_active,
                           datatypes=req.params.get("mdatatypes", "").replace(";", ", "),
                           bibtexmapping=req.params.get("mbibtex", ""),
                           citeprocmapping=req.params.get("mciteproc", ""),
                           orig_name=req.params.get("mname_orig", ""))
            mtype = getMetaType(req.params.get("mname"))
            if mtype:
                mtype.setAccess("read", "")
                for key in req.params.keys():
                    if key.startswith("left"):
                        mtype.setAccess(key[4:], req.params.get(key).replace(";", ","))
                        break

    elif req.params.get("acttype") == "field":
        # section for fields
        for key in req.params.keys():
            # create new meta field
            if key.startswith("newdetail_"):
                return FieldDetail(req, req.params.get("parent"), "")

            # edit meta field
            elif key.startswith("editdetail_"):
                return FieldDetail(req, req.params.get("parent"), key[11:-2])

            # delete metafield: key[13:-2] = pid | n
            elif key.startswith("deletedetail_"):
                deleteMetaField(req.params.get("parent"), key[13:-2])
                return showDetailList(req, req.params.get("parent"))

            # change field order up
            if key.startswith("updetail_"):
                moveMetaField(req.params.get("parent"), key[9:-2], -1)
                return showDetailList(req, req.params.get("parent"))

            # change field order down
            elif key.startswith("downdetail_"):
                moveMetaField(req.params.get("parent"), key[11:-2], 1)
                return showDetailList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showDetailList(req, req.params.get("parent"))

            if existMetaField(req.params.get("parent"), req.params.get("mname")) and req.params.get("form_op", "") == "save_newdetail":
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 3)  # field still existing
            elif req.params.get("mname", "") == "" or req.params.get("mlabel", "") == "":
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return FieldDetail(req, req.params.get("parent"), req.params.get("orig_name", ""), 4)

            _option = ""
            for o in req.params.keys():
                if o.startswith("option_"):
                    _option += o[7]

            _fieldvalue = ""
            if req.params.get("mtype", "") + "_value" in req.params.keys():
                _fieldvalue = str(req.params.get(req.params.get("mtype") + "_value"))

            _filenode = None
            if "valuesfile" in req.params.keys():
                valuesfile = req.params.pop("valuesfile")
                _filenode = importFileToRealname(valuesfile.filename, valuesfile.tempname)

            _attr_dict = {}
            if req.params.get("mtype", "") + "_handle_attrs" in req.params.keys():

                attr_names = [s.strip() for s in req.params.get(req.params.get("mtype", "") + "_handle_attrs").split(",")]
                key_prefix = req.params.get("mtype", "") + "_attr_"

                for attr_name in attr_names:
                    attr_value = req.params.get(key_prefix + attr_name, "")
                    _attr_dict[attr_name] = attr_value

            updateMetaField(req.params.get("parent", ""), req.params.get("mname", ""),
                            req.params.get("mlabel", ""), req.params.get("orderpos", ""),
                            req.params.get("mtype", ""), _option, req.params.get("mdescription", ""),
                            _fieldvalue, fieldid=req.params.get("fieldid", ""),
                            filenode=_filenode,
                            attr_dict=_attr_dict)

        return showDetailList(req, req.params.get("parent"))

    elif req.params.get("acttype") == "mask":

        # mask may have been edited: flush masks cache
        flush_maskcache(req=req)

        # section for masks
        for key in req.params.keys():

            # new mask
            if key.startswith("newmask_"):
                return MaskDetails(req, req.params.get("parent"), "")

            # edit metatype masks
            elif key.startswith("editmask_"):
                return MaskDetails(req, req.params.get("parent"), key[9:-2], err=0)

            # delete mask
            elif key.startswith("deletemask_"):
                mtype = getMetaType(req.params.get("parent"))
                mtype.removeChild(tree.getNode(key[11:-2]))
                return showMaskList(req, req.params.get("parent"))

            # create autmatic mask with all fields
            elif key.startswith("automask_"):
                generateMask(getMetaType(req.params.get("parent")))
                return showMaskList(req, req.params.get("parent"))

            # cope selected mask
            if key.startswith("copymask_"):
                mtype = getMetaType(req.params.get("parent"))
                mask = mtype.getMask(key[9:-2])
                cloneMask(mask, "copy_" + mask.getName())
                return showMaskList(req, req.params.get("parent"))

        if "form_op" in req.params.keys():
            if req.params.get("form_op", "") == "cancel":
                return showMaskList(req, req.params.get("parent"))

            if req.params.get("mname", "") == "":
                return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=1)
            elif not checkString(req.params.get("mname", "")):
                # if the name contains wrong characters
                return MaskDetails(req, req.params.get("parent", ""), req.params.get("morig_name", ""), err=4)

            mtype = getMetaType(req.params.get("parent", ""))
            if req.params.get("form_op") == "save_editmask":
                mask = mtype.getMask(req.params.get("maskid", ""))

            elif req.params.get("form_op") == "save_newmask":
                mask = tree.Node(req.params.get("mname", ""), type="mask")
                mtype.addChild(mask)

            mask.setName(req.params.get("mname"))
            mask.setDescription(req.params.get("mdescription"))
            mask.setMasktype(req.params.get("mtype"))
            mask.setSeparator(req.params.get("mseparator"))

            if req.params.get("mtype") == "export":
                mask.setExportMapping(req.params.get("exportmapping") or "")
                mask.setExportHeader(req.params.get("exportheader"))
                mask.setExportFooter(req.params.get("exportfooter"))
                _opt = ""
                if "types" in req.params.keys():
                    _opt += "t"
                if "notlast" in req.params.keys():
                    _opt += "l"
                mask.setExportOptions(_opt)

            mask.setLanguage(req.params.get("mlanguage", ""))
            mask.setDefaultMask("mdefault" in req.params.keys())
            mask.setAccess("read", "")
            for key in req.params.keys():
                if key.startswith("left"):
                    mask.setAccess(key[4:], req.params.get(key).replace(";", ","))
                    break
        return showMaskList(req, str(req.params.get("parent", "")))
    return view(req)
Example #5
0
def showEditor(req):
    path = req.path[1:].split("/")
    mtype = getMetaType(path[1])
    editor = mtype.getMask(path[2])

    req.params["metadatatype"] = mtype
    for key in req.params.keys():
        if req.params.get("op", "") == "cancel":
            if "savedetail" in req.params.keys():
                del req.params["savedetail"]
            break

        if key.startswith("up_"):
            changeOrder(q(Node).get(key[3:-2]).parents[0], q(Node).get(key[3:-2]).orderpos, -1)
            break

        if key.startswith("down_"):
            changeOrder(q(Node).get(key[5:-2]).parents[0], -1, q(Node).get(key[5:-2]).orderpos)
            break

        if key.startswith("delete_"):
            editor.deleteMaskitem(key[7:-2])
            break

        if key.startswith("edit_"):
            op = key[5:-2]
            req.params["edit"] = op
            req.params["op"] = "edit"
            break

        if key.startswith("new_"):
            req.params["edit"] = " "
            break

        if key.startswith("newdetail_"):
            req.params["pid"] = key[10:-2]
            req.params["op"] = "newdetail"
            req.params["edit"] = " "
            if req.params.get("type")in("vgroup", "hgroup"):
                req.params["type"] = "field"
                req.params["op"] = "new"
            if "savedetail" in req.params.keys():
                del req.params["savedetail"]
            break

    if req.params.get("op", "") == "group":
        # create new group for selected objects
        req.params["op"] = "new"
        req.params["edit"] = " "
        req.params["type"] = req.params.get("group_type")
        req.params["pid"] = q(Node).get(req.params.get("sel_id").split(";")[0]).parents[0].id

    if "saveedit" in req.params.keys() and req.params.get("op", "") != "cancel":
        # update node
        label = req.params.get("label", "-new-")
        if req.params.get("op", "") == "edit":
            item = q(Node).get(req.params.get("id"))
            item.setLabel(req.params.get("label", ""))
            db.session.commit()
            if "mappingfield" in req.params.keys():
                # field of export mask
                item.set("attribute", req.params.get("attribute"))
                item.set("fieldtype", req.params.get("fieldtype"))
                mf = req.params.get("mappingfield").split(";")
                if req.params.get("fieldtype") == "mapping":  # mapping field of mapping definition selected
                    item.set("mappingfield", mf[0])
                else:  # attribute name as object name
                    item.set("mappingfield", ";".join(mf[1:]))
                db.session.commit()
            else:
                f = q(Node).get(long(req.params.get("field")))

            field = item.children
            try:
                field = list(field)[0]
                if ustr(field.id) != req.params.get("field"):
                    item.children.remove(field)
                    item.children.append(f)
                field.setValues(req.params.get(u"{}_value".format(field.get("type")), u""))
                db.session.commit()
            except:
                logg.exception("exception in showEditor / saveedit, ignore")
                pass

        elif req.params.get("op", "") == "new":
            if req.params.get("fieldtype", "") == "common" and req.params.get("field"):
                # existing field used
                fieldid = long(req.params.get("field"))
            elif "mappingfield" in req.params.keys():
                # new mapping field
                fieldid = ""  # long(req.params.get("mappingfield"))
                label = "mapping"

            else:
                # create new metaattribute
                parent = req.params.get("metadatatype").getName()
                fieldvalue = req.params.get(req.params.get("newfieldtype", "") + '_value', "")

                if req.params.get("type") == "label":
                    # new label
                    fieldid = ""
                else:
                    # normal field
                    updateMetaField(parent, req.params.get("fieldname"), label, 0,
                                    req.params.get("newfieldtype"), option="", description=req.params.get("description", ""),
                                    fieldvalues=fieldvalue, fieldvaluenum="", fieldid="")
                    fieldid = ustr(getMetaField(parent, req.params.get("fieldname")).id)

            item = editor.addMaskitem(label, req.params.get("type"), fieldid, req.params.get("pid", "0"))

            if "mappingfield" in req.params.keys():
                item.set("attribute", req.params.get("attribute"))
                item.set("fieldtype", req.params.get("fieldtype"))
                mf = req.params.get("mappingfield").split(";")
                if req.params.get("fieldtype") == "mapping":  # mapping field of mapping definition selected
                    item.set("mappingfield", mf[0])
                else:  # attribute name as object name
                    item.set("mappingfield", ";".join(mf[1:]))
                db.session.commit()

            position = req.params.get("insertposition", "end")
            if position == "end":
                # insert at the end of existing mask
                item.orderpos = len(q(Node).get(req.params.get("pid")).children) - 1
                db.session.commit()
            else:
                # insert at special position
                fields = editor.getMaskFields()
                fields.all().sort(lambda x, y: cmp(x.orderpos, y.orderpos))
                for f in fields:
                    if f.orderpos >= q(Node).get(position).orderpos and f.id != item.id:
                        f.orderpos = f.orderpos + 1
                item.orderpos = q(Node).get(position).orderpos - 1
                db.session.commit()

        item.setWidth(req.params.get("width", u'400'))
        item.setUnit(req.params.get("unit", u""))
        item.setDefault(req.params.get("default", u""))
        item.setFormat(req.params.get("format", u""))
        item.setSeparator(req.params.get("separator", u""))
        item.setDescription(req.params.get("description", u""))
        item.setTestNodes(req.params.get("testnodes", u""))
        item.setMultilang(req.params.get("multilang", u""))
        db.session.commit()

        if "required" in req.params.keys():
            item.setRequired(unicode(1))
        else:
            item.setRequired(unicode(0))
        db.session.commit()

    if "savedetail" in req.params.keys():
        label = req.params.get("label", "-new-")
        # save details (used for hgroup)
        if req.params.get("op", "") == "edit":
            item = q(Node).get(req.params.get("id"))
            item.setLabel(req.params.get("label", ""))
        elif req.params.get("op", "") == "new":
            if req.params.get("sel_id", "") != "":
                item = editor.addMaskitem(label, req.params.get("type"), req.params.get(
                    "sel_id", "")[:-1], long(req.params.get("pid", "0")))
            else:
                item = editor.addMaskitem(label, req.params.get("type"), 0, long(req.params.get("pid", "0")))
        db.session.commit()

        # move selected elementd to new item-container
        if req.params.get("sel_id", "") != "":
            pos = 0
            for i in req.params.get("sel_id")[:-1].split(";"):
                n = q(Node).get(i)  # node to move
                n.setOrderPos(pos)
                p = q(Node).get(n.parents()[0].id)  # parentnode
                p.children.remove(n)
                item.children.append(n)  # new group
                pos += 1
            db.session.commit()

        # position:
        position = req.params.get("insertposition", "end")
        if position == "end":
            # insert at the end of existing mask
            item.setOrderPos(len(q(Node).get(req.params.get("pid")).children) - 1)
            db.session.commit()
        else:
            # insert at special position
            fields = []
            pidnode = q(Node).get(req.params.get("pid"))
            for field in pidnode.getChildren():
                if field.getType().getName() == "maskitem" and field.id != pidnode.id:
                    fields.append(field)
            fields.sort(lambda x, y: cmp(x.orderpos, y.orderpos))
            for f in fields:
                if f.orderpos >= q(Node).get(position).orderpos and f.id != item.id:
                    f.orderpos = f.orderpos + 1
            item.orderpos = q(Node).get(position).orderpos - 1
            db.session.commit()

        if "edit" not in req.params.keys():
            item.set("type", req.params.get("type", u""))
        item.setWidth(req.params.get("width", u'400'))
        item.setUnit(req.params.get("unit", u""))
        item.setDefault(req.params.get("default", u""))
        item.setFormat(req.params.get("format", u""))
        item.setSeparator(req.params.get("separator", u""))
        item.setDescription(req.params.get("description", u""))
        if "required" in req.params.keys():
            item.setRequired(unicode(1))
        else:
            item.setRequired(unicode(0))
        db.session.commit()

    v = {}
    v["edit"] = req.params.get("edit", "")
    if req.params.get("edit", "") != "":
        v["editor"] = editor.editItem(req)
    else:
        # show metaEditor
        v["editor"] = ""
        try:
            v["editor"] = req.getTALstr(editor.getMetaMask(req), {})
        except:
            logg.exception("exception in showEditor")
            v["editor"] = editor.getMetaMask(req)

    v["title"] = editor.name
    v["csrf"] = req.csrf_token.current_token
    return req.getTAL("web/admin/modules/metatype.html", v, macro="editor_popup")