Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
8e01355
Merge pull request #31 from rafaelnovello/master
Jun 13, 2013
22982bb
More glue for admin in documentoptions and some dynamic widget stuff …
Jun 13, 2013
e72a212
Add more attributes to make delete in Django's 1.5 admin work
Jun 14, 2013
80606d5
Removed forgotton print statements
Jun 14, 2013
b71981f
bugfix: instance empty ListFields were not removed before saving, so…
laurentpayot Jun 20, 2013
2eefb4f
Merge pull request #35 from laurentpayot/master
Jun 20, 2013
e409826
Minor changes
Jun 20, 2013
75ac5b8
EmbeddedDocumentForm optimization with position argument and atomic u…
laurentpayot Jun 21, 2013
fcc5a91
Merge pull request #36 from laurentpayot/EmbeddedDocumentForm-optimiz…
Jun 21, 2013
26d1d69
Load instance in EmbeddedDocumentForm.__init__ if position argument i…
Jun 21, 2013
e66c492
Test for parent_embedded_field before using it
Jun 21, 2013
d020626
Updated documentation for embedded fields
Jun 21, 2013
6ad8c05
More docs
Jun 21, 2013
5cbe856
And again doc formatting
Jun 21, 2013
6931bb3
Figure out position if instance is provided for embedded forms
Jun 21, 2013
655aeee
actually assign position and not just figure it out. Dough!
Jun 21, 2013
036d519
Use position argument in embedded formsets
Jun 21, 2013
a3745c8
A couple small fixes and some code formatting
Jun 22, 2013
29f4f74
Initial support for MapFields. Probably full of bugs and not too sure…
Jun 23, 2013
9e02487
Added a field map to the generator to handle fields like SortedListField
Jun 23, 2013
6edf16c
small MapField bugfixes
laurentpayot Jun 23, 2013
38ec76a
Merge pull request #38 from laurentpayot/master
Jun 23, 2013
da4b134
MapFields with FileFields save now. Not exactly sure what though.
Jun 23, 2013
d37e892
Correctly init proxy_class for new images
Jun 23, 2013
f2d6ef9
Forgotten print statement
Jun 23, 2013
e071760
Handle file fields in list fields too and a bit of clean up
Jun 23, 2013
fd3fc2a
get the filename for uploaded files after an old file has been deleted
Jun 23, 2013
e9be017
Better support for custom fieldgenerators.
Jun 24, 2013
0cf56e8
Correctly handle ListField(FileField())
Jun 26, 2013
48e2ab9
Version bump
Jun 26, 2013
821fde8
Git ignore
Jun 26, 2013
8086f01
Romved eclipse stuff
Jun 26, 2013
75029e5
DocumentWrapper clean and removed all _admin_opt references
Jun 26, 2013
1b883c9
Define format_html if we can't import it from Django. Closes #41
Jun 27, 2013
3d173b8
Avoid format_html altogether now. A real fix for #41, not just copy&p…
Jun 27, 2013
b6000a0
Removed the relationship experiment
Jun 28, 2013
660ff2a
Deal with None in EmbeddedDocumentFormSet._construct_form
Jul 1, 2013
c7ae5bb
Correctly handle widget overrides in Map and ListFields
Jul 8, 2013
8d96398
Version bump
Jul 8, 2013
ce0287b
Handling of unique_with and ListField(ReferenceField()). Closes #43
Jul 8, 2013
07c69e6
reduce is in functools module in Python 3
laurentpayot Jul 8, 2013
9ce39f8
Merge pull request #44 from laurentpayot/master
Jul 8, 2013
113c6a9
Cleanup of fields_for_document. Finally keep the fields in creation o…
Jul 8, 2013
bac9406
Use f.name more consistently and not some var that points to f.name
Jul 9, 2013
9072c36
Use db_alias and collection_name in _get_unique_filename. And delete …
Jul 9, 2013
1ac29d2
Field defaults in Fieldgenerator can be (are supposed to be?) callables
Jul 9, 2013
dcb11fc
Don't construct the instance several times during clean and save
Jul 9, 2013
4570a48
Cleanup of reference form fields. ReferenceField now uses pk and no l…
Jul 9, 2013
57f0939
Use hasattr instead of except in fieldgenerator so errors during fiel…
Jul 9, 2013
420ef26
SOme documentation and correct id's in map field widget
Jul 10, 2013
6f9d8c9
Formatting fun
Jul 10, 2013
d6d2b3a
Formatting again
Jul 10, 2013
7759f08
More documentation stuff
Jul 10, 2013
8d28552
Parameters for field generation
Jul 10, 2013
d27b3f5
Don't pass min_length to string fields with choices
Jul 12, 2013
c57c620
Get rid of the fake document hack with mongoengine 0.8.3
Jul 12, 2013
3886b87
Add a swapped property to DocumentOptions. Might be usefull for more …
Jul 15, 2013
6a7d10d
Initial setting on fields
Jul 15, 2013
6853342
Support unbound function in patch_document
Jul 17, 2013
fb57c72
Generate a verbose_name for fields if it's None too
Jul 19, 2013
38e2a28
Remove _delete_bofore_save stuff for now. Seems to be unnecessary acc…
Jul 22, 2013
ff22563
ReferenceFields('my_class') don't run until max recursion depth is re…
Jul 30, 2013
34cd9bd
Fix http://dev.1flow.net/webapps/1flow/group/4093/
Aug 1, 2013
26f656b
Data and files argument before instance or position for EmbeddedDocum…
Aug 8, 2013
3733bd6
Merge pull request #49 from Karmak23/master
Aug 8, 2013
5cb3a5b
Hopefully fixes for #47 and #48 in one go
Aug 8, 2013
0c50eff
Handle missing _changed_fields. Fix for #51.
Aug 9, 2013
1bba2ad
create instance first then access _changed_fields
Aug 9, 2013
1224196
Hrmpf. Close #52. It's getting emerassing...
Aug 9, 2013
e118526
Fix for #53 from @Prydie. Cheers
Aug 16, 2013
053624f
Allow passing of a pre initialised contained field into List and MapF…
Aug 31, 2013
6724f56
Stop passing around widget classes and use objects
Aug 31, 2013
a41eb42
Handle value == None in prepare_value
Aug 31, 2013
efc4d7a
Proper fieldname generation
Sep 5, 2013
147a7c2
Basic support for a Django style rel attribute on ReferenceFields
Sep 10, 2013
0516d8e
Support rel attribute for ListField(ReferenceFields())
Sep 10, 2013
1af07ae
Fix one of the stupid copy & paste oversights for #22.
Sep 13, 2013
8afa890
Get Django compatible error messages from mongoengine ValidationError…
Sep 16, 2013
3d099bb
Hrmpf. More error handling for #57
Sep 16, 2013
39262c2
Hmm, hopefully get a useable message for #57 now.
Sep 16, 2013
36ce932
Properly call document validation excluding untouched fields
Sep 25, 2013
ec80e4c
Use a tuple in the last commit instead of a list
Sep 25, 2013
d9bf32c
Html5 widget support; Hopefully got rid of the need for _dont_save st…
Oct 21, 2013
7a3f4f0
Remove debug print statemant
Oct 21, 2013
df67df4
PEP8 and a couple new form fields that return None instead of ''
Oct 24, 2013
d8c16b5
Fix a bug in unique_with queryset generation
Oct 31, 2013
efa1bb1
We don't need no recursion for #60
Nov 9, 2013
164ef61
Hmpf. Print isn't supposed to be there...
Nov 9, 2013
058ce02
Cleanup of container widgets and code for LazyDocumentWrapper
Nov 12, 2013
703965c
Absolute imports and proper handling of embedded field names for Form…
Nov 14, 2013
21fb038
Make sure not to use LazyDocumentMetaWrapper as doc's meta for #61
Nov 21, 2013
2a265b8
A couple more changes for Django 1.6 and hidden MapField widget
Nov 26, 2013
58a1c36
Errors found by pyflakes
Nov 27, 2013
d8cc4d4
get_verbose_name fix for new django 1.7
naisonsouza Oct 4, 2014
9a581e4
get_verbose_name fix for newer Django versions
laurentpayot Dec 5, 2014
b3331fe
mongoengine StringField regex fix
laurentpayot Dec 5, 2014
7115aa0
LazyDocumentMetaWrapper getitem method fixed
Bahus Dec 23, 2014
cef1d49
Version bump to 0.3.1
Bahus Dec 23, 2014
0b4cc51
specify app_label in document meta
Feb 5, 2015
fdeedc0
Django 1.7+ compatibility: get_verbose_name -> camel_case_to_spaces
olivierlefloch Mar 10, 2015
50d92fe
More Django 1.7 compatibility
olivierlefloch Mar 10, 2015
5438a1d
Django 1.8 support (OPS-4393)
olivierlefloch May 4, 2015
64b10d4
Set _deferred on the model properly (OPS-4393)
olivierlefloch May 5, 2015
8f1e078
compute the document pk value on the fly
May 6, 2015
faa3975
Fix deletion in admin (django 1.7+) (OPS-4455)
olivierlefloch May 20, 2015
996d04c
Merge branch 'master' into olefloch/OPS-4455/delete_in_admin_17
olivierlefloch May 20, 2015
0645b12
Merge pull request #7 from Work4Labs/olefloch/OPS-4455/delete_in_admi…
olivierlefloch May 20, 2015
c4e9a20
Merge pull request #72 from naisonsouza/django-1.7-version-fix
jschrewe Jul 6, 2015
62bab67
Merge pull request #77 from laurentpayot/django_fixes
jschrewe Jul 6, 2015
3759a48
Merge branch ‘pr/78’ from (@Bahus) and close #78
Jul 6, 2015
9c033f6
Merge ‘pr/81’ from @m-vdb and @olivierlefloch Close #81
Jul 6, 2015
397cd92
PEP-8 cleanup. DocumentFormMetaclass now inherits from
Jul 6, 2015
9d7e48d
Figure out a decent ‘queryset’ in EmbeddedDocumentFormSet.__init__ for
Jul 7, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ MANIFEST
build/*
*egg*
*.bak
.settings/*
*.tmproj
.tm_properties



4 changes: 0 additions & 4 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

95 changes: 73 additions & 22 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,38 @@ documents.
Requirements
------------

- `mongoengine <http://mongoengine.org/>`_
- Django >= 1.4
- `mongoengine <http://mongoengine.org/>`__ >= 0.8.3

Supported field types
---------------------

Mongodbforms supports all the fields that have a simple representation
in Django's formfields (IntField, TextField, etc). In addition it also
supports ``ListFields`` and ``MapFields``.

File fields
~~~~~~~~~~~

Mongodbforms handles file uploads just like the normal Django forms.
Uploaded files are stored in GridFS using the mongoengine fields.
Because GridFS has no directories and stores files in a flat space an
uploaded file whose name already exists gets a unique filename with the
form ``<filename>_<unique_number>.<extension>``.

Container fields
~~~~~~~~~~~~~~~~

For container fields like ``ListFields`` and ``MapFields`` a very simple
widget is used. The widget renders the container content in the
appropriate field plus one empty field. This is mainly done to not
introduce any Javascript dependencies, the backend code will happily
handle any kind of dynamic form, as long as the field ids are
continuously numbered in the POST data.

You can use any of the other supported fields inside list or map fields.
Including ``FileFields`` which aren't really supported by mongoengine
inside container fields.

Usage
-----
Expand All @@ -20,7 +51,7 @@ Normal documents
To use mongodbforms with normal documents replace djangos forms with
mongodbform forms.

::
.. code:: python

from mongodbforms import DocumentForm

Expand All @@ -32,64 +63,84 @@ Embedded documents

For embedded documents use ``EmbeddedDocumentForm``. The Meta-object of
the form has to be provided with an embedded field name. The embedded
object is appended to this. The form constructor takes an additional
argument: The document the embedded document gets added to.
object is appended to this. The form constructor takes a couple of
additional arguments: The document the embedded document gets added to
and an optional position argument.

If no position is provided the form adds a new embedded document to the
list if the form is saved. To edit an embedded document stored in a list
field the position argument is required. If you provide a position and
no instance to the form the instance is automatically loaded using the
position argument.

If the form is saved the new embedded object is automatically added to
the provided parent document. If the embedded field is a list field the
embedded document is appended to the list, if it is a plain embedded
field the current object is overwritten. Note that the parent document
is not saved.
If the embedded field is a plain embedded field the current object is
simply overwritten.

::
.. code:: python

# forms.py
from mongodbforms import EmbeddedDocumentForm

class MessageForm(EmbeddedDocumentForm):
class Meta:
document = Message
embedded_field_name = 'messages'

fields = ['subject', 'sender', 'message',]

# views.py

# create a new embedded object
form = MessageForm(parent_document=some_document, ...)
# edit the 4th embedded object
form = MessageForm(parent_document=some_document, position=3, ...)

Documentation
-------------

In theory the documentation `Django's
modelform <https://docs.djangoproject.com/en/dev/topics/forms/modelforms/>`_
modelform <https://docs.djangoproject.com/en/dev/topics/forms/modelforms/>`__
documentation should be all you need (except for one exception; read
on). If you find a discrepancy between something that mongodbforms does
and what Django's documentation says, you have most likely found a bug.
Please `report
it <https://github.com/jschrewe/django-mongodbforms/issues>`_.
it <https://github.com/jschrewe/django-mongodbforms/issues>`__.

Form field generation
~~~~~~~~~~~~~~~~~~~~~

Because the fields on mongoengine documents have no notion of form
fields every mongodbform uses a generator class to generate the form
field for a db field, which is not explicitly set.
fields mongodbform uses a generator class to generate the form field for
a db field, which is not explicitly set.

To use your own field generator you can either set a generator for your
whole project using ``MONGODBFORMS_FIELDGENERATOR`` in settings.py or
you can use the ``formfield_generator`` option on the form's Meta class.

The default generator is defined in ``mongodbforms/fieldgenerator.py``
and should make it easy to override form fields and widgets. If you set
a generator on the document form you can also pass two dicts
``field_overrides`` and ``widget_overrides`` to ``__init__``. For a list
of valid keys have a look at ``MongoFormFieldGenerator``.

If you want to use your own generator class you can use the
``formfield_generator`` option on the form's Meta class.
.. code:: python

::
# settings.py

# set the fieldgeneretor for the whole application
MONGODBFORMS_FIELDGENERATOR = 'myproject.fieldgenerator.GeneratorClass'

# generator.py
from mongodbforms.fieldgenerator import MongoFormFieldGenerator

class MyFieldGenerator(MongoFormFieldGenerator):
...

# forms.py
from mongodbforms import DocumentForm

from generator import MyFieldGenerator

class MessageForm(DocumentForm):
class Meta:
formfield_generator = MyFieldGenerator
Expand Down
Loading