Package ajango :: Package site :: Package sites :: Module input
[hide private]
[frames] | no frames]

Source Code for Module ajango.site.sites.input

 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  """ 
20  Modul strony wprowadzajacej dane. 
21   
22  Obiekt obsluguje strone umozliwiajaca wprowadzenie nowych danych. 
23   
24  Obiekt Generujacy 
25  ================= 
26   
27  L{ajango.generator.views.input} 
28  """ 
29   
30  from __future__             import print_function 
31  from ajango.site.sites      import SiteBase 
32  from ajango.database.inputs import input_factory 
33  from ajango.database.inputs import InputManager 
34  from ajango.database.query  import DataCreate 
35   
36 -class Site(SiteBase):
37 """ Klasa strony wprowadzania danych. """
38 - def __init__(self, ob):
39 self.inputs = InputManager() 40 self.table = "" 41 self.models = None 42 SiteBase.__init__(self, ob)
43 - def init(self):
44 """ Metoda inicjalizujaca. """ 45 self.type = 'input'
46 - def add_input(self, param):
47 """ Dodanie pola wprowadzania danych. """ 48 self.inputs.add_input(input_factory(param))
49 - def set_table_name(self, table):
50 """ Ustawienie nazwy tabeli do pobrania. """ 51 self.table = table
52 - def set_models(self, models):
53 """ Ustawienie modelu dla strony. """ 54 self.models = models
55 - def _is_form_available(self):
56 """ Sprawdzenie czy dostepne sa dane dla obecnego widoku. """ 57 try: 58 return (self.request.method == 'POST' and 59 self.request.POST['view_id'] == ("view_%d" % self.view_id)) 60 except KeyError: 61 return False
62 - def send_data(self, post):
63 """ Wprowadzenie informacji do bazy danych. """ 64 data = DataCreate(self.table) 65 data.set_models(self.models) 66 data.create_from_post(post) 67 data.save()
68 - def content(self):
69 """ Buduje dane dla strony. """ 70 data = [] 71 self.data['result'] = True 72 if self._is_form_available(): 73 if self.inputs.is_valid(self.request.POST): 74 self.send_data(self.request.POST) 75 self.inputs.set_data(self.request.POST) 76 for elem in self.inputs.get_inputs(): 77 data.append(elem.get_data()) 78 self.data['tabledata'] = data
79