2018-05-18 14:40:38 -05:00
|
|
|
import sys
|
|
|
|
|
2023-06-21 03:48:29 -05:00
|
|
|
from django.conf import settings
|
2018-05-18 14:40:38 -05:00
|
|
|
from django.core.management.base import BaseCommand
|
2023-06-21 03:48:29 -05:00
|
|
|
from django.utils import translation
|
2018-05-18 14:40:38 -05:00
|
|
|
|
|
|
|
from umap.models import Map
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2023-06-21 03:48:29 -05:00
|
|
|
help = (
|
|
|
|
"Retrieve anonymous edit url of a map. "
|
|
|
|
"Eg.: python manage.py anonymous_edit_url 1234"
|
|
|
|
)
|
2018-05-18 14:40:38 -05:00
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2023-06-21 03:48:29 -05:00
|
|
|
parser.add_argument("pk", help="PK of the map to retrieve.")
|
|
|
|
parser.add_argument(
|
|
|
|
"--lang",
|
|
|
|
help="Language code to use in the URL.",
|
|
|
|
default=settings.LANGUAGE_CODE,
|
|
|
|
)
|
2018-05-18 14:40:38 -05:00
|
|
|
|
|
|
|
def abort(self, msg):
|
|
|
|
self.stderr.write(msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2023-06-21 03:48:29 -05:00
|
|
|
translation.activate(options["lang"])
|
|
|
|
pk = options["pk"]
|
2018-05-18 14:40:38 -05:00
|
|
|
try:
|
|
|
|
map_ = Map.objects.get(pk=pk)
|
|
|
|
except Map.DoesNotExist:
|
2023-06-21 03:48:29 -05:00
|
|
|
self.abort("Map with pk {} not found".format(pk))
|
2018-05-18 14:40:38 -05:00
|
|
|
if map_.owner:
|
2023-06-21 03:48:29 -05:00
|
|
|
self.abort("Map is not anonymous (owner: {})".format(map_.owner))
|
2023-05-31 09:30:07 -05:00
|
|
|
print(map_.get_anonymous_edit_url())
|