本文整理汇总了Python中moderation.diff.get_changes_between_models函数的典型用法代码示例。如果您正苦于以下问题:Python get_changes_between_models函数的具体用法?Python get_changes_between_models怎么用?Python get_changes_between_models使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_changes_between_models函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_view
def change_view(self, request, object_id, extra_context=None):
from moderation import moderation
moderated_object = ModeratedObject.objects.get(pk=object_id)
changed_object = moderated_object.changed_object
moderator = moderation.get_moderator(changed_object.__class__)
changes = get_changes_between_models(
moderated_object.get_object_for_this_type(),
changed_object,
moderator.fields_exclude).values()
if request.POST:
admin_form = self.get_form(request, moderated_object)(request.POST)
if admin_form.is_valid():
reason = admin_form.cleaned_data['moderation_reason']
if 'approve' in request.POST:
moderated_object.approve(request.user, reason)
elif 'reject' in request.POST:
moderated_object.reject(request.user, reason)
extra_context = {'changes': changes,
'django_version': django.get_version()[:3]}
return super(ModeratedObjectAdmin, self).change_view(request,
object_id,
extra_context)
示例2: test_date_field_in_model_object_should_be_unicode
def test_date_field_in_model_object_should_be_unicode(self):
'''Test if when model field value is not unicode, then when getting
changes between models, all changes should be unicode.
'''
changes = get_changes_between_models(self.obj1, self.obj2)
self.assertTrue(isinstance(changes['date'][0], unicode))
self.assertTrue(isinstance(changes['date'][1], unicode))
示例3: test_date_field_in_model_object_should_be_unicode
def test_date_field_in_model_object_should_be_unicode(self):
'''Test if when model field value is not unicode, then when getting
changes between models, all changes should be unicode.
'''
changes = get_changes_between_models(self.obj1, self.obj2)
date_change = changes['modelwithdatefield__date']
self.assertTrue(isinstance(date_change.change[0], str))
self.assertTrue(isinstance(date_change.change[1], str))
示例4: test_html_to_list_should_return_list
def test_html_to_list_should_return_list(self):
'''Test if changes dict generated from model that has non unicode field
is properly used by html_to_list function
'''
changes = get_changes_between_models(self.obj1, self.obj2)
changes_list1 = html_to_list(changes['date'][0])
changes_list2 = html_to_list(changes['date'][1])
self.assertTrue(isinstance(changes_list1, list))
self.assertTrue(isinstance(changes_list2, list))
示例5: test_get_changes_between_models
def test_get_changes_between_models(self):
self.profile.description = 'New description'
moderated_object = ModeratedObject(content_object=self.profile)
moderated_object.save()
self.profile = UserProfile.objects.get(user__username='moderator')
diff = get_changes_between_models(moderated_object.changed_object,
self.profile)
self.assertEqual(diff, {'description': ('New description',
u'Profile description')})
示例6: has_object_been_changed
def has_object_been_changed(self, original_obj, fields_exclude=None):
if fields_exclude is None:
fields_exclude = self.moderator.fields_exclude
changes = get_changes_between_models(original_obj,
self.changed_object,
fields_exclude)
for change in changes:
left_change, right_change = changes[change].change
if left_change != right_change:
return True
return False
示例7: test_get_changes_between_models_image
def test_get_changes_between_models_image(self):
'''Verify proper diff for ImageField fields'''
image1 = ModelWithImage(image='tmp/test1.jpg')
image1.save()
image2 = ModelWithImage(image='tmp/test2.jpg')
image2.save()
changes = get_changes_between_models(image1, image2)
self.assertEqual(norm_whitespace(changes['modelwithimage__image'].diff),
norm_whitespace(u'<img src="/media/tmp/test1.jpg"> '
u'<img style="margin-left: 10px;" '
u'src="/media/tmp/test2.jpg">'))
示例8: test_excluded_fields_should_be_excluded_from_changes
def test_excluded_fields_should_be_excluded_from_changes(self):
self.profile.description = 'New description'
moderated_object = ModeratedObject(content_object=self.profile)
moderated_object.save()
self.profile = UserProfile.objects.get(user__username='moderator')
changes = get_changes_between_models(moderated_object.changed_object,
self.profile, excludes=['description'])
self.assertEqual(unicode(changes),
u"{u'userprofile__url': Change object: "\
u"http://www.google.com - http://www.google.com}")
示例9: test_get_changes_between_models
def test_get_changes_between_models(self):
self.profile.description = 'New description'
moderated_object = ModeratedObject(content_object=self.profile)
moderated_object.save()
self.profile = UserProfile.objects.get(user__username='moderator')
changes = get_changes_between_models(moderated_object.changed_object,
self.profile)
self.assertEqual(unicode(changes),
u"{u'userprofile__url': Change object: http://www.google.com"\
u" - http://www.google.com, u'userprofile__description': "\
u"Change object: New description - Old description}")
示例10: change_view
def change_view(self, request, object_id, extra_context=None):
from moderation import moderation
moderated_object = ModeratedObject.objects.get(pk=object_id)
changed_obj = moderated_object.changed_object
moderator = moderation.get_moderator(changed_obj.__class__)
if moderator.visible_until_rejected:
old_object = changed_obj
new_object = moderated_object.get_object_for_this_type()
else:
old_object = moderated_object.get_object_for_this_type()
new_object = changed_obj
changes = get_changes_between_models(
old_object,
new_object,
moderator.fields_exclude).values()
if request.POST:
admin_form = self.get_form(request, moderated_object)(request.POST)
if admin_form.is_valid():
reason = admin_form.cleaned_data['moderation_reason']
if 'approve' in request.POST:
moderation_message = moderated_object.approve(request.user, reason)
messages.add_message(request, messages.INFO, moderation_message)
return self.response_change(request, new_object)
elif 'reject' in request.POST:
moderation_message = moderated_object.reject(request.user, reason)
messages.add_message(request, messages.INFO, moderation_message)
content_type = ContentType.objects.get_for_model(changed_obj.__class__)
try:
object_admin_url = urlresolvers.reverse("admin:%s_%s_change" %
(content_type.app_label,
content_type.model),
args=(changed_obj.pk,))
except urlresolvers.NoReverseMatch:
object_admin_url = None
extra_context = {'changes': changes,
'old_object': old_object,
'new_object': new_object,
'django_version': django.get_version()[:3],
'object_admin_url': object_admin_url}
return super(ModeratedObjectAdmin, self).change_view(request,
object_id,
extra_context)
示例11: test_get_changes_between_models_image
def test_get_changes_between_models_image(self):
'''Verify proper diff for ImageField fields'''
image1 = ModelWithImage(image='tmp/test1.jpg')
image1.save()
image2 = ModelWithImage(image='tmp/test2.jpg')
image2.save()
changes = get_changes_between_models(image1, image2)
self.assertEqual(
norm_whitespace(changes['modelwithimage__image'].diff),
norm_whitespace('<div class="img-wrapper"> '
'<img src="/media/tmp/test1.jpg"> '
'<img src="/media/tmp/test2.jpg"> '
'</div>'))
示例12: test_get_changes_between_models
def test_get_changes_between_models(self):
self.profile.description = 'New description'
moderated_object = ModeratedObject(content_object=self.profile)
moderated_object.save()
self.profile = UserProfile.objects.get(user__username='moderator')
changes = get_changes_between_models(moderated_object.changed_object,
self.profile)
self.assertIn(
"'userprofile__description': Change object: New description - "
"Old description", str(changes))
self.assertIn("'userprofile__user': Change object: 1 - 1",
str(changes))
self.assertIn(
"'userprofile__url': Change object: http://www.google.com - "
"http://www.google.com", str(changes))
示例13: test_foreign_key_changes
def test_foreign_key_changes(self):
self.profile.user = User.objects.get(username='admin')
moderated_object = ModeratedObject(content_object=self.profile)
moderated_object.save()
self.profile = UserProfile.objects.get(user__username='moderator')
changes = get_changes_between_models(moderated_object.changed_object,
self.profile)
self.assertIn("'userprofile__user': Change object: 4 - 1",
str(changes))
self.assertIn(
"'userprofile__description': Change object: Old description - Old "
"description",
str(changes))
self.assertIn("'userprofile__url': Change object: http://www"
".google.com - http://www.google.com", str(changes))
示例14: filter_moderated_objects
def filter_moderated_objects(self, query_set):
from moderation.models import MODERATION_STATUS_PENDING,\
MODERATION_STATUS_REJECTED
exclude_pks = []
for obj in query_set:
try:
changes = get_changes_between_models(
obj,
obj.moderated_object.changed_object)
if obj.moderated_object.moderation_status \
in [MODERATION_STATUS_PENDING,
MODERATION_STATUS_REJECTED] \
and not changes:
exclude_pks.append(obj.pk)
except ObjectDoesNotExist:
pass
return query_set.exclude(pk__in=exclude_pks)
示例15: change_view
def change_view(self, request, object_id, extra_context=None):
from moderation import moderation
moderated_object = ModeratedObject.objects.get(pk=object_id)
changed_object = moderated_object.changed_object
moderator = moderation.get_moderator(changed_object.__class__)
changes = get_changes_between_models(
moderated_object.get_object_for_this_type(), changed_object, moderator.fields_exclude
).values()
if request.POST:
admin_form = self.get_form(request, moderated_object)(request.POST)
if admin_form.is_valid():
reason = admin_form.cleaned_data["moderation_reason"]
if "approve" in request.POST:
moderated_object.approve(request.user, reason)
elif "reject" in request.POST:
moderated_object.reject(request.user, reason)
content_type = ContentType.objects.get_for_model(changed_object.__class__)
try:
object_admin_url = urlresolvers.reverse(
"admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(changed_object.pk,)
)
except urlresolvers.NoReverseMatch:
object_admin_url = None
extra_context = {
"changes": changes,
"django_version": django.get_version()[:3],
"object_admin_url": object_admin_url,
}
return super(ModeratedObjectAdmin, self).change_view(request, object_id, extra_context)