1 from django.core.management.base import NoArgsCommand
2 from optparse import make_option
4 from django.conf import settings
7 class Command(NoArgsCommand):
8 option_list = NoArgsCommand.option_list + (
9 make_option('--force', action='store_true', default=False, help='Force update of all files, even if the source files are older than the current compressed file.'),
11 help = 'Updates and compresses CSS and JavsScript on-demand, without restarting Django'
14 def handle_noargs(self, **options):
16 force = options.get('force', False)
17 verbosity = int(options.get('verbosity', 1))
19 from compress.utils import needs_update, filter_css, filter_js
21 for name, css in settings.COMPRESS_CSS.items():
22 u, version = needs_update(css['output_filename'],
23 css['source_filenames'])
25 if (force or u) or verbosity >= 2:
26 msg = 'CSS Group \'%s\'' % name
29 print "Version: %s" % version
32 filter_css(css, verbosity)
34 if (force or u) or verbosity >= 2:
37 for name, js in settings.COMPRESS_JS.items():
38 u, version = needs_update(js['output_filename'],
39 js['source_filenames'])
41 if (force or u) or verbosity >= 2:
42 msg = 'JavaScript Group \'%s\'' % name
45 print "Version: %s" % version
48 filter_js(js, verbosity)
50 if (force or u) or verbosity >= 2:
53 # Backwards compatibility for Django r9110
54 if not [opt for opt in Command.option_list if opt.dest == 'verbosity']:
55 Command.option_list += (
56 make_option('--verbosity', '-v', action="store", dest="verbosity",
57 default='1', type='choice', choices=['0', '1', '2'],
58 help="Verbosity level; 0=minimal output, 1=normal output, 2=all output"),