Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

A bunch of changes and fixes #14

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

A bunch of changes and fixes #14

wants to merge 42 commits into from

Conversation

lexqt
Copy link

@lexqt lexqt commented Nov 13, 2012

Hello, @wpjunior.

Maybe I misunderstood something from your mail (whether a new version will be introduced in a current mongotools repo or in some external system only) but anyway I created this pull request just in case.

A bunch of changes and fixes intended to make mongotools views and forms more like their equivalents from Django (v 1.4) and to support more features from MongoEngine (v 0.7-0.8), e.g.:

  • Sync mongotools codebase with Django 1.4
  • Add missed view and form classes properties
  • Use inheritance from Django classes whenever it's possible
  • Rename MongoForm to DocumentForm (like in https://github.com/jschrewe/django-mongodbforms)
  • Add EmbeddedDocument form
  • Fix FileField support
  • Fix form validation
  • etc

in order to override in subclasses
to be more like original equivalents from Django
`fields_for_document` now returns `None` for fields not supported by
formfield generator. Such fields are filtered or replaced later by declared
fields in `DocumentFormMetaClass`.
``parent_document`` argument is not obligatory anymore. It can be
automatically set if embedded doc has a parent reference
(MongoEngine/mongoengine#139).

Add basic support for ListField(EmbeddedDocumentField).
Get rid of positional arguments. Use only kwargs to simplify
generated fields customization in forms. E.g.:

    class MyForm(DocumentForm):
      class Meta:
        document = MyDoc

      my_field = default_generator.generate(MyDoc.my_field,
                               formfield_kwarg=custom_value)
Now it's ok to dynamically overwrite field attrs (like `required`) at
form initialization.
See Django `ModelForm._post_clean`.
Otherwise we can get unexpected results sometimes.
Example:
There is a document with "alias" field. Alias is used in all urls incl.
update view url. We use UpdateView with DocumentForm, set some field to
invalid value and change alias. Our document is not saved because of one
invalid field value. Update view is rendered again. But `object` var from
context_data is an updated document with another alias. So html form
`action` arg is a wrong url pointing to non-existent doc. And we can get
404 error on next form submission.
Better than nothing.
TODO: implement something like `BaseModelForm.validate_unique`.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant