-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create command to fix moderations after import layers
- Loading branch information
1 parent
3869a8b
commit 1b81b5d
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
mapaguarani/core/management/commands/fix_moderation_after_imports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters