fixed MapUpdte logic to work without an existing map update
import logging
from django.core import management
-from django.core.exceptions import ObjectDoesNotExist
from django.core.management import BaseCommand
+from django.db import transaction
from c3nav.mapdata.management.commands import clearmapcache
@@ -18,7 +18,7 @@ class Command(BaseCommand):
from c3nav.control.models import UserPermissions
from c3nav.mapdata.models import MapUpdate
from c3nav.mapdata.models.access import AccessPermissionToken
- from c3nav.editor.models import ChangeSet, ChangeSetUpdate
+ from c3nav.editor.models import ChangeSet
from c3nav.site.models import Announcement
from django.contrib.auth import get_user_model
@@ -28,43 +28,23 @@ class Command(BaseCommand):
print("please add --yes to confirm that you really want to delete all users, changesets, and mapupdates")
return
- try:
+ with transaction.atomic():
ChangeSet.objects.all().delete()
logger.info('Deleted all ChangeSets')
- except ObjectDoesNotExist:
- pass
- try:
- # should not be necessary, but just to make sure
- ChangeSetUpdate.objects.all().delete()
- logger.info('Deleted all ChangeSetsUpdates')
- except ObjectDoesNotExist:
- pass
- try:
+
MapUpdate.objects.all().delete()
logger.info('Deleted all MapUpdates')
- except ObjectDoesNotExist:
- pass
- try:
AccessPermissionToken.objects.all().delete()
logger.info('Deleted all AccessPermissionTokens')
- except ObjectDoesNotExist:
- pass
- try:
+
Announcement.objects.filter(author__is_superuser=False).delete()
logger.info('Deleted all Announcements nor attached to a super user')
- except ObjectDoesNotExist:
- pass
- try:
+
UserPermissions.objects.filter(user__is_superuser=False).delete()
logger.info('Deleted all UserPermissions not attached to a super user')
- except ObjectDoesNotExist:
- pass
- try:
get_user_model().objects.filter(is_superuser=False).delete()
logger.info('Deleted all Users who are not a super user')
- except ObjectDoesNotExist:
- pass
management.call_command(clearmapcache.Command(), include_history=True, include_geometries=True)
