当前位置: 首页>>代码示例>>Python>>正文


Python ModeratedObject.changed_object方法代码示例

本文整理汇总了Python中moderation.models.ModeratedObject.changed_object方法的典型用法代码示例。如果您正苦于以下问题:Python ModeratedObject.changed_object方法的具体用法?Python ModeratedObject.changed_object怎么用?Python ModeratedObject.changed_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moderation.models.ModeratedObject的用法示例。


在下文中一共展示了ModeratedObject.changed_object方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_save_handler

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
    def post_save_handler(self, sender, instance, **kwargs):
        """
        Creates new moderation object if instance is created,
        If instance exists and is only updated then save instance as
        content_object of moderated_object
        """
        # check if object was loaded from fixture, bypass moderation if so

        if kwargs['raw']:
            return

        pk = instance.pk
        moderator = self.get_moderator(sender)

        if kwargs['created']:
            old_object = sender._default_manager.get(pk=pk)
            moderated_obj = ModeratedObject(content_object=old_object)
            if not moderator.visible_until_rejected:
                # Hide it by placing in draft state
                moderated_obj.moderation_state = MODERATION_DRAFT_STATE
            moderated_obj.save()
            moderator.inform_moderator(instance)
            return

        moderated_obj = ModeratedObject.objects.get_for_instance(instance)

        if (moderated_obj.moderation_status == MODERATION_STATUS_APPROVED and
                moderator.bypass_moderation_after_approval):
            # save new data in moderated object
            moderated_obj.changed_object = instance
            moderated_obj.save()
            return

        if moderated_obj.has_object_been_changed(instance):
            copied_instance = self._copy_model_instance(instance)

            if not moderator.visible_until_rejected:
                # Save instance with old data from changed_object, undoing
                # the changes that save() just saved to the database.
                moderated_obj.changed_object.save_base(raw=True)

                # Save the new data in moderated_object, so it will be applied
                # to the real record when the moderator approves the change.
                moderated_obj.changed_object = copied_instance

            moderated_obj.moderation_status = MODERATION_STATUS_PENDING
            moderated_obj.save()
            moderator.inform_moderator(instance)
            instance._moderated_object = moderated_obj
开发者ID:aptivate,项目名称:django-moderation,代码行数:51,代码来源:register.py

示例2: _get_or_create_moderated_object

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
    def _get_or_create_moderated_object(self, instance, unchanged_obj):
        """
        Get or create ModeratedObject instance.
        If moderated object is not equal instance then serialize unchanged
        in moderated object in order to use it later in post_save_handler
        """
        try:
            moderated_object\
             = ModeratedObject.objects.get_for_instance(instance)

        except ObjectDoesNotExist:
            moderated_object = ModeratedObject(content_object=unchanged_obj)
            moderated_object.changed_object = unchanged_obj

        else:
            if moderated_object.has_object_been_changed(instance):
                moderated_object.changed_object = unchanged_obj

        return moderated_object
开发者ID:jesselegg,项目名称:django-moderation,代码行数:21,代码来源:register.py

示例3: test_deserialzed_object

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
    def test_deserialzed_object(self):
        moderated_object = ModeratedObject(content_object=self.profile)
        self.profile.description = "New description"
        moderated_object.changed_object = self.profile
        moderated_object.save()
        pk = moderated_object.pk

        moderated_object = ModeratedObject.objects.get(pk=pk)

        self.assertEqual(moderated_object.changed_object.description, "New description")

        self.assertEqual(moderated_object.content_object.description, u"Old description")
开发者ID:nickburns2006,项目名称:django-moderation,代码行数:14,代码来源:models.py

示例4: test_change_of_deserialzed_object

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
    def test_change_of_deserialzed_object(self):
        self.profile.description = 'New description'
        moderated_object = ModeratedObject(content_object=self.profile)
        moderated_object.save()
        pk = moderated_object.pk

        self.profile.description = 'New changed description'
        moderated_object.changed_object = self.profile.description
        moderated_object.save()

        moderated_object = ModeratedObject.objects.get(pk=pk)

        self.assertEqual(moderated_object.changed_object.description,
                         'New changed description')
开发者ID:EBNull,项目名称:django-moderation,代码行数:16,代码来源:models.py

示例5: post_save_handler

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
    def post_save_handler(self, sender, instance, **kwargs):
        """
        Creates new moderation object if instance is created,
        If instance exists and is only updated then save instance as
        content_object of moderated_object
        """
        #check if object was loaded from fixture, bypass moderation if so

        if kwargs['raw']:
            return
        
        pk = instance.pk
        moderator = self.get_moderator(sender)

        if kwargs['created']:
            old_object = sender._default_manager.get(pk=pk)
            moderated_obj = ModeratedObject(content_object=old_object)
            moderated_obj.save()
            if instance.author and not moderator.is_auto_approve(instance, instance.author):
                moderator.inform_moderator(instance)
        else:
            
            moderated_obj \
             = ModeratedObject.objects.get_for_instance(instance)
             
            if moderated_obj.moderation_status == MODERATION_STATUS_APPROVED\
               and moderator.bypass_moderation_after_approval:
                return

            if moderated_obj.has_object_been_changed(instance):
                copied_instance = self._copy_model_instance(instance)

                if not moderator.visible_until_rejected:
                    # save instance with data from changed_object
                    moderated_obj.changed_object.save_base(raw=True)

                    # save new data in moderated object
                    moderated_obj.changed_object = copied_instance

                moderated_obj.moderation_status = MODERATION_STATUS_PENDING
                moderated_obj.moderation_reason = None
                moderated_obj.save()
                if moderated_obj.changed_by and not moderator.is_auto_approve(instance, moderated_obj.changed_by):
                    moderator.inform_moderator(instance)
                instance._moderated_object = moderated_obj
开发者ID:cosi1,项目名称:django-moderation,代码行数:47,代码来源:register.py

示例6: get_new_instance

# 需要导入模块: from moderation.models import ModeratedObject [as 别名]
# 或者: from moderation.models.ModeratedObject import changed_object [as 别名]
 def get_new_instance(unchanged_obj):
     moderated_object = ModeratedObject(content_object=unchanged_obj)
     moderated_object.changed_object = unchanged_obj
     return moderated_object
开发者ID:aptivate,项目名称:django-moderation,代码行数:6,代码来源:register.py


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