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

Source Code for Package ajango.site.sites

  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 zarzadzania stronami. 
 21   
 22  Modul posiada mechanizmy do wyswietlania stron zgodnych z okreslonymi danymi. 
 23   
 24  Dostepne strony 
 25  =============== 
 26   
 27  System pozwala na obsluge nastepujacych L{stron<ajango.site.sites>}. 
 28   
 29      - L{pusta strona <ajango.site.sites.empty>} 
 30      - L{strona wprowadzania danych <ajango.site.sites.input>} 
 31      - L{strona wyswietlajaca <ajango.site.sites.display>} 
 32      - L{lista danych <ajango.site.sites.list>} 
 33      - L{strona z mozliwoscia edycji <ajango.site.sites.editable>} (niedostepne) 
 34      - L{strona wyswietlania raportu <ajango.site.sites.raport>} 
 35      - L{agregacja stron <ajango.site.sites.container>} 
 36   
 37  W celu zapoznania sie z metoda generowania stron w pliku szkieletowym 
 38  zajrzyj do L{ajango.generator.views}. 
 39  """ 
 40   
 41  from django.utils.datastructures import MultiValueDictKeyError 
 42  from ajango.core.factory         import FactoryBase 
 43  from django.core.management.base import CommandError 
 44  from django.shortcuts            import render 
 45  from abc                         import ABCMeta, abstractmethod 
 46  import ajango 
47 48 -class SiteFactoryObject(FactoryBase):
49 """ Obiekt fabryki stron. """
50 - def init(self):
51 """ Metoda inicjalizujaca. """ 52 self.set_items('Site', { 53 'empty' : 'ajango.site.sites.empty', 54 'input' : 'ajango.site.sites.input', 55 'list' : 'ajango.site.sites.list', 56 'display' : 'ajango.site.sites.display', 57 'editable' : 'ajango.site.sites.editable', 58 'raport' : 'ajango.site.sites.raport', 59 'container' : 'ajango.site.sites.container' 60 })
61
62 -def site_factory(key, param):
63 """ Fabryka stron. """ 64 return SiteFactoryObject(param).get_class_factory(key)
65
66 #pylint: disable=R0902 67 -class SiteBase(object):
68 """ Abstrakcyjna klasa obslugujaca strone. """ 69 __metaclass__ = ABCMeta 70 global_view_id_counter = 0
71 - def __init__(self, ob):
72 self.view_id = self.global_view_id_counter 73 self.global_view_id_counter = self.global_view_id_counter + 1 74 self.request = ob['request'] 75 self.theme = 'default' 76 self.header = "" 77 self.type = 'empty' # default type for layout 78 self.init() 79 self.layout = 'ajango_layout.html' 80 self.include = 'ajango_%s.html' % self.type 81 self.data = dict() 82 self.data['appName'] = ob['appName'] 83 self.data['viewName'] = ob['viewName'] 84 self.data['menu'] = []
85 - def set_view_id(self, view_id):
86 """ 87 Zmiana id widoku niezbedna przy obsludze wiekszej ilosci widokow. 88 """ 89 self.view_id = view_id
90 - def set_title(self, text):
91 """ Ustaw tytul strony. """ 92 self.data['title'] = text
93 - def set_header(self, text):
94 """ Ustaw tytul sekcji. """ 95 self.header = text
96 - def set_theme(self, theme):
97 """ 98 Ustawienie tematu layoutu. 99 100 Ajango wczytuje pliku html z folderu oznaczonego przez zmienna 101 ustawiana w tej funkcji. System pobiera pliki o nazwach okreslonych 102 na podstawie dokumentacji, ale mozna je umiescic 103 w pakietach o nazwach podanych w zmiennej. 104 """ 105 self.theme = theme
106 @abstractmethod
107 - def init(self):
108 """ Metoda inicjalizujaca. """ 109 raise NotImplementedError()
110 - def set_include(self, text):
111 """ Ustawienie glownego pliku ze strona odpowiedniego dla strony. """ 112 self.include = text
113 - def set_layout(self, html):
114 """ Ustawienie pliku layoutu. """ 115 self.layout = html
116 @abstractmethod
117 - def content(self):
118 """ Ustawienie zmiennych dostarczanych do szblonow. """ 119 raise NotImplementedError()
120 - def make_content(self):
121 """ Metoda wywolywana przez zewnetrzny interface. """ 122 if self.header != "": 123 self.data['header'] = self.header 124 self.data['include_view'] = self.theme + '/' + self.include 125 self.data['view_id'] = self.view_id 126 self.content()
128 """ 129 Buduje dane kontentu i zwraca informacje na temat danych 130 utworzonych przez strone. 131 """ 132 self.make_content() 133 return self.data
134 - def make_site(self):
135 """ 136 Wywolaj renderowanie strony. 137 138 Zwraca informacje jakie powinny byc tworzone w plikach view.py 139 frameworku Django. 140 """ 141 self.make_content() 142 return render(self.request, self.theme + '/' + self.layout, 143 {'data_site' : self.data})
144 - def set_menu(self, tab):
145 """ Ustawienie menu. """ 146 self.data['menu'] = tab
147
148 -class GetSite(object):
149 """ Klasa strony odczytujacej dane za pomoca metody post i get. """ 150 __metaclass__ = ABCMeta 151 @abstractmethod
152 - def get_request(self):
153 """ Zwraca obiekt request. """ 154 raise NotImplementedError()
155 - def get_id(self):
156 """ Zwraca id rekordu ktory wyswietla. """ 157 try: 158 request = self.get_request() 159 identity = int(request.GET['id']) 160 except MultiValueDictKeyError: 161 identity = -1 162 except ValueError: 163 return -1 164 return identity
165