Permalink
Browse files

Made picklefield completely optional

  • Loading branch information...
1 parent 8a4faf7 commit bf521dfcbcebd3a0ca2ccebb2ca0f80a8cd10f22 @samluescher committed Jan 23, 2012
Showing with 15 additions and 26 deletions.
  1. +3 −4 form_designer/admin.py
  2. +9 −20 form_designer/models.py
  3. +3 −1 form_designer/settings.py
  4. +0 −1 requirements.txt
View
@@ -24,6 +24,7 @@ class FormDefinitionFieldInline(admin.StackedInline):
(_('Model Choices'), {'fields': ['choice_model', 'choice_model_empty_label']}),
]
+
class FormDefinitionAdmin(admin.ModelAdmin):
fieldsets = [
(_('Basic'), {'fields': ['name', 'require_hash', 'method', 'action', 'title', 'body']}),
@@ -38,6 +39,7 @@ class FormDefinitionAdmin(admin.ModelAdmin):
FormDefinitionFieldInline,
]
+
class FormLogAdmin(admin.ModelAdmin):
list_display = ('form_no_link', 'created', 'id', 'created_by', 'data_html')
list_filter = ('form_definition',)
@@ -109,9 +111,6 @@ def changelist_view(self, request, extra_context=None):
return super(FormLogAdmin, self).changelist_view(request, extra_context)
+
admin.site.register(FormDefinition, FormDefinitionAdmin)
admin.site.register(FormLog, FormLogAdmin)
-
-
-#admin.site.register(FormSubmission, admin.ModelAdmin)
-admin.site.register(FormValue, admin.ModelAdmin)
View
@@ -14,11 +14,8 @@
from form_designer.utils import get_class
from form_designer import settings
-try:
+if settings.VALUE_PICKLEFIELD:
from picklefield.fields import PickledObjectField
- PICKLEFIELD_INSTALLED = True
-except ImportError:
- PICKLEFIELD_INSTALLED = False
class FormValueDict(dict):
@@ -79,6 +76,7 @@ def get_absolute_url(self):
return ('form_designer.views.detail', [str(self.name)])
def get_form_data(self, form):
+ # TODO: refactor, move to utils or views
data = []
field_dict = self.get_field_dict()
form_keys = form.fields.keys()
@@ -92,13 +90,15 @@ def get_form_data(self, form):
return data
def get_form_data_context(self, form_data):
+ # TODO: refactor, move to utils
dict = {}
if form_data:
for field in form_data:
dict[field['name']] = field['value']
return dict
def compile_message(self, form_data, template=None):
+ # TODO: refactor, move to utils
from django.template.loader import get_template
from django.template import Context, Template
if template:
@@ -126,6 +126,7 @@ def log(self, form, user=None):
FormLog(form_definition=self, data=form_data, created_by=created_by).save()
def string_template_replace(self, text, context_dict):
+ # TODO: refactor, move to utils
from django.template import Context, Template, TemplateSyntaxError
try:
t = Template(text)
@@ -134,6 +135,7 @@ def string_template_replace(self, text, context_dict):
return text
def send_mail(self, form, files=[]):
+ # TODO: refactor, move to utils
form_data = self.get_form_data(form)
message = self.compile_message(form_data)
context_dict = self.get_form_data_context(form_data)
@@ -290,20 +292,6 @@ def __unicode__(self):
return self.label if self.label else self.name
-"""
-from picklefield.fields import PickledObjectField
-
-class FormLog(models.Model):
- created = models.DateTimeField(_('Created'), auto_now=True)
- form_definition = models.ForeignKey(FormDefinition, verbose_name=_('Form'))
- #data = PickledObjectField(_('Data'), null=True, blank=True)
-
- class Meta:
- verbose_name = _('Form log')
- verbose_name_plural = _('Form logs')
- ordering = ['-created']
-"""
-
class FormLog(models.Model):
form_definition = models.ForeignKey(FormDefinition, related_name='logs')
created = models.DateTimeField(_('Created'), auto_now=True)
@@ -373,13 +361,14 @@ def save(self, *args, **kwargs):
class FormValue(models.Model):
form_log = models.ForeignKey(FormLog, related_name='values')
field_name = models.SlugField(_('field name'), max_length=255)
- if PICKLEFIELD_INSTALLED:
+ if settings.VALUE_PICKLEFIELD:
# use PickledObjectField if available because it preserves the
# original data type
value = PickledObjectField(_('value'), null=True, blank=True)
else:
# otherwise just use a TextField, with the drawback that
- # all values will just be stored as unicode strings.
+ # all values will just be stored as unicode strings,
+ # but you can easily query the database for form results.
value = models.TextField(_('value'), null=True, blank=True)
def __unicode__(self):
@@ -85,4 +85,6 @@
'tif', 'tiff', 'ttf', 'txt', 'wav', 'wma', 'wmv', 'xls', 'xlsx', 'xml', 'zip'
))
-MAX_UPLOAD_SIZE = getattr(settings, 'MAX_UPLOAD_SIZE', 5242880) # 5M
+MAX_UPLOAD_SIZE = getattr(settings, 'MAX_UPLOAD_SIZE', 5242880) # 5M
+
+VALUE_PICKLEFIELD = getattr(settings, 'FORM_DESIGNER_VALUE_PICKLEFIELD', False)
View
@@ -1 +0,0 @@
-django-picklefield

0 comments on commit bf521df

Please sign in to comment.