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