Skip to content

Commit 911942d

Browse files
author
Jan Schrewe
committed
setup.py generates a README.txt for pypi if pandoc is installed.
1 parent 9b74fc4 commit 911942d

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.pyc
22
.pydevproject
33
.project
4-
*~
4+
*~
5+
dist/*
6+
MANIFEST

README.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
django mongodbforms
2+
===================
3+
4+
This is an implementation of django's model forms for mongoengine
5+
documents.
6+
7+
Requirements
8+
------------
9+
10+
- `mongoengine <http://mongoengine.org/>`_
11+
12+
Usage
13+
-----
14+
15+
mongodbforms supports forms for normal documents and embedded documents.
16+
17+
Normal documents
18+
~~~~~~~~~~~~~~~~
19+
20+
To use mongodbforms with normal documents replace djangos forms with
21+
mongodbform forms.
22+
23+
::
24+
25+
from mongodbforms import DocumentForm
26+
27+
class BlogForm(DocumentForm)
28+
...
29+
30+
Embedded documents
31+
~~~~~~~~~~~~~~~~~~
32+
33+
For embedded documents use ``EmbeddedDocumentForm``. The Meta-object of
34+
the form has to be provided with an embedded field name. The embedded
35+
object is appended to this. The form constructor takes an additional
36+
argument: The document the embedded document gets added to.
37+
38+
If the form is saved the new embedded object is automatically added to
39+
the provided parent document. If the embedded field is a list field the
40+
embedded document is appended to the list, if it is a plain embedded
41+
field the current object is overwritten. Note that the parent document
42+
is not saved.
43+
44+
::
45+
46+
# forms.py
47+
from mongodbforms import EmbeddedDocumentForm
48+
49+
class MessageForm(EmbeddedDocumentForm):
50+
class Meta:
51+
document = Message
52+
embedded_field_name = 'messages'
53+
54+
fields = ['subject', 'sender', 'message',]
55+
56+
# views.py
57+
form = MessageForm(parent_document=some_document, ...)
58+
59+
Documentation
60+
-------------
61+
62+
In theory the documentation `Django's
63+
modelform <https://docs.djangoproject.com/en/dev/topics/forms/modelforms/>`_
64+
documentation should be all you need (except for one exception; read
65+
on). If you find a discrepancy between something that mongodbforms does
66+
and what Django's documentation says, you have most likely found a bug.
67+
Please `report
68+
it <https://github.com/jschrewe/django-mongodbforms/issues>`_.
69+
70+
Form field generation
71+
~~~~~~~~~~~~~~~~~~~~~
72+
73+
Because the fields on mongoengine documents have no notion of form
74+
fields every mongodbform uses a generator class to generate the form
75+
field for a db field, which is not explicitly set.
76+
77+
If you want to use your own generator class you can use the
78+
``formfield_generator`` option on the form's Meta class.
79+
80+
::
81+
82+
# generator.py
83+
from mongodbforms.fieldgenerator import MongoFormFieldGenerator
84+
85+
class MyFieldGenerator(MongoFormFieldGenerator):
86+
...
87+
88+
# forms.py
89+
from mongodbforms import DocumentForm
90+
91+
from generator import MyFieldGenerator
92+
93+
class MessageForm(DocumentForm):
94+
class Meta:
95+
formfield_generator = MyFieldGenerator
96+

setup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env python
22

33
from distutils.core import setup
4+
from subprocess import call
5+
6+
def convert_readme():
7+
try:
8+
call(["pandoc", "-t", "rst", "-o", "README.txt", "readme.md"])
9+
except OSError:
10+
pass
11+
return open('README.txt').read()
412

513
setup(name='mongodbforms',
614
version='0.1.3',
@@ -12,5 +20,5 @@
1220
package_data={
1321
},
1422
license='New BSD License',
15-
long_description=open('readme.md').read(),
23+
long_description=convert_readme(),
1624
)

0 commit comments

Comments
 (0)