]> git.phdru.name Git - m_librarian.git/blob - m_librarian/web/views/list_books.py
Refactor(web): Use `#filter WebSafe` instead of `cgi.escape`
[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 from m_librarian.translations import translations
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.3.1'
38 __CHEETAH_versionTuple__ = (3, 3, 1, 'final', 0)
39 __CHEETAH_genTime__ = 1718725757.733093
40 __CHEETAH_genTimestamp__ = 'Tue Jun 18 18:49:17 2024'
41 __CHEETAH_src__ = 'list_books.tmpl'
42 __CHEETAH_srcLastModified__ = 'Tue Jun 18 18:49:15 2024'
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 <script type="text/javascript" language="Javascript">
96 <!--
97 function toggleBooks(selector, value) {
98   cboxes = document.querySelectorAll(selector);
99   for (var i = 0; i < cboxes.length; i++) {
100     cboxes[i].checked = value;
101   }
102 }
103
104 function toggleAll(value) {
105   toggleBooks(\'input[type=checkbox]\', value);
106 }
107
108 function toggleAuthor(name, value) {
109   toggleBooks(\'input[type=checkbox][name^=\' + name + \']\', value);
110 }
111
112 function toggleSeries(name, value) {
113   toggleBooks(\'input[type=checkbox][name^=\' + name + \'_book]\', value);
114 }
115 // -->
116 </script>
117
118 ''')
119         if VFFSL(SL,"books_by_author",True): # generated from line 31, col 1
120             _orig_filter_17563757 = _filter
121             filterName = u'WebSafe'
122             if "WebSafe" in self._CHEETAH__filters:
123                 _filter = self._CHEETAH__currentFilter = self._CHEETAH__filters[filterName]
124             else:
125                 _filter = self._CHEETAH__currentFilter = \
126                         self._CHEETAH__filters[filterName] = getattr(self._CHEETAH__filtersLib, filterName)(self).filter
127             write(u'''  <form action="/download/" method="POST" style="height: 80%">
128   <table style="width: 100%; height: 90%">
129   <tr>
130   <td><input type=checkbox name="_toggleAll"
131   onClick="toggleAll(this.checked)"></td>
132   ''')
133             if False:
134                 _
135             _ = VFFSL(SL,"getattr",False)(VFFSL(SL,"translations",True), 'ugettext', None) or VFFSL(SL,"translations.gettext",True)
136             for column in VFFSL(SL,"columns",True): # generated from line 39, col 3
137                 write(u'''    <td style="text-align: center">''')
138                 if False:
139                     _(VFFSL(SL,"column",True))
140                 _v = VFFSL(SL,"_",False)(VFFSL(SL,"column",True)) # u'$_($column)' on line 40, col 36
141                 if _v is not None: write(_filter(_v, rawExpr=u'$_($column)')) # from line 40, col 36.
142                 write(u'''</td>
143 ''')
144             write(u'''  </tr>
145 ''')
146             columns1 = VFFSL(SL,"len",False)(VFFSL(SL,"columns",True))+1
147             for anum, author in VFFSL(SL,"enumerate",False)(VFFSL(SL,"sorted",False)(VFFSL(SL,"books_by_author",True))): # generated from line 44, col 3
148                 series = None
149                 snum = 0
150                 books = VFFSL(SL,"books_by_author",True)[VFFSL(SL,"author",True)]
151                 write(u'''  <tr>
152   <td><input type=checkbox name="a''')
153                 _v = VFFSL(SL,"anum",True)+1 # u'${anum+1}' on line 49, col 35
154                 if _v is not None: write(_filter(_v, rawExpr=u'${anum+1}')) # from line 49, col 35.
155                 write(u'''_"
156   onClick="toggleAuthor(this.name, this.checked)"></td>
157   <td colspan="''')
158                 _v = VFFSL(SL,"columns1",True)-1 # u'${columns1-1}' on line 51, col 16
159                 if _v is not None: write(_filter(_v, rawExpr=u'${columns1-1}')) # from line 51, col 16.
160                 write(u'''"><b>''')
161                 _v = VFFSL(SL,"author",True) # u'$author' on line 51, col 34
162                 if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 51, col 34.
163                 write(u'''</b></td>
164   </tr>
165 ''')
166                 for book in VFFSL(SL,"books",True): # generated from line 53, col 5
167                     if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 54, col 5
168                         series = VFFSL(SL,"book.series",True)
169                         snum += 1
170                         write(u'''  <tr>
171   <td><input type=checkbox name="a''')
172                         _v = VFFSL(SL,"anum",True)+1 # u'${anum+1}' on line 58, col 35
173                         if _v is not None: write(_filter(_v, rawExpr=u'${anum+1}')) # from line 58, col 35.
174                         write(u'''_s''')
175                         _v = VFFSL(SL,"snum",True) # u'${snum}' on line 58, col 46
176                         if _v is not None: write(_filter(_v, rawExpr=u'${snum}')) # from line 58, col 46.
177                         write(u'''"
178   onClick="toggleSeries(this.name, this.checked)"></td>
179   <td colspan="''')
180                         _v = VFFSL(SL,"columns1",True)-1 # u'${columns1-1}' on line 60, col 16
181                         if _v is not None: write(_filter(_v, rawExpr=u'${columns1-1}')) # from line 60, col 16.
182                         write(u'''"><b>
183   ''')
184                         _v = VFFSL(SL,"author",True) # u'$author' on line 61, col 3
185                         if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 61, col 3.
186                         write(u''' \u2014 <i>
187 ''')
188                         if VFFSL(SL,"book.series",True): # generated from line 62, col 3
189                             _v = VFFSL(SL,"series",True) # u'$series' on line 63, col 1
190                             if _v is not None: write(_filter(_v, rawExpr=u'$series')) # from line 63, col 1.
191                             write(u''', 1''')
192                         else: # generated from line 64, col 3
193                             write(u'''\u0412\u043d\u0435 \u0441\u0435\u0440\u0438\u0439''')
194                         write(u'''  </i></b></td>
195   </tr>
196 ''')
197                     write(u'''  <tr>
198   <td><input type=checkbox name="a''')
199                     _v = VFFSL(SL,"anum",True)+1 # u'${anum+1}' on line 71, col 35
200                     if _v is not None: write(_filter(_v, rawExpr=u'${anum+1}')) # from line 71, col 35.
201                     write(u'''_s''')
202                     _v = VFFSL(SL,"snum",True) # u'${snum}' on line 71, col 46
203                     if _v is not None: write(_filter(_v, rawExpr=u'${snum}')) # from line 71, col 46.
204                     write(u'''_books" value="''')
205                     _v = VFFSL(SL,"book.id",True) # u'$book.id' on line 71, col 68
206                     if _v is not None: write(_filter(_v, rawExpr=u'$book.id')) # from line 71, col 68.
207                     write(u'''"></td>
208 ''')
209                     for column in VFFSL(SL,"columns",True): # generated from line 72, col 3
210                         if VFFSL(SL,"column",True) in ('ser_no', 'size'): # generated from line 73, col 3
211                             style = ' style="text-align: right; width: 5ex"'
212                         else: # generated from line 75, col 3
213                             style = ''
214                         write(u'''  <td''')
215                         _v = VFFSL(SL,"style",True) # u'$style' on line 78, col 6
216                         if _v is not None: write(_filter(_v, rawExpr=u'$style')) # from line 78, col 6.
217                         write(u'''>''')
218                         _v = VFFSL(SL,"unicode",False)(VFFSL(SL,"getattr",False)(VFFSL(SL,"book",True), VFFSL(SL,"column",True)) or '') # u"$unicode($getattr($book, $column) or '')" on line 78, col 13
219                         if _v is not None: write(_filter(_v, rawExpr=u"$unicode($getattr($book, $column) or '')")) # from line 78, col 13.
220                         write(u'''</td>
221 ''')
222                     write(u'''  </tr>
223 ''')
224             write(u'''  <tr>
225   <td colspan="''')
226             _v = VFFSL(SL,"columns1",True) # u'$columns1' on line 84, col 16
227             if _v is not None: write(_filter(_v, rawExpr=u'$columns1')) # from line 84, col 16.
228             write(u'''" style="text-align: center"><input type="submit" value="\u0421\u043a\u0430\u0447\u0430\u0442\u044c"></td>
229   </tr>
230   </table>
231   </form>
232 ''')
233             _filter = self._CHEETAH__currentFilter = _orig_filter_17563757
234         else: # generated from line 89, col 1
235             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>
236 ''')
237         
238         ########################################
239         ## END - generated method body
240         
241         return _dummyTrans and trans.response().getvalue() or ""
242         
243
244     def writeBody(self, **KWS):
245
246
247
248         ## CHEETAH: main method generated for this template
249         trans = KWS.get("trans")
250         if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
251             trans = self.transaction # is None unless self.awake() was called
252         if not trans:
253             trans = DummyTransaction()
254             _dummyTrans = True
255         else: _dummyTrans = False
256         write = trans.response().write
257         SL = self._CHEETAH__searchList
258         _filter = self._CHEETAH__currentFilter
259         
260         ########################################
261         ## START - generated method body
262         
263         
264         ########################################
265         ## END - generated method body
266         
267         return _dummyTrans and trans.response().getvalue() or ""
268         
269     ##################################################
270     ## CHEETAH GENERATED ATTRIBUTES
271
272
273     _CHEETAH__instanceInitialized = False
274
275     _CHEETAH_version = __CHEETAH_version__
276
277     _CHEETAH_versionTuple = __CHEETAH_versionTuple__
278
279     _CHEETAH_genTime = __CHEETAH_genTime__
280
281     _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
282
283     _CHEETAH_src = __CHEETAH_src__
284
285     _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
286
287     title = 'Список книг'
288
289     _mainCheetahMethod_for_list_books = 'writeBody'
290
291 ## END CLASS DEFINITION
292
293 if not hasattr(list_books, '_initCheetahAttributes'):
294     templateAPIClass = getattr(list_books,
295                                '_CHEETAH_templateClass',
296                                Template)
297     templateAPIClass._addCheetahPlumbingCodeToClass(list_books)
298
299
300 # CHEETAH was developed by Tavis Rudd and Mike Orr
301 # with code, advice and input from many other volunteers.
302 # For more information visit https://cheetahtemplate.org/
303
304 ##################################################
305 ## if run from command line:
306 if __name__ == '__main__':
307     from Cheetah.TemplateCmdLineIface import CmdLineIface
308     CmdLineIface(templateObj=list_books()).run()
309
310