28 lines
No EOL
984 B
Python
28 lines
No EOL
984 B
Python
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from core.models import Series, Code
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Get details for a code'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('code', type=str)
|
|
|
|
def handle(self, *args, **options):
|
|
splits = options["code"].split(":")
|
|
|
|
if (not splits[0] == "EXP") or len(splits) > 3:
|
|
self.stderr.write(self.style.WARNING(f'This is not a valid code.'))
|
|
return
|
|
|
|
if len(splits) == 2:
|
|
self.stderr.write(self.style.WARNING(f'This is not a complete code. It may be used literally.'))
|
|
return
|
|
|
|
series_id = options["code"].split(":")[1]
|
|
code_id = options["code"].split(":")[2]
|
|
|
|
series = Series.objects.get(id=series_id)
|
|
code = Code.objects.get(id=code_id, series=series)
|
|
|
|
self.stdout.write(self.style.SUCCESS(f'"{ code.title }" from series "{ series.title }" ({ series.description })')) |