Skip to content

Commit

Permalink
create command to fix moderations after import layers
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosmartin committed Apr 15, 2018
1 parent 3869a8b commit 1b81b5d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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!!!')
3 changes: 3 additions & 0 deletions mapaguarani/core/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1b81b5d

Please sign in to comment.