From 1b81b5defafecfe8f567853396ddbd177772adda Mon Sep 17 00:00:00 2001 From: Bruno Martin Date: Sun, 15 Apr 2018 17:34:02 -0300 Subject: [PATCH] create command to fix moderations after import layers --- .../commands/fix_moderation_after_imports.py | 32 +++++++++++++++++++ mapaguarani/core/moderator.py | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 mapaguarani/core/management/commands/fix_moderation_after_imports.py diff --git a/mapaguarani/core/management/commands/fix_moderation_after_imports.py b/mapaguarani/core/management/commands/fix_moderation_after_imports.py new file mode 100644 index 0000000..ffb4678 --- /dev/null +++ b/mapaguarani/core/management/commands/fix_moderation_after_imports.py @@ -0,0 +1,32 @@ +from django.core.management.base import BaseCommand, CommandError +from django.contrib.contenttypes.models import ContentType +from core.models import IndigenousLand, ArchaeologicalPlace, IndigenousVillage +from moderation.models import ModeratedObject + +from django.contrib.auth import get_user_model +User = get_user_model() + + +class Command(BaseCommand): + help = 'Create moderatedObjcts for imported objects.' + + def handle(self, *args, **options): + + admin = User.objects.get(username='admin') + def create_moderated_objects(queryset): + contetn_type = ContentType.objects.get_for_model(queryset[0]) + for imported_object in queryset: + moderated_obj = ModeratedObject.objects.filter(object_pk=imported_object.id, + content_type=contetn_type) + if not moderated_obj: + moderated_obj = ModeratedObject(object_pk=imported_object.id, + content_type=contetn_type) + moderated_obj.instance=imported_object + moderated_obj.save() + moderated_obj.automoderate(user=admin) + + create_moderated_objects(IndigenousLand.objects.all()) + create_moderated_objects(IndigenousVillage.objects.all()) + create_moderated_objects(ArchaeologicalPlace.objects.all()) + + self.stdout.write('Objetos ModeratedObject criados com sucesso!!!') diff --git a/mapaguarani/core/moderator.py b/mapaguarani/core/moderator.py index c7b8e55..17b42c6 100644 --- a/mapaguarani/core/moderator.py +++ b/mapaguarani/core/moderator.py @@ -14,6 +14,9 @@ class BaseModerator(GenericModerator): # message_template_moderator # subject_template_user # message_template_user + # Use these lines to run fix_moderation_after_imports + notify_moderator = False + notify_user = False def send(self, content_object, subject_template, message_template, recipient_list, extra_context=None):