]> git.phdru.name Git - m_librarian.git/blob - m_librarian/web/views/list_books.py
Feat(web): Configure columns for author and book tables
[m_librarian.git] / m_librarian / web / views / list_books.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4
5
6
7 ##################################################
8 ## DEPENDENCIES
9 import sys
10 import os
11 import os.path
12 try:
13     import builtins as builtin
14 except ImportError:
15     import __builtin__ as builtin
16 from os.path import getmtime, exists
17 import time
18 import types
19 from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
20 from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
21 from Cheetah.Template import Template
22 from Cheetah.DummyTransaction import *
23 from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
24 from Cheetah.CacheRegion import CacheRegion
25 import Cheetah.Filters as Filters
26 import Cheetah.ErrorCatchers as ErrorCatchers
27 from Cheetah.compat import unicode
28 import cgi
29 from views.layout import layout
30
31 ##################################################
32 ## MODULE CONSTANTS
33 VFFSL=valueFromFrameOrSearchList
34 VFSL=valueFromSearchList
35 VFN=valueForName
36 currentTime=time.time
37 __CHEETAH_version__ = '3.1.0'
38 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
39 __CHEETAH_genTime__ = 1528670845.332275
40 __CHEETAH_genTimestamp__ = 'Mon Jun 11 01:47:25 2018'
41 __CHEETAH_src__ = 'list_books.tmpl'
42 __CHEETAH_srcLastModified__ = 'Mon Jun 11 01:46:57 2018'
43 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
44
45 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
46     raise AssertionError(
47       'This template was compiled with Cheetah version'
48       ' %s. Templates compiled before version %s must be recompiled.'%(
49          __CHEETAH_version__, RequiredCheetahVersion))
50
51 ##################################################
52 ## CLASSES
53
54 class list_books(layout):
55
56     ##################################################
57     ## CHEETAH GENERATED METHODS
58
59
60     def __init__(self, *args, **KWs):
61
62         super(list_books, self).__init__(*args, **KWs)
63         if not self._CHEETAH__instanceInitialized:
64             cheetahKWArgs = {}
65             allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
66             for k,v in KWs.items():
67                 if k in allowedKWs: cheetahKWArgs[k] = v
68             self._initCheetahInstance(**cheetahKWArgs)
69         
70
71     def body(self, **KWS):
72
73
74
75         ## CHEETAH: generated from #def body at line 5, col 1.
76         trans = KWS.get("trans")
77         if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
78             trans = self.transaction # is None unless self.awake() was called
79         if not trans:
80             trans = DummyTransaction()
81             _dummyTrans = True
82         else: _dummyTrans = False
83         write = trans.response().write
84         SL = self._CHEETAH__searchList
85         _filter = self._CHEETAH__currentFilter
86         
87         ########################################
88         ## START - generated method body
89         
90         write(u'''<h1>''')
91         _v = VFFSL(SL,"title",True) # u'$title' on line 6, col 5
92         if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 6, col 5.
93         write(u'''</h1>
94
95 ''')
96         if VFFSL(SL,"books_by_author",True): # generated from line 8, col 1
97             write(u'''  <form action="/download/" method="POST" style="height: 80%">
98   <table style="width: 100%; height: 90%">
99 ''')
100             series = None
101             columns1 = VFFSL(SL,"len",False)(VFFSL(SL,"columns",True))+1
102             for author in VFFSL(SL,"sorted",False)(VFFSL(SL,"books_by_author",True)): # generated from line 13, col 3
103                 books = VFFSL(SL,"books_by_author",True)[VFFSL(SL,"author",True)]
104                 for book in VFFSL(SL,"books",True): # generated from line 15, col 5
105                     if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 16, col 5
106                         series = VFFSL(SL,"book.series",True)
107                         write(u'''  <tr>
108   <td colspan="''')
109                         _v = VFFSL(SL,"columns1",True) # u'$columns1' on line 19, col 16
110                         if _v is not None: write(_filter(_v, rawExpr=u'$columns1')) # from line 19, col 16.
111                         write(u'''"><b>
112   ''')
113                         _v = VFFSL(SL,"author",True) # u'$author' on line 20, col 3
114                         if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 20, col 3.
115                         write(u''' \u2014 <i>
116 ''')
117                         if VFFSL(SL,"book.series",True): # generated from line 21, col 3
118                             _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 22, col 1
119                             if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 22, col 1.
120                         else: # generated from line 23, col 3
121                             write(u'''\u0412\u043d\u0435 \u0441\u0435\u0440\u0438\u0439''')
122                         write(u'''  </i></b></td>
123   </tr>
124 ''')
125                     write(u'''  <tr>
126   <td><input type=checkbox name=books value="''')
127                     _v = VFFSL(SL,"book.id",True) # u'$book.id' on line 30, col 46
128                     if _v is not None: write(_filter(_v, rawExpr=u'$book.id')) # from line 30, col 46.
129                     write(u'''"></td>
130 ''')
131                     for column in VFFSL(SL,"columns",True): # generated from line 31, col 3
132                         write(u'''  <td>''')
133                         _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(unicode(VFFSL(SL,"getattr",False)(VFFSL(SL,"book",True), VFFSL(SL,"column",True)) or '')) # u"$cgi.escape(unicode($getattr($book, $column) or ''))" on line 32, col 7
134                         if _v is not None: write(_filter(_v, rawExpr=u"$cgi.escape(unicode($getattr($book, $column) or ''))")) # from line 32, col 7.
135                         write(u'''</td>
136 ''')
137                     write(u'''  </tr>
138 ''')
139             write(u'''  <tr>
140   <td colspan="''')
141             _v = VFFSL(SL,"columns1",True) # u'$columns1' on line 38, col 16
142             if _v is not None: write(_filter(_v, rawExpr=u'$columns1')) # from line 38, col 16.
143             write(u'''" style="text-align: center"><input type="submit" value="\u0421\u043a\u0430\u0447\u0430\u0442\u044c"></td>
144   </tr>
145   </table>
146   </form>
147 ''')
148         else: # generated from line 42, col 1
149             write(u'''  <p>\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438!</p>
150 ''')
151         
152         ########################################
153         ## END - generated method body
154         
155         return _dummyTrans and trans.response().getvalue() or ""
156         
157
158     def writeBody(self, **KWS):
159
160
161
162         ## CHEETAH: main method generated for this template
163         trans = KWS.get("trans")
164         if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
165             trans = self.transaction # is None unless self.awake() was called
166         if not trans:
167             trans = DummyTransaction()
168             _dummyTrans = True
169         else: _dummyTrans = False
170         write = trans.response().write
171         SL = self._CHEETAH__searchList
172         _filter = self._CHEETAH__currentFilter
173         
174         ########################################
175         ## START - generated method body
176         
177         
178         ########################################
179         ## END - generated method body
180         
181         return _dummyTrans and trans.response().getvalue() or ""
182         
183     ##################################################
184     ## CHEETAH GENERATED ATTRIBUTES
185
186
187     _CHEETAH__instanceInitialized = False
188
189     _CHEETAH_version = __CHEETAH_version__
190
191     _CHEETAH_versionTuple = __CHEETAH_versionTuple__
192
193     _CHEETAH_genTime = __CHEETAH_genTime__
194
195     _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
196
197     _CHEETAH_src = __CHEETAH_src__
198
199     _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
200
201     title = 'Список книг'
202
203     _mainCheetahMethod_for_list_books = 'writeBody'
204
205 ## END CLASS DEFINITION
206
207 if not hasattr(list_books, '_initCheetahAttributes'):
208     templateAPIClass = getattr(list_books,
209                                '_CHEETAH_templateClass',
210                                Template)
211     templateAPIClass._addCheetahPlumbingCodeToClass(list_books)
212
213
214 # CHEETAH was developed by Tavis Rudd and Mike Orr
215 # with code, advice and input from many other volunteers.
216 # For more information visit http://cheetahtemplate.org/
217
218 ##################################################
219 ## if run from command line:
220 if __name__ == '__main__':
221     from Cheetah.TemplateCmdLineIface import CmdLineIface
222     CmdLineIface(templateObj=list_books()).run()
223
224