Permalink
Browse files

Added migration, minor fixes

  • Loading branch information...
1 parent d21b8fe commit f41092db95f487719cae1baa1025530f0f1d387c @samluescher committed Jan 21, 2012
View
@@ -39,7 +39,7 @@ class FormDefinitionAdmin(admin.ModelAdmin):
]
class FormLogAdmin(admin.ModelAdmin):
- list_display = ('form_no_link', 'created', 'id', 'data_html')
+ list_display = ('form_no_link', 'created', 'id', 'created_by', 'data_html')
list_filter = ('form_definition',)
list_display_links = ()
@@ -0,0 +1,153 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'FormValue'
+ db.create_table('form_designer_formvalue', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('form_log', self.gf('django.db.models.fields.related.ForeignKey')(related_name='values', to=orm['form_designer.FormLog'])),
+ ('field_name', self.gf('django.db.models.fields.SlugField')(max_length=255, db_index=True)),
+ ('value', self.gf('picklefield.fields.PickledObjectField')(null=True, blank=True)),
+ ))
+ db.send_create_signal('form_designer', ['FormValue'])
+
+ from form_designer.models import FormLog
+ for log in FormLog.objects.all():
+ log.set_data(log.data)
+ log.save()
+
+ # Deleting field 'FormLog.data'
+ db.delete_column('form_designer_formlog', 'data')
+
+ # Adding field 'FormLog.created_by'
+ db.add_column('form_designer_formlog', 'created_by', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'FormValue'
+ db.delete_table('form_designer_formvalue')
+
+ # Adding field 'FormLog.data'
+ db.add_column('form_designer_formlog', 'data', self.gf('picklefield.fields.PickledObjectField')(null=True, blank=True), keep_default=False)
+
+ # TODO: Since we can't access the data field because data is actually
+ # a property now, we cant convert formlog.values.all() back to pickled
+ # formlog.data
+
+ # Deleting field 'FormLog.created_by'
+ db.delete_column('form_designer_formlog', 'created_by_id')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'form_designer.formdefinition': {
+ 'Meta': {'object_name': 'FormDefinition'},
+ 'action': ('django.db.models.fields.URLField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'allow_get_initial': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'body': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'display_logged': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'error_message': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'form_template_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'log_data': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'mail_from': ('form_designer.fields.TemplateCharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'mail_subject': ('form_designer.fields.TemplateCharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'mail_to': ('form_designer.fields.TemplateCharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'mail_uploaded_files': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'message_template': ('form_designer.fields.TemplateTextField', [], {'null': 'True', 'blank': 'True'}),
+ 'method': ('django.db.models.fields.CharField', [], {'default': "'POST'", 'max_length': '10'}),
+ 'name': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
+ 'private_hash': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '40'}),
+ 'public_hash': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '40'}),
+ 'require_hash': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'save_uploaded_files': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'submit_label': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'success_clear': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'success_message': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'success_redirect': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'form_designer.formdefinitionfield': {
+ 'Meta': {'ordering': "['position']", 'object_name': 'FormDefinitionField'},
+ 'choice_labels': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'choice_model': ('form_designer.fields.ModelNameField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'choice_model_empty_label': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'choice_values': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'decimal_places': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'field_class': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+ 'form_definition': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['form_designer.FormDefinition']"}),
+ 'help_text': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'include_result': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'initial': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'max_digits': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'max_length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'max_value': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+ 'min_length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'min_value': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'regex': ('form_designer.fields.RegexpExpressionField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'required': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'widget': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'form_designer.formlog': {
+ 'Meta': {'object_name': 'FormLog'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'created_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'form_definition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'logs'", 'to': "orm['form_designer.FormDefinition']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'form_designer.formvalue': {
+ 'Meta': {'object_name': 'FormValue'},
+ 'field_name': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}),
+ 'form_log': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'values'", 'to': "orm['form_designer.FormLog']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'value': ('picklefield.fields.PickledObjectField', [], {'null': 'True', 'blank': 'True'})
+ }
+ }
+
+ complete_apps = ['form_designer']
View
@@ -113,9 +113,12 @@ def count_fields(self):
def __unicode__(self):
return self.title or self.name
- def log(self, form):
+ def log(self, form, user=None):
form_data = self.get_form_data(form)
- FormLog(form_definition=self, data=form_data).save()
+ created_by = None
+ if user and user.is_authenticated():
+ created_by = user
+ FormLog(form_definition=self, data=form_data, created_by=created_by).save()
def string_template_replace(self, text, context_dict):
from django.template import Context, Template, TemplateSyntaxError
@@ -300,7 +303,7 @@ class Meta:
class FormLog(models.Model):
form_definition = models.ForeignKey(FormDefinition, related_name='logs')
created = models.DateTimeField(_('Created'), auto_now=True)
- created_by = models.ForeignKey(User, null=True)
+ created_by = models.ForeignKey(User, null=True, blank=True)
_data = None
def __unicode__(self):
@@ -309,6 +312,7 @@ def __unicode__(self):
def get_data(self):
if self._data:
+ # before instance is saved
return self._data
data = []
for item in self.values.all():
@@ -319,13 +323,18 @@ def get_data(self):
return data
def set_data(self, form_data):
+ # keep form data in temporary variable since instance must
+ # be saved before saving values
self._data = form_data
data = property(get_data, set_data)
def save(self, *args, **kwargs):
super(FormLog, self).save(*args, **kwargs)
if self._data:
+ # safe form data and then clear temporary variable
+ for value in self.values.all():
+ value.delete()
for item in self._data:
value = FormValue()
value.field_name = item['name']
View
@@ -40,7 +40,7 @@ def process_form(request, form_definition, extra_context={}, disable_redirection
messages.success(request, success_message)
form_success = True
if form_definition.log_data:
- form_definition.log(form)
+ form_definition.log(form, request.user)
if form_definition.mail_to:
form_definition.send_mail(form, files)
if form_definition.success_redirect and not disable_redirection:
View
@@ -0,0 +1 @@
+django-picklefield

0 comments on commit f41092d

Please sign in to comment.