def __init__(self, dbm, name=None, slug=None, primitive_type=None, description=None, constraints=None, tags=None, id=None, **kwargs): """Create a new DataDictType. This represents a type of data that can be used to coordinate data collection and interoperability. """ assert isinstance(dbm, DatabaseManager) assert name is None or is_string(name) assert slug is None or is_string(slug) assert primitive_type is None or is_string(primitive_type) assert description is None or is_string(description) assert constraints is None or isinstance(constraints, dict) # how to assert any kwargs? DataObject.__init__(self, dbm) # Are we being constructed from an existing doc? if name is None: return # Not made from existing doc, so create a new one doc = DataDictDocument(id, primitive_type, constraints, slug, name, description, tags, **kwargs) self._set_document(doc)
def get_datadict_type_by_slug(dbm,slug): assert isinstance(dbm, DatabaseManager) assert is_string(slug) rows = dbm.load_all_rows_in_view('by_datadict_type', key=slug,include_docs='true') if not len(rows): raise DataObjectNotFound("DataDictType","slug",slug) assert len(rows) == 1, "More than one item found for slug %s" % (slug,) # include_docs = 'true' returns the doc as a dict, which has to be wrapped into a DataDictDocument, and then into a DataDictType _doc = DataDictDocument.wrap(rows[0].doc) return DataDictType.new_from_doc(dbm,_doc)
def get_datadict_type_by_slug(dbm, slug): assert isinstance(dbm, DatabaseManager) assert is_string(slug) rows = dbm.load_all_rows_in_view('by_datadict_type', key=slug, include_docs='true') if not len(rows): raise DataObjectNotFound("DataDictType", "slug", slug) assert len(rows) == 1, "More than one item found for slug %s" % (slug, ) # include_docs = 'true' returns the doc as a dict, which has to be wrapped into a DataDictDocument, and then into a DataDictType _doc = DataDictDocument.wrap(rows[0].doc) return DataDictType.new_from_doc(dbm, _doc)
def create_from_json(cls, json, dbm): doc = DataDictDocument.wrap(json) return DataDictType.new_from_doc(dbm, doc)
def create_from_json(cls, json,dbm): doc = DataDictDocument.wrap(json) return DataDictType.new_from_doc(dbm,doc)