Beispiel #1
0
    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)
    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)
Beispiel #3
0
    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 = list(
            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:
                    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_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,
            'django_version': django.get_version()[:3],
            'object_admin_url': object_admin_url
        }
        return super(ModeratedObjectAdmin,
                     self).change_view(request,
                                       object_id,
                                       extra_context=extra_context)
Beispiel #4
0
    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)
Beispiel #5
0
    def moderator(self):
        from moderation import moderation

        model_class = self.content_object.__class__

        return moderation.get_moderator(model_class)
Beispiel #6
0
    def moderator(self):
        from moderation import moderation

        return moderation.get_moderator(self.model)
Beispiel #7
0
    def change_view(self, request, object_id, extra_context=None):
        """
        Copied and pasted from the base class as I needed to override
        extra_context

        And the class hasn't been sublclassed properly to allow that.
        """
        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 = list(
            get_changes_between_models(
                old_object,
                new_object,
                moderator.fields_exclude,
                resolve_foreignkeys=moderator.resolve_foreignkeys).values())

        if request.POST:
            admin_form = self.get_form(request, moderated_object)(request.POST)

            if admin_form.is_valid():
                reason = admin_form.cleaned_data['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_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

        # This is the only bit of code overridden.
        try:
            preview_links = self.get_pdf_links(moderated_object)
        except BaseException:
            preview_links = None

        extra_context = {
            'changes': changes,
            'django_version': django.get_version()[:3],
            'object_admin_url': object_admin_url,
            # This is the only bit of code overridden
            'preview': preview_links
        }

        return super(ModeratedObjectAdmin,
                     self).change_view(request,
                                       object_id,
                                       extra_context=extra_context)
Beispiel #8
0
    def moderator(self):
        from moderation import moderation

        return moderation.get_moderator(self.model)
Beispiel #9
0
    def moderator(self):
        from moderation import moderation

        model_class = self.content_object.__class__

        return moderation.get_moderator(model_class)