~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/core/management/commands/check.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
1
2
from __future__ import unicode_literals
2
 
import warnings
3
 
 
4
 
from django.core.checks.compatibility.base import check_compatibility
5
 
from django.core.management.base import NoArgsCommand
6
 
 
7
 
 
8
 
class Command(NoArgsCommand):
9
 
    help = "Checks your configuration's compatibility with this version " + \
10
 
           "of Django."
11
 
 
12
 
    def handle_noargs(self, **options):
13
 
        for message in check_compatibility():
14
 
            warnings.warn(message)
 
3
 
 
4
from optparse import make_option
 
5
 
 
6
from django.apps import apps
 
7
from django.core import checks
 
8
from django.core.checks.registry import registry
 
9
from django.core.management.base import BaseCommand, CommandError
 
10
 
 
11
 
 
12
class Command(BaseCommand):
 
13
    help = "Checks the entire Django project for potential problems."
 
14
 
 
15
    requires_system_checks = False
 
16
 
 
17
    option_list = BaseCommand.option_list + (
 
18
        make_option('--tag', '-t', action='append', dest='tags',
 
19
            help='Run only checks labeled with given tag.'),
 
20
        make_option('--list-tags', action='store_true', dest='list_tags',
 
21
            help='List available tags.'),
 
22
    )
 
23
 
 
24
    def handle(self, *app_labels, **options):
 
25
        if options.get('list_tags'):
 
26
            self.stdout.write('\n'.join(sorted(registry.tags_available())))
 
27
            return
 
28
 
 
29
        if app_labels:
 
30
            app_configs = [apps.get_app_config(app_label) for app_label in app_labels]
 
31
        else:
 
32
            app_configs = None
 
33
 
 
34
        tags = options.get('tags', None)
 
35
        if tags and any(not checks.tag_exists(tag) for tag in tags):
 
36
            invalid_tag = next(tag for tag in tags if not checks.tag_exists(tag))
 
37
            raise CommandError('There is no system check with the "%s" tag.' % invalid_tag)
 
38
 
 
39
        self.check(app_configs=app_configs, tags=tags, display_num_errors=True)