Skip to content

Commit

Permalink
Merge branch 'add-revisions'
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed May 17, 2012
2 parents 3f28300 + 02a77dc commit 3e39d17
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wysiwyg_forms/models.py
Expand Up @@ -3,6 +3,8 @@
except ImportError:
import simplejson as json

from uuid import uuid4

from django.db import models
from django import forms
from django.template.defaultfilters import slugify
Expand All @@ -17,6 +19,7 @@
class Form(models.Model):
slug = models.SlugField(editable=False)
name = models.CharField(max_length=250)
revision = models.CharField(max_length=250, editable=False)
description = models.TextField()

def __unicode__(self):
Expand Down Expand Up @@ -59,6 +62,17 @@ def save(self, *args, **kwargs):
self.slug = slugify(self.name).replace("-", "_")[:50]
for field in self.fields:
field.save()

if self.revision:
# Incremement the revision number and generate a new revision hash
rev_number, rev_hash = self.revision.split("-")
rev_number += 1
rev_hash = uuid4().hex
self.revision = "%d-%s" % (rev_number, rev_hash)
else:
# Initial revision
self.revision = "0-%s" % uuid4().hex

super(Form, self).save(*args, **kwargs)

def as_django_form(self):
Expand Down

0 comments on commit 3e39d17

Please sign in to comment.