Пример #1
0
 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 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)
Пример #3
0
 def make_bound_schema(self):
     if getattr(self, '_mixin_bound', False):
         return type(self)
     
     original_fields = self._meta.fields.keys()
     
     def get_active_mixins(kls, target=None):
         return self.get_active_mixins(target=target)
     
     def send_mixin_event(kls, event, kwargs):
         return self.send_mixin_event(event, kwargs)
     
     cls = type(self)
     
     document_kwargs = {
         'fields':{},#copy(self._meta.fields.fields), #fields => uber dictionary, fields.fields => fields we defined
         'proxy': True,
         'name': cls.__name__,
         'parents': (cls,),
         'module': cls.__module__,
         'attrs': {'get_active_mixins':classmethod(get_active_mixins),
                   'send_mixin_event':classmethod(send_mixin_event),
                   '_mixin_bound':True},
     }
     self.send_mixin_event('document_kwargs', {'document_kwargs':document_kwargs})
     new_cls = create_document(**document_kwargs)
     assert self._meta.fields.keys() == original_fields
     return new_cls
Пример #4
0
    def register_collection(self):
        #create a base page document
        params = {
            'module': 'dockitcms.models.virtual',
            'virtual': False,
            'verbose_name': self.title,
            'collection': self.get_collection_name(),
            'parents': (BasePage, schema.Document),
            'name': self.get_schema_name(),
            'attrs': SortedDict(),
            'fields': SortedDict(),
            'typed_field': '_page_type',
        }
        if self.application:
            params['app_label'] = self.application.name
        params['attrs']['_collection_document'] = self

        base_doc = create_document(**params)
        force_register_documents(base_doc._meta.app_label, base_doc)
        base_doc.objects.index('path').commit()

        #loop through page_definitions and register them
        for page_def in self.page_definitions:
            params = {
                'parents': (base_doc,),
                'virtual': False,
                'typed_key': page_def.unique_id,
                'attrs': SortedDict([
                    ('_page_def', page_def),
                ])
            }
            page_def.get_document(**params)

        #CONSIDER: provide page defs defined in code
        for unique_id, page_schema in dict().items(): #REGISTERED_PAGE_DEFS.items()
            params = {
                'virtual': False,
                'typed_key': unique_id,
                'parents': (page_schema, base_doc),
                'name': '', #page_schema._meta.name,
                'fields': SortedDict(),
            }
            create_document(**params)

        return base_doc
Пример #5
0
 def get_document(self, **kwargs):
     fields = self.get_fields()
     name = self.get_schema_name()
     params = {'module':'dockitcms.models',
               'virtual':True,}
     if self.inherit_from:
         parent = self._meta.fields['inherit_from'].get_schema(self.inherit_from)
         if parent:
             params['parents'] = (parent, )
     params.update(kwargs)
     document = create_document(name, fields, **params)
     
     def __unicode__(instance):
         if not self.object_label:
             return repr(instance)
         try:
             return self.object_label % instance
         except (KeyError, TypeError):
             return repr(instance)
     
     document.__unicode__ = __unicode__
     return document
Пример #6
0
 def get_document(self, **kwargs):
     params = self.get_document_kwargs(**kwargs)
     doc = create_document(**params)
     if not issubclass(doc, schema.Document):
         raise TypeError("Did not properly create a document")
     return doc
Пример #7
0
 def get_document(self, **kwargs):
     params = self.get_document_kwargs(**kwargs)
     doc = create_document(**params)
     if not issubclass(doc, schema.Document):
         raise TypeError("Did not properly create a document")
     return doc