How to use the schema.schema.Metadatatype function in schema

To help you get started, we’ve selected a few schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mediatum / mediatum / web / admin / modules / metatype.py View on Github external
v = getAdminStdVars(req)

    if err == 0 and id == "":
        # new metadatatype
        metadatatype = Metadatatype(u"")
        db.session.commit()
        v["original_name"] = ""

    elif id != "" and err == 0:
        # edit metadatatype
        metadatatype = getMetaType(id)
        v["original_name"] = metadatatype.getName()

    else:
        # error
        metadatatype = Metadatatype(req.params["mname"])
        metadatatype.set("description", req.params["description"])
        metadatatype.set("longname", req.params["mlongname"])
        metadatatype.set("active", "mactive" in req.params)
        metadatatype.set("datatypes", req.params.get("mdatatypes", "").replace(";", ", "))
        metadatatype.set("bibtexmapping", req.params.get("mbibtex", ""))
        metadatatype.set("citeprocmapping", req.params.get("mciteproc", ""))
        db.session.commit()
        v["original_name"] = req.params["mname_orig"]
    d = Data()
    v["datatypes"] = d.get_all_datatypes()
    v["datatypes"].sort(lambda x, y: cmp(t(lang(req), x.__name__), t(lang(req), y.__name__)))
    v["metadatatype"] = metadatatype
    v["error"] = err
    v["bibtextypes"] = getAllBibTeXTypes()
    v["bibtexselected"] = metadatatype.get("bibtexmapping").split(";")
    v["citeproctypes"] = citeproc.TYPES
github mediatum / mediatum / workflow / fileattachment.py View on Github external
self.access_ruleset_assocs.append(NodeToAccessRuleset(ruleset_name=r.ruleset_name, ruletype='data'))
                db.session.commit()

        if "gotrue" in req.params:
            return self.forwardAndShow(node, True, req)
        elif "gofalse" in req.params:
            return self.forwardAndShow(node, False, req)

        if self.getTrueLabel(language=node.get("system.wflanguage")) == "" and self.getFalseLabel(
                language=node.get("system.wflanguage")) == "":
            buttons = []
        else:
            buttons = self.tableRowButtons(node)

        try:
            mask = q(Metadatatype).filter_by(name=node.schema).one().getMask(self.get("mask_fileatt"))
            maskdata = mask.getViewHTML([node], VIEW_HIDE_EMPTY, language=lang(req))
        except:
            logg.exception("exception in workflow step fileAttachment, getViewHTML failed, empty string")
            maskdata = ""

        return req.getTAL("workflow/fileattachment.html",
                          {"buttons": buttons,
                           "files": self.files,
                           "wfnode": self,
                           "pretext": self.getPreText(lang(req)),
                           "posttext": self.getPostText(lang(req)),
                           "sidebar": self.getSidebarText(lang(req)),
                           'maskdata': maskdata,
                           "csrf": req.csrf_token.current_token,},
                          macro="fileattachment_show_node")
github mediatum / mediatum / schema / schema.py View on Github external
def updateMetaType(name, description="", longname="", active=0, datatypes="", bibtexmapping="", orig_name="", citeprocmapping=""):
    metadatatypes = q(Metadatatypes).one()
    metadatatype = metadatatypes.children.filter_by(name=orig_name).scalar()

    if metadatatype is not None:
        metadatatype.name = name
    else:
        metadatatype = Metadatatype(name)
        metadatatypes.children.append(metadatatype)

    metadatatype.set("description", description)
    metadatatype.set("longname", longname)
    metadatatype.set("active", ustr(active))
    metadatatype.set("datatypes", datatypes)
    metadatatype.set("bibtexmapping", bibtexmapping)
    metadatatype.set("citeprocmapping", citeprocmapping)
    db.session.commit()
github mediatum / mediatum / web / admin / modules / metatype.py View on Github external
def MetatypeDetail(req, id, err=0):
    v = getAdminStdVars(req)

    if err == 0 and id == "":
        # new metadatatype
        metadatatype = Metadatatype(u"")
        db.session.commit()
        v["original_name"] = ""

    elif id != "" and err == 0:
        # edit metadatatype
        metadatatype = getMetaType(id)
        v["original_name"] = metadatatype.getName()

    else:
        # error
        metadatatype = Metadatatype(req.params["mname"])
        metadatatype.set("description", req.params["description"])
        metadatatype.set("longname", req.params["mlongname"])
        metadatatype.set("active", "mactive" in req.params)
        metadatatype.set("datatypes", req.params.get("mdatatypes", "").replace(";", ", "))
        metadatatype.set("bibtexmapping", req.params.get("mbibtex", ""))
github mediatum / mediatum / web / newadmin / views / user.py View on Github external
        "metadatatypes": QuerySelectMultipleField(query_factory=lambda: db.query(Metadatatype).order_by(Metadatatype.name),
                                          widget=form.Select2Widget(multiple=True)),
github mediatum / mediatum / web / services / export / handlers.py View on Github external
# check node existence
    node = q(Node).get(id)
    if node is None:
        return _client_error_response(404, u"node not found")

    home = get_home_root_node()
    collections = get_collections_node()
    # check node access
    if node.has_read_access(user=user) and (node.is_descendant_of(collections) or node.is_descendant_of(home)):
        pass
    else:
        return _client_error_response(403, u"forbidden")

    if mdt_name:
        mdt = q(Metadatatype).filter_by(name=mdt_name).count()
        if not mdt:
            return _client_error_response(404, u'no such metadata type: ' + mdt_name)

    if allchildren:
        if csv:
            # fetch only those columns which are needed, this is faster than fetch all columns and need less space
            nodequery = node.all_children_by_query(q(Node.attrs.label("attributes"), Node.id, Node.name, Node.schema, Node.type))
        else:
            nodequery = node.all_children
    elif parents:
        nodequery = node.parents
    else:
        nodequery = node.children

    if searchquery:
        search_languages = get_service_search_languages()
github mediatum / mediatum / web / common / sort.py View on Github external
Must be given either a container OR a metadatatype.
    """

    assert t_desc>""  # check that it is an non-empty string
    assert bool(container)!=bool(metadatatype)  # only accept either, container or metadatatype!

    if metadatatype:
        metadatatypes = (metadatatype,)
    else:
        schemanames = container.all_children_by_query(
            q(_Node.schema)
            .filter_by(subnode=False)
            .group_by(_Node.schema)
            .order_by(_func.count(_Node.schema).desc())
        )
        metadatatypes = (q(_Metadatatype).filter_by(name=s[0]).one() for s in schemanames)

    yield SortChoice(t_off, off, False, "not selected" if selected_value else "")
    for m in metadatatypes:
        result = tuple(_get_metadata_type_for_sort(m, t_desc, selected_value))
        if result:
            for r in result:
                yield r
            return
github mediatum / mediatum / core / startup.py View on Github external
tree.registerNodeClass("image", Image)
from contenttypes.document import Document
tree.registerNodeClass("document", Document)
from contenttypes.flash import Flash
tree.registerNodeClass("flash", Flash)
from contenttypes.video import Video
tree.registerNodeClass("video", Video)
from core.user import User
tree.registerNodeClass("user", User)
from core.usergroup import UserGroup
tree.registerNodeClass("usergroup", UserGroup)
from contenttypes.default import Default
tree.registerNodeClass("default", Default)

from schema.schema import Metadatatype, Metadatafield, Mask, Maskitem
tree.registerNodeClass("metadatatype", Metadatatype)
tree.registerNodeClass("metafield", Metadatafield)
tree.registerNodeClass("mask", Mask)
tree.registerNodeClass("maskitem", Maskitem)

from workflow import workflow
workflow.register()

from utils.utils import splitpath

for k,v in config.getsubset("plugins").items():
    print 'Initializing plugin "'+k+'"'
    path,module = splitpath(v)
    if path and path not in sys.path:
        sys.path += [path]
    m = __import__(module)
github mediatum / mediatum / schema / schema.py View on Github external
def get_permitted_schemas():
    return q(Metadatatype).filter(Metadatatype.a.active == "1").filter_read_access().order_by(Metadatatype.a.longname).all()
github mediatum / mediatum / web / newadmin / views / user.py View on Github external
def on_model_change(self, form, usergroup, is_created):
        if is_created:
            """ create ruleset for group """
            existing_ruleset = q(AccessRuleset).filter_by(name=usergroup.name).scalar()
            if existing_ruleset is None:
                rule = get_or_add_access_rule(group_ids=[usergroup.id])
                ruleset = AccessRuleset(name=usergroup.name, description=usergroup.name)
                arr = AccessRulesetToRule(rule=rule)
                ruleset.rule_assocs.append(arr)

        """ add/remove access to Metadatatypes """
        for mt in q(Metadatatype):
            nrs_list = q(NodeToAccessRuleset).filter_by(nid=mt.id).filter_by(ruleset_name=usergroup.name).all()
            if mt in form.metadatatypes.data:
                if not nrs_list:
                    mt.access_ruleset_assocs.append(NodeToAccessRuleset(ruleset_name=usergroup.name, ruletype=u'read'))
            else:
                for nrs in nrs_list:
                    mt.access_ruleset_assocs.remove(nrs)