Package ajango :: Package database
[hide private]
[frames] | no frames]

Source Code for Package ajango.database

 1  ########################################################################### 
 2  #                                                                         # 
 3  #  Copyright (C) 2016  Rafal Kobel <rafyco1@gmail.com>                    # 
 4  #                                                                         # 
 5  #  This program is free software: you can redistribute it and/or modify   # 
 6  #  it under the terms of the GNU General Public License as published by   # 
 7  #  the Free Software Foundation, either version 3 of the License, or      # 
 8  #  (at your option) any later version.                                    # 
 9  #                                                                         # 
10  #  This program is distributed in the hope that it will be useful,        # 
11  #  but WITHOUT ANY WARRANTY; without even the implied warranty of         # 
12  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           # 
13  #  GNU General Public License for more details.                           # 
14  #                                                                         # 
15  #  You should have received a copy of the GNU General Public License      # 
16  #  along with this program.  If not, see <http://www.gnu.org/licenses/>.  # 
17  #                                                                         # 
18  ########################################################################### 
19  """ Funkcje pomocnicze do zarzadzania baza danych. """ 
20   
21  from __future__                  import print_function 
22  from django.core.management.base import CommandError 
23  from xml.dom                     import minidom 
24  import inspect 
25   
26  #pylint: disable=W0212 
27 -def get_table_name_in_db(table):
28 """ Pobranie nazwy tabeli na podstawie obiektu modelu. """ 29 return table._meta.db_table
30 31 #pylint: disable=W0612
32 -def get_table_by_name(table_name, models):
33 """ Pobranie modelu na podstawie nazwy tabeli w bazie danych. """ 34 for name, temp_table in inspect.getmembers(models): 35 if inspect.isclass(temp_table): 36 try: 37 if get_table_name_in_db(temp_table) == table_name: 38 return temp_table 39 except AttributeError: 40 pass 41 raise CommandError("There are no table name called: %r" % table_name)
42