def test_force_register_documents(self): doc = create_document('testDocument', fields={'title':schema.CharField()}) doc = create_document('testDocument', fields={'title':schema.CharField(), 'slug':schema.SlugField()}) force_register_documents(doc._meta.app_label, doc) doc = get_base_document(doc._meta.collection) self.assertTrue('slug' in doc._meta.fields)
def Deserializer(object_list, **options): """ Deserialize simple Python objects back into Django ORM instances. It's expected that you pass the Python objects themselves (instead of a stream or a string) to the constructor """ # models.get_apps() use_natural_keys = options.get("use_natural_keys", True) for d in object_list: # Look up the model and starting build a dict of data for it. doc_cls = get_base_document(d["model"]) data = d["fields"] if use_natural_keys: data["@natural_key"] = d["natural_key"] else: data[doc_cls._meta.pk.attname] = doc_cls._meta.pk.to_python(d["pk"]) yield base.DeserializedObject(doc_cls.to_python(data), natural_key=d["natural_key"])
def Deserializer(object_list, **options): """ Deserialize simple Python objects back into Django ORM instances. It's expected that you pass the Python objects themselves (instead of a stream or a string) to the constructor """ #models.get_apps() use_natural_keys = options.get('use_natural_keys', True) for d in object_list: # Look up the model and starting build a dict of data for it. doc_cls = get_base_document(d["collection"]) data = d['fields'] if use_natural_keys and 'natural_key' in d: data['@natural_key'] = d['natural_key'] elif 'pk' in d: data[doc_cls._meta.pk.attname] = doc_cls._meta.pk.to_python( d["pk"]) if 'natural_key' in d: yield base.DeserializedObject(doc_cls.to_python(data), natural_key=d['natural_key']) else: yield base.DeserializedObject(doc_cls.to_python(data))
def get_document(self): return get_base_document(self.collection)
def test_document_was_registered(self): self.assertTrue(SimpleDocument._meta.collection in app_cache.documents) get_base_document(SimpleDocument._meta.collection)