Project

General

Profile

Download (1.49 KB) Statistics
| Branch: | Tag: | Revision:

root / entrouvert / djommon / multitenant / management / commands / tenant_command.py @ 1db4b242

1
# this file derive from django-tenant-schemas
2
#   Author: Bernardo Pires Carneiro
3
#   Email: carneiro.be@gmail.com
4
#   License: MIT license
5
#   Home-page: http://github.com/bcarneiro/django-tenant-schemas
6
from optparse import make_option
7
from django.core.management.base import BaseCommand, CommandError
8
from django.core.management import call_command, get_commands, load_command_class
9
from django.db import connection
10
from entrouvert.djommon.multitenant.management.commands import InteractiveTenantOption
11

    
12

    
13
class Command(InteractiveTenantOption, BaseCommand):
14
    help = "Wrapper around django commands for use with an individual tenant"
15

    
16
    def run_from_argv(self, argv):
17
        """
18
        Changes the option_list to use the options from the wrapped command.
19
        Adds schema parameter to specifiy which schema will be used when
20
        executing the wrapped command.
21
        """
22
        # load the command object.
23
        try:
24
            app_name = get_commands()[argv[2]]
25
        except KeyError:
26
            raise CommandError("Unknown command: %r" % argv[2])
27

    
28
        if isinstance(app_name, BaseCommand):
29
            # if the command is already loaded, use it directly.
30
            klass = app_name
31
        else:
32
            klass = load_command_class(app_name, argv[2])
33

    
34
        super(Command, self).run_from_argv(argv)
35

    
36
    def handle(self, *args, **options):
37
        tenant = self.get_tenant_from_options_or_interactive(**options)
38
        connection.set_tenant(tenant)
39

    
40
        call_command(*args, **options)
(12-12/12)