parent
bbf4b72e07
commit
48c27d56e4
1 changed files with 16 additions and 6 deletions
|
@ -1,27 +1,37 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.utils import translation
|
||||||
|
|
||||||
from umap.models import Map
|
from umap.models import Map
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = ('Retrieve anonymous edit url of a map. '
|
help = (
|
||||||
'Eg.: python manage.py anonymous_edit_url 1234')
|
"Retrieve anonymous edit url of a map. "
|
||||||
|
"Eg.: python manage.py anonymous_edit_url 1234"
|
||||||
|
)
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument('pk', help='PK of the map to retrieve.')
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
def abort(self, msg):
|
def abort(self, msg):
|
||||||
self.stderr.write(msg)
|
self.stderr.write(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
pk = options['pk']
|
translation.activate(options["lang"])
|
||||||
|
pk = options["pk"]
|
||||||
try:
|
try:
|
||||||
map_ = Map.objects.get(pk=pk)
|
map_ = Map.objects.get(pk=pk)
|
||||||
except Map.DoesNotExist:
|
except Map.DoesNotExist:
|
||||||
self.abort('Map with pk {} not found'.format(pk))
|
self.abort("Map with pk {} not found".format(pk))
|
||||||
if map_.owner:
|
if map_.owner:
|
||||||
self.abort('Map is not anonymous (owner: {})'.format(map_.owner))
|
self.abort("Map is not anonymous (owner: {})".format(map_.owner))
|
||||||
print(map_.get_anonymous_edit_url())
|
print(map_.get_anonymous_edit_url())
|
||||||
|
|
Loading…
Reference in a new issue