Permalink
Browse files

Merge pull request #59 from marcin-koziol/field_conversion_fix

Field conversion fix. Closes #58 Thx Daniel :)
  • Loading branch information...
2 parents ff833f9 + d8a5bea commit 883ae15f4afa4998899a6dc0e1f4f9706e204225 @dominno committed Feb 24, 2012
Showing with 24 additions and 9 deletions.
  1. +2 −2 src/moderation/forms.py
  2. +12 −2 src/moderation/tests/unit/forms.py
  3. +10 −5 src/moderation/tests/unit/utils.py
@@ -1,4 +1,4 @@
-from django.forms.models import ModelForm
+from django.forms.models import ModelForm, model_to_dict
from moderation.models import MODERATION_STATUS_PENDING,\
MODERATION_STATUS_REJECTED
from django.core.exceptions import ObjectDoesNotExist
@@ -16,7 +16,7 @@ def __init__(self, *args, **kwargs):
not instance.moderated_object.moderator.\
visible_until_rejected:
initial =\
- instance.moderated_object.changed_object.__dict__
+ model_to_dict(instance.moderated_object.changed_object)
kwargs.setdefault('initial', {})
kwargs['initial'].update(initial)
except ObjectDoesNotExist:
@@ -1,4 +1,5 @@
-from moderation.tests.apps.test_app1.models import UserProfile
+from django.db.models.fields.files import ImageFieldFile
+from moderation.tests.apps.test_app1.models import UserProfile, ModelWithImage
from django.forms import CharField
from moderation.forms import BaseModeratedObjectForm
from moderation.register import ModerationManager
@@ -21,7 +22,7 @@ class Meta:
model = UserProfile
self.ModeratedObjectForm = ModeratedObjectForm
- self.moderation = setup_moderation([UserProfile])
+ self.moderation = setup_moderation([UserProfile, ModelWithImage])
def tearDown(self):
teardown_moderation()
@@ -57,6 +58,15 @@ def test_if_form_is_initialized_existing_object(self):
self.assertEqual(profile.description, u"old description")
self.assertEqual(form.initial['description'], u'Changed description')
+ def test_if_form_has_image_field_instance_of_image_field_file(self):
+ object = ModelWithImage(image='my_image.jpg')
+ object.save()
+
+ object = ModelWithImage.unmoderated_objects.get(id=1)
+ form = self.ModeratedObjectForm(instance=object)
+ self.assertTrue(isinstance(form.initial['image'], ImageFieldFile),
+ 'image in form.initial is instance of ImageField File')
+
def test_form_when_obj_has_no_moderated_obj(self):
self.moderation.unregister(UserProfile)
profile = UserProfile(description="old description",
@@ -23,11 +23,16 @@ class PEP8TestCase(unittest.TestCase):
def test_pep8_rules(self):
import subprocess
-
- p = subprocess.Popen(
- ['pep8', '--filename=*.py', '--show-source', '--show-pep8',
- '--ignore=W291', '--exclude=migrations', moderation.__path__[0]],
- stdout=subprocess.PIPE)
+ try:
+ p = subprocess.Popen(
+ ['pep8', '--filename=*.py', '--show-source', '--show-pep8',
+ '--ignore=W291', '--exclude=migrations',
+ moderation.__path__[0]], stdout=subprocess.PIPE)
+ except OSError, e:
+ self.assertNotEqual(e.errno, 2,
+ "pep8 command is missing. "
+ "You can install it with easy_install pep8")
+ raise
out, err = p.communicate()
self.assertEqual(out, "",

0 comments on commit 883ae15

Please sign in to comment.