• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python diff.get_changes_between_models函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
开发者ID:ixc,项目名称:django-moderation,代码行数:27,代码来源:admin.py


示例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))
开发者ID:bx2,项目名称:django-moderation,代码行数:8,代码来源:test_diff.py


示例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))
开发者ID:Captainpopcorn10101,项目名称:django-moderation,代码行数:10,代码来源:diff.py


示例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))
开发者ID:bx2,项目名称:django-moderation,代码行数:11,代码来源:test_diff.py


示例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')})
开发者ID:bx2,项目名称:django-moderation,代码行数:12,代码来源:test_diff.py


示例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
开发者ID:EBNull,项目名称:django-moderation,代码行数:13,代码来源:models.py


示例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">'))
开发者ID:Inkvi,项目名称:django-moderation,代码行数:13,代码来源:diff.py


示例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}")
开发者ID:ixc,项目名称:django-moderation,代码行数:13,代码来源:diff.py


示例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}")
开发者ID:ixc,项目名称:django-moderation,代码行数:14,代码来源:diff.py


示例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)
开发者ID:marcin-koziol,项目名称:django-moderation,代码行数:50,代码来源:admin.py


示例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>'))
开发者ID:Captainpopcorn10101,项目名称:django-moderation,代码行数:15,代码来源:diff.py


示例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))
开发者ID:Captainpopcorn10101,项目名称:django-moderation,代码行数:18,代码来源:diff.py


示例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))
开发者ID:Captainpopcorn10101,项目名称:django-moderation,代码行数:18,代码来源:diff.py


示例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)
开发者ID:bx2,项目名称:django-moderation,代码行数:18,代码来源:managers.py


示例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)
开发者ID:jesselegg,项目名称:django-moderation,代码行数:36,代码来源:admin.py



注:本文中的moderation.diff.get_changes_between_models函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fields.SerializedObjectField类代码示例发布时间:2022-05-27
下一篇:
Python utils.get_translation_fields函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap