Ejemplo n.º 1
0
 def test_ref(self):
     assert registry.entity == registry.get('entity')
     assert registry.get('banana') is None
     assert registry.entity.ref('banana') == 'e:banana'
     t, v = registry.deref('e:banana')
     assert t == registry.entity
     assert v == 'banana'
Ejemplo n.º 2
0
    def __init__(self, schema, name, data):
        self.schema = schema
        self.model = schema.model

        self.name = stringify(name)
        self.qname = '%s:%s' % (schema.name, self.name)
        if self.name in self.RESERVED:
            raise InvalidModel("Reserved name: %s" % self.name)

        self.data = data
        self._label = data.get('label', name)
        self._description = data.get('description')
        self.required = data.get('required', False)
        self.hidden = data.get('hidden', False)
        self.stub = data.get('stub', False)

        type_ = data.get('type', 'string')
        self.type = registry.get(type_)
        if self.type is None:
            raise InvalidModel("Invalid type: %s" % type_)

        self.matchable = data.get('matchable', self.type.matchable)
        self.range = None
        self.reverse = None
        self.uri = URIRef(data.get('rdf', NS[self.qname]))
Ejemplo n.º 3
0
def transform_proxy(proxy, fields, skip_schemas=DEFAULT_SKIP_SCHEMAS):
    if any(proxy.schema.is_a(s) for s in skip_schemas):
        return
    for field in fields:
        if field == "trash":
            data = generate_trash(proxy)
        else:
            prop = registry.get(field)
            data = proxy.get_type_values(prop)
        yield from ((field, clean_value(value)) for value in data)
Ejemplo n.º 4
0
    def __init__(self, schema, name, data):
        self.model = schema.model

        #: The schema which the property is defined for. This is always the
        #: most abstract schema that has this property, not the possible
        #: child schemata that inherit it.
        self.schema = schema

        #: Machine-readable name for this property.
        self.name = stringify(name)

        #: Qualified property name, which also includes the schema name.
        self.qname = "%s:%s" % (schema.name, self.name)
        if self.name in self.RESERVED:
            raise InvalidModel("Reserved name: %s" % self.name)

        self._hash = hash("<Property(%r)>" % self.qname)

        self.data = data
        self._label = data.get("label", name)
        self._description = data.get("description")

        #: This property should not be shown or mentioned in the user interface.
        self.hidden = data.get("hidden", False)

        type_ = data.get("type", "string")
        #: The data type for this property.
        self.type = registry.get(type_)
        if self.type is None:
            raise InvalidModel("Invalid type: %s" % type_)

        #: Whether this property should be used for matching and cross-referencing.
        self.matchable = data.get("matchable", self.type.matchable)

        #: If the property is of type ``entity``, the set of valid schema to be added
        #: in this property can be constrained. For example, an asset can be owned,
        #: but a person cannot be owned.
        self.range = None

        #: When a property points to another schema, a reverse property is added for
        #: various administrative reasons. These properties are, however, not real
        #: and cannot be written to. That's why they are marked as stubs and adding
        #: values to them will raise an exception.
        self.stub = data.get("stub", False)

        #: When a property points to another schema, a stub reverse property is
        #: added as a place to store metadata to help display the link in inverted
        #: views.
        self.reverse = None

        #: RDF term for this property (i.e. the predicate URI).
        self.uri = URIRef(data.get("rdf", NS[self.qname]))
Ejemplo n.º 5
0
    def __init__(self, schema, name, data, stub=False):
        self.schema = schema
        self.name = name.strip()
        self.qname = '%s:%s' % (schema.name, self.name)
        self.data = data
        self._label = data.get('label', name)
        self._description = data.get('description')
        self.caption = data.get('caption', False)
        self.required = data.get('required', False)
        self._type = data.get('type', 'text')
        self.type = registry.get(self._type)
        if self.type is None:
            raise InvalidModel("Invalid type: %s" % self._type)

        self.range = None
        self.reverse = None
        self.stub = stub

        self.uri = NAMESPACE[self.qname]
        if 'rdf' in data:
            self.uri = URIRef(data.get('rdf'))
Ejemplo n.º 6
0
    def __init__(self, schema, name, data):
        self.schema = schema
        self.model = schema.model

        self.name = stringify(name)
        self.qname = "%s:%s" % (schema.name, self.name)
        if self.name in self.RESERVED:
            raise InvalidModel("Reserved name: %s" % self.name)

        self.data = data
        self._label = data.get("label", name)
        self._description = data.get("description")
        self.hidden = data.get("hidden", False)
        self.stub = data.get("stub", False)

        type_ = data.get("type", "string")
        self.type = registry.get(type_)
        if self.type is None:
            raise InvalidModel("Invalid type: %s" % type_)

        self.matchable = data.get("matchable", self.type.matchable)
        self.range = None
        self.reverse = None
        self.uri = URIRef(data.get("rdf", NS[self.qname]))
Ejemplo n.º 7
0
 def field(self):
     type_ = registry.get(self.type)
     if type_ is not None and type_.group is not None:
         return type_.group
Ejemplo n.º 8
0
 def test_registry(self):
     assert registry.entity == registry.get('entity')
     assert registry.get('banana') is None
     assert registry.get(registry.entity) == registry.entity
Ejemplo n.º 9
0
 def test_specificity(self):
     urls = registry.get('url')
     self.assertEqual(urls.specificity('http://foo.com/'), 1)
Ejemplo n.º 10
0
 def test_registry(self):
     assert registry.entity == registry.get("entity")
     assert registry.get("banana") is None
     assert registry.get(registry.entity) == registry.entity