示例#1
0
    def formfield(self, **kwargs):
        from django_mongoengine.forms.documents import documentform_factory

        defaults = {"label": self.label, "help_text": self.help_text}
        form_class = EmbeddedDocumentField
        defaults.update(kwargs)
        form = form_class(documentform_factory(self.document_type), **defaults)
        return form
 def formfield(self, **kwargs):
     from django_mongoengine.forms.documents import documentform_factory
     defaults = {
         'label': self.label,
         'help_text': self.help_text,
     }
     form_class = EmbeddedDocumentField
     defaults.update(kwargs)
     form = form_class(documentform_factory(self.document_type), **defaults)
     return form
示例#3
0
 def formfield(self, **kwargs):
     from django_mongoengine.forms.documents import documentform_factory
     defaults = {
         'label': self.verbose_name,
         'help_text': self.help_text,
     }
     form_class = EmbeddedDocumentField
     defaults.update(kwargs)
     form = form_class(documentform_factory(self.document_type), **defaults)
     return form
示例#4
0
    def get_changelist_form(self, request, **kwargs):
        """
        Returns a Form class for use in the Formset on the changelist page.
        """
        defaults = {
            "formfield_callback": partial(self.formfield_for_dbfield, request=request),
        }
        defaults.update(kwargs)
        if defaults.get('fields') is None and not modelform_defines_fields(defaults.get('form')):
            defaults['fields'] = forms.ALL_FIELDS

        return documentform_factory(self.model, **defaults)
示例#5
0
    def get_changelist_form(self, request, **kwargs):
        """
        Returns a Form class for use in the Formset on the changelist page.
        """
        defaults = {
            "formfield_callback": partial(self.formfield_for_dbfield, request=request),
        }
        defaults.update(kwargs)
        if defaults.get('fields') is None and not modelform_defines_fields(defaults.get('form')):
            defaults['fields'] = forms.ALL_FIELDS

        return documentform_factory(self.model, **defaults)
示例#6
0
 def get_form_class(self):
     """
     Returns the form class to use in this view
     """
     if self.form_class:
         return self.form_class
     else:
         if self.document is not None:
             # If a document has been explicitly provided, use it
             document = self.document
         elif hasattr(self, 'object') and self.object is not None:
             # If this view is operating on a single object, use
             # the class of that object
             document = self.object.__class__
         else:
             # Try to get a queryset and extract the document class
             # from that
             document = self.get_queryset()._document
         return documentform_factory(document)
示例#7
0
    def get_form_class(self):
        """
        Returns the form class to use in this view
        """
        if self.form_class:
            return self.form_class
        else:
            if hasattr(self, 'object') and self.object is not None:
                # If this view is operating on a single object, use
                # the class of that object
                document = self.object.__class__
            elif self.document is not None:
                # If a document has been explicitly provided, use it
                document = self.document
            else:
                # Try to get a queryset and extract the document class
                # from that
                document = self.get_queryset()._document

            exclude = getattr(self, 'form_exclude', ())
            return documentform_factory(document, exclude=exclude)
示例#8
0
    def test_documentform_factory(self):
        from .models import MongoDoc, DjangoModel

        m_form = documentform_factory(MongoDoc, fields="__all__")()
        d_form = modelform_factory(DjangoModel, fields="__all__")()
        self.assertEqual(d_form.as_p(), m_form.as_p())
示例#9
0
    def get_form_class(self):
        from django_mongoengine.forms.documents import documentform_factory

        return documentform_factory(self.object.__class__, fields=self.fields)
示例#10
0
 def get_form_class(self):
     from django_mongoengine.forms.documents import documentform_factory
     return documentform_factory(self.object.__class__, fields=self.fields)
示例#11
0
 def test_documentform_factory(self):
     from .models import MongoDoc, DjangoModel
     m_form = documentform_factory(MongoDoc, fields="__all__")()
     d_form = modelform_factory(DjangoModel, fields="__all__")()
     self.assertEqual(d_form.as_p(), m_form.as_p())