Skip to content

Commit e384b41

Browse files
author
Jan Schrewe
committed
Fixes issue jschrewe#5 and adds a default form field generator to the form meta.
1 parent f99273f commit e384b41

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Mon Jan 23 16:54:50 CET 2012
2+
eclipse.preferences.version=1
3+
encoding//mongodbforms/fieldgenerator.py=utf-8
4+
encoding//mongodbforms/fields.py=utf-8

mongodbforms/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from django.forms.fields import *
22
from documents import *
3+
from fieldgenerator import *
4+
from util import *

mongodbforms/documents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def __init__(self, options=None):
203203
self.exclude = getattr(options, 'exclude', None)
204204
self.widgets = getattr(options, 'widgets', None)
205205
self.embedded_field = getattr(options, 'embedded_field_name', None)
206-
self.formfield_generator = getattr(options, 'formfield_generator', None)
206+
self.formfield_generator = getattr(options, 'formfield_generator', MongoDefaultFormFieldGenerator)
207207

208208

209209
class DocumentFormMetaclass(type):
@@ -418,8 +418,8 @@ def save(self, commit=True):
418418
fail_message = 'created'
419419
else:
420420
fail_message = 'changed'
421-
except KeyError:
422-
fail_message = 'embedded docuement saved'
421+
except (KeyError, AttributeError):
422+
fail_message = 'embedded document saved'
423423
obj = save_instance(self, self.instance, self._meta.fields,
424424
fail_message, commit, construct=False)
425425

mongodbforms/fieldgenerator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""
24
Based on django mongotools (https://github.com/wpjunior/django-mongotools) by
35
Wilson Júnior (wilsonpjunior@gmail.com).
@@ -247,7 +249,7 @@ def generate(self, field, **kwargs):
247249
can be found.
248250
"""
249251
try:
250-
return super(MongoFormFieldGenerator, self).generate(field, **kwargs)
252+
return super(MongoDefaultFormFieldGenerator, self).generate(field, **kwargs)
251253
except NotImplementedError:
252254
# a normal charfield is always a good guess
253255
# for a widget.

mongodbforms/fields.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""
24
Based on django mongotools (https://github.com/wpjunior/django-mongotools) by
35
Wilson Júnior (wilsonpjunior@gmail.com).
@@ -8,6 +10,7 @@
810
from pymongo.errors import InvalidId
911
from pymongo.objectid import ObjectId
1012
from django.utils.encoding import smart_unicode, force_unicode
13+
from django.utils.translation import ugettext_lazy as _
1114

1215
class MongoChoiceIterator(object):
1316
def __init__(self, field):

0 commit comments

Comments
 (0)