Skip to content

Commit

Permalink
Fix keyOrder when adding form field that are not in the mandatory par…
Browse files Browse the repository at this point in the history
…ams list
  • Loading branch information
Rémy HUBSCHER committed Jan 29, 2013
1 parent 79c2fb5 commit 603066a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
.*.swp

# Buildout files.
.mr.developer.cfg
.mr.developer.cfg
.coverage
6 changes: 5 additions & 1 deletion mail_factory/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Try to import floppyforms
import floppyforms as forms

# If we can import it but we don't want to use it
if not 'floppyforms' in settings.INSTALLED_APPS:
raise ImportError

Expand Down Expand Up @@ -38,7 +39,10 @@ def __init__(self, *args, **kwargs):
if param not in self.fields:
self.fields[param] = self.get_field_for_param(param)

self.fields.keyOrder = self.mail.params
keyOrder = self.mail.params
keyOrder += [x for x in self.fields.keyOrder
if x not in self.mail.params]
self.fields.keyOrder = keyOrder

def get_field_for_param(self, param):
"""By default always return a CharField for a param."""
Expand Down
5 changes: 3 additions & 2 deletions mail_factory/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ class Meta:
mailform_class = CommentForm
mailform = mailform_class()

self.assertEqual(mailform.fields.keyOrder, ['content'])
self.assertEqual(mailform.fields.keyOrder, ['content', 'title'])
self.assertEqual(mailform.mail, CommentMail)
self.assertIn('content', mailform.fields)


class MailFactoryViewsTestCase(TestCase):
def setUp(self):
self.superuser = User.objects.create_superuser('newbie', None, '$ecret')
self.superuser = User.objects.create_superuser('newbie', None,
'$ecret')
self.client = Client()

def test_mail_list_view(self):
Expand Down

0 comments on commit 603066a

Please sign in to comment.