src/cm/management/commands/set_workspacename.py
changeset 142 9b3438382e53
parent 141 3acc965253e2
equal deleted inserted replaced
141:3acc965253e2 142:9b3438382e53
     1 from django.core.management.base import LabelCommand, CommandError
     1 from django.core.management.base import LabelCommand, CommandError, BaseCommand, make_option
       
     2 from base64 import b64decode
     2 
     3 
     3 class Command(LabelCommand):
     4 class Command(LabelCommand):
       
     5     option_list = BaseCommand.option_list + (
       
     6         make_option('--base64', action='store_true', dest='base64', default=False,
       
     7             help='Assume all input are base64 encoded.'),
       
     8     )
       
     9     
     4     help = "Change workspace name"
    10     help = "Change workspace name"
     5 
    11 
     6     def handle(self, *labels, **options):
    12     def handle(self, *labels, **options):
     7         if len(labels)!=1:
    13         if len(labels)!=1:
     8             raise CommandError('Enter workspace name')
    14             raise CommandError('Enter workspace name')
     9         name = labels[0]
    15         base64 = options.get('base64')
    10         from cm.models import Configuration
    16         if base64:
    11         Configuration.objects.set_workspace_name(name.decode('utf8'))        
    17             name = b64decode(labels[0])
       
    18         else:
       
    19             name = labels[0]
       
    20         name = name.decode('utf8')
       
    21         
       
    22         from cm.models import Configuration        
       
    23         Configuration.objects.set_workspace_name(name)