File: count_queries_on_save.py

package info (click to toggle)
python-django-dynamic-fixture 4.0.1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 616 kB
  • sloc: python: 3,909; makefile: 237; sh: 6
file content (38 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

from optparse import make_option

from django.core.management.base import AppCommand
from queries.count_queries_on_save import CountQueriesOnSave


class Command(AppCommand):
    help = """
    Default Usage:
    manage.py count_queries_on_save
    manage.py count_queries_on_save --settings=my_settings

    = Specifying apps:
    manage.py count_queries_on_save [APP_NAMES]+
    Usage:
    manage.py count_queries_on_save app1 app2
    manage.py count_queries_on_save app1 app2
    
    = Skipping apps:
    manage.py count_queries_on_save --skip=[APP_NAME,]+
    Usage:
    manage.py count_queries_on_save --skip=app1
    manage.py count_queries_on_save --skip=app1,app2
    manage.py count_queries_on_save app1 app2 --skip=app2
    """
    args = '<app_name app_name ...> --skip=APP1,APP2'
    option_list = AppCommand.option_list + (
        make_option('--skip', '-s', dest='skip-apps', default='',
                    help='Skip applications. Separate application labels by commas.'),
    )

    def handle(self, *args, **options):
        script = CountQueriesOnSave()
        app_labels = args
        exclude_app_labels = options['skip-apps'].split(',')
        report = script.execute(app_labels, exclude_app_labels)
        report.export_csv(order_by_quantity_queries=True)