Skip to content

Commit

Permalink
Merge branch 'WimpyAnalytics-1.9formsave13'
Browse files Browse the repository at this point in the history
  • Loading branch information
zsiciarz committed Jan 17, 2016
2 parents 1ed20d8 + dcc4f2e commit c6763ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions markitup/fields.py
Expand Up @@ -102,6 +102,12 @@ def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
return value.raw

def to_python(self, value):
if isinstance(value, Markup):
return value
else:
return super(MarkupField, self).to_python(value)

def deconstruct(self):
name, path, args, kwargs = super(MarkupField, self).deconstruct()
# Force add_rendered_field to False for migrations
Expand Down
24 changes: 24 additions & 0 deletions tests/tests.py
Expand Up @@ -149,6 +149,30 @@ def testAdminFormField(self):
AdminMarkItUpWidget)


class MarkupFieldFormSaveTests(TestCase):

def setUp(self):
self.data = {'title': 'example post', 'body': '**markdown**'}
self.form_class = modelform_factory(Post, fields=['title', 'body'])

def testFormCreate(self):
form = self.form_class(self.data)
form.save()

actual = Post.objects.get(title=self.data['title'])
self.assertEquals(actual.body.raw, self.data['body'])

def testFormUpdate(self):
existing = Post.objects.create(title=self.data['title'], body=self.data['body'])

update = {'title': 'New title', 'body': '**different markdown**'}
form = self.form_class(update, instance=existing)
form.save()

actual = Post.objects.get(title=update['title'])
self.assertEquals(actual.body.raw, update['body'])


class HiddenFieldFormTests(TestCase):
def setUp(self):
self.post = CallableDefault(body='[link](http://example.com) & "text"')
Expand Down

0 comments on commit c6763ea

Please sign in to comment.