1. Sergey Sorokin
  2. django-admin-tools

Commits

David Jean Louis  committed 728b946

make sure management commands work as expected

  • Participants
  • Parent commits 8118410
  • Branches default

Comments (0)

Files changed (2)

File admin_tools/dashboard/management/commands/customdashboard.py

View file
 DEFAULT_FILE = 'dashboard.py'
 
 class Command(BaseCommand):
-    option_list = BaseCommand.option_list + (
-        make_option(
-            '-f',
-            '--file',
-            help='The file path where the base code should be written (default: dashboard.py)',
-            default=DEFAULT_FILE,
-        ),
-    )
     help = ('Creates a template file containing the base code to get you '
             'started with your custom dashboard.')
-    args = '[appname]'
+    args = '[file]'
     label = 'application name'
 
-    def handle(self, appname=None, **options):
+    def handle(self, file=None, **options):
         context = {}
         context['project'] = os.path.basename(os.getcwd())
-        if appname:
-            tpl = 'dashboard/dashboard_app_index.txt'
-            if not os.path.exists(appname):
-                raise CommandError('application "%s" not found' % appname)
-            dst = os.path.join(appname, options['file'])
-            context['app'] = appname
-            if options['file'] != DEFAULT_FILE:
-                context['warning'] = True
-        else:
-            tpl = 'dashboard/dashboard.txt'
-            dst = os.path.join(options['file'])
+        tpl = 'dashboard/dashboard.txt'
+        dst = file is not None and file or DEFAULT_FILE
         if os.path.exists(dst):
             raise CommandError('file "%s" already exists' % dst)
         context['file'] = os.path.basename(dst).split('.')[0]
         open(dst, 'w').write(render_to_string(tpl, context))
-        print '"%s" written.' % os.path.join(options['file'])
+        print '"%s" written.' % os.path.join(dst)
 

File admin_tools/menu/management/commands/custommenu.py

View file
 from django.template.loader import render_to_string
 
 
+DEFAULT_FILE = 'menu.py'
+
 class Command(BaseCommand):
-    option_list = BaseCommand.option_list + (
-        make_option(
-            '-f',
-            '--file',
-            help='The file path where the base code should be written (default: menu.py)',
-            default='menu.py',
-        ),
-    )
     help = ('Creates a template file containing the base code to get you '
             'started with your custom menu')
+    args = ['file']
 
-    def handle(self, **options):
+    def handle(self, file=None, **options):
         project_name = os.path.basename(os.getcwd())
-        dst = os.path.join(options['file'])
+        dst = file is not None and file or DEFAULT_FILE
         if os.path.exists(dst):
             raise CommandError('Error: file "%s" already exists' % dst)
         open(dst, 'w').write(render_to_string('menu/menu.txt', {
             'project': project_name,
-            'file': os.path.basename(options['file']).split('.')[0]
+            'file': os.path.basename(dst).split('.')[0]
         }))
-        print '"%s" written.' % os.path.join(options['file'])
+        print '"%s" written.' % os.path.join(dst)