| Home | Trees | Indices | Help |
|---|
|
|
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 z edycja danych.
21
22 Obiekt obsluguje strone pozwalajaca na edytowanie danych.
23
24 Obiekt Generujacy
25 =================
26
27 L{ajango.generator.views.editable}
28 """
29
30 from __future__ import print_function
31 from django.utils.datastructures import MultiValueDictKeyError
32 from ajango.site.sites import SiteBase
33 from ajango.database.inputs import input_factory
34 from ajango.database.inputs import InputManager
35 from ajango.database.query import DataEdit
36 from ajango.database import get_table_by_name
37
39 """ Klasa strony wprowadzania danych. """
41 self.inputs = InputManager()
42 self.table = ""
43 self.models = None
44 self.editable_ob = None
45 SiteBase.__init__(self, ob)
46 self.identity = self.get_id()
60 """ Sprawdzenie czy dostepne sa dane dla obecnego widoku. """
61 try:
62 return (self.request.method == 'POST' and
63 self.request.POST['view_id'] == ("view_%d" % self.view_id))
64 except KeyError:
65 return False
67 """ Zwraca id rekordu ktory wyswietla. """
68 try:
69 identity = self.request.GET['id']
70 except MultiValueDictKeyError:
71 try:
72 identity = self.request.POST['identity']
73 except MultiValueDictKeyError:
74 identity = -1
75 return identity
77 """ Wprowadzenie informacji do bazy danych. """
78 data = DataEdit(self.table, self.editable_ob)
79 data.set_models(self.models)
80 data.edit_with_post(post)
81 data.save()
83 """ Buduje dane dla strony. """
84 table_ob = get_table_by_name(self.table, self.models)
85 try:
86 self.editable_ob = table_ob.objects.filter(id=self.identity)[0]
87 except IndexError:
88 self.editable_ob = None
89 data = []
90 self.data['result'] = True
91 self.data['identity'] = self.identity
92 if self.editable_ob == None:
93 self.data['result'] = False
94 return
95 if self._is_form_available():
96 if self.inputs.is_valid(self.request.POST):
97 self.send_data(self.request.POST)
98 self.data['result'] = False
99 return
100 self.inputs.set_data(self.request.POST)
101 else:
102 self.inputs.set_data_table(self.editable_ob)
103 for elem in self.inputs.get_inputs():
104 data.append(elem.get_data())
105 self.data['tabledata'] = data
106
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Oct 20 21:01:52 2016 | http://epydoc.sourceforge.net |