]> git.phdru.name Git - m_librarian.git/blob - m_librarian/web/views/list_books.py
Feat(web/views/list_books): Toggle checkboxes for series
[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__ = 1671296508.007271
41 __CHEETAH_genTimestamp__ = 'Sat Dec 17 20:01:48 2022'
42 __CHEETAH_src__ = 'list_books.tmpl'
43 __CHEETAH_srcLastModified__ = 'Sat Dec 17 20:01:44 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(name, value) {
99   cboxes = document.querySelectorAll(
100     \'input[type=checkbox][name^=\' + name + \'_book]\');
101   for (var i = 0; i < cboxes.length; i++) {
102     cboxes[i].checked = value;
103   }
104 }
105 // -->
106 </script>
107
108 ''')
109         if VFFSL(SL,"books_by_author",True): # generated from line 21, col 1
110             write(u'''  <form action="/download/" method="POST" style="height: 80%">
111   <table style="width: 100%; height: 90%">
112   <tr>
113   <td>&nbsp;</td>
114   ''')
115             if False:
116                 _
117             _ = VFFSL(SL,"getattr",False)(VFFSL(SL,"translations",True), 'ugettext', None) or VFFSL(SL,"translations.gettext",True)
118             for column in VFFSL(SL,"columns",True): # generated from line 27, col 3
119                 write(u'''    <td style="text-align: center">''')
120                 if False:
121                     _(VFFSL(SL,"column",True))
122                 _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"_",False)(VFFSL(SL,"column",True))) # u'$cgi.escape($_($column))' on line 28, col 36
123                 if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($_($column))')) # from line 28, col 36.
124                 write(u'''</td>
125 ''')
126             write(u'''  </tr>
127 ''')
128             columns1 = VFFSL(SL,"len",False)(VFFSL(SL,"columns",True))+1
129             for anum, author in VFFSL(SL,"enumerate",False)(VFFSL(SL,"sorted",False)(VFFSL(SL,"books_by_author",True))): # generated from line 32, col 3
130                 series = None
131                 snum = 0
132                 books = VFFSL(SL,"books_by_author",True)[VFFSL(SL,"author",True)]
133                 for book in VFFSL(SL,"books",True): # generated from line 36, col 5
134                     if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 37, col 5
135                         series = VFFSL(SL,"book.series",True)
136                         snum += 1
137                         write(u'''  <tr>
138   <td><input type=checkbox name="a''')
139                         _v = VFFSL(SL,"anum",True)+1 # u'${anum+1}' on line 41, col 35
140                         if _v is not None: write(_filter(_v, rawExpr=u'${anum+1}')) # from line 41, col 35.
141                         write(u'''_s''')
142                         _v = VFFSL(SL,"snum",True) # u'${snum}' on line 41, col 46
143                         if _v is not None: write(_filter(_v, rawExpr=u'${snum}')) # from line 41, col 46.
144                         write(u'''"
145   onClick="toggleBooks(this.name, this.checked)"></td>
146   <td colspan="''')
147                         _v = VFFSL(SL,"columns1",True)-1 # u'${columns1-1}' on line 43, col 16
148                         if _v is not None: write(_filter(_v, rawExpr=u'${columns1-1}')) # from line 43, col 16.
149                         write(u'''"><b>
150   ''')
151                         _v = VFFSL(SL,"author",True) # u'$author' on line 44, col 3
152                         if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 44, col 3.
153                         write(u''' \u2014 <i>
154 ''')
155                         if VFFSL(SL,"book.series",True): # generated from line 45, col 3
156                             _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 46, col 1
157                             if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 46, col 1.
158                         else: # generated from line 47, col 3
159                             write(u'''\u0412\u043d\u0435 \u0441\u0435\u0440\u0438\u0439''')
160                         write(u'''  </i></b></td>
161   </tr>
162 ''')
163                     write(u'''  <tr>
164   <td><input type=checkbox name="a''')
165                     _v = VFFSL(SL,"anum",True)+1 # u'${anum+1}' on line 54, col 35
166                     if _v is not None: write(_filter(_v, rawExpr=u'${anum+1}')) # from line 54, col 35.
167                     write(u'''_s''')
168                     _v = VFFSL(SL,"snum",True) # u'${snum}' on line 54, col 46
169                     if _v is not None: write(_filter(_v, rawExpr=u'${snum}')) # from line 54, col 46.
170                     write(u'''_books" value="''')
171                     _v = VFFSL(SL,"book.id",True) # u'$book.id' on line 54, col 68
172                     if _v is not None: write(_filter(_v, rawExpr=u'$book.id')) # from line 54, col 68.
173                     write(u'''"></td>
174 ''')
175                     for column in VFFSL(SL,"columns",True): # generated from line 55, col 3
176                         if VFFSL(SL,"column",True) in ('ser_no', 'size'): # generated from line 56, col 3
177                             style = ' style="text-align: right; width: 5ex"'
178                         else: # generated from line 58, col 3
179                             style = ''
180                         write(u'''  <td''')
181                         _v = VFFSL(SL,"style",True) # u'$style' on line 61, col 6
182                         if _v is not None: write(_filter(_v, rawExpr=u'$style')) # from line 61, col 6.
183                         write(u'''>''')
184                         _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 61, col 13
185                         if _v is not None: write(_filter(_v, rawExpr=u"$cgi.escape(unicode($getattr($book, $column) or ''))")) # from line 61, col 13.
186                         write(u'''</td>
187 ''')
188                     write(u'''  </tr>
189 ''')
190             write(u'''  <tr>
191   <td colspan="''')
192             _v = VFFSL(SL,"columns1",True) # u'$columns1' on line 67, col 16
193             if _v is not None: write(_filter(_v, rawExpr=u'$columns1')) # from line 67, col 16.
194             write(u'''" style="text-align: center"><input type="submit" value="\u0421\u043a\u0430\u0447\u0430\u0442\u044c"></td>
195   </tr>
196   </table>
197   </form>
198 ''')
199         else: # generated from line 71, col 1
200             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>
201 ''')
202         
203         ########################################
204         ## END - generated method body
205         
206         return _dummyTrans and trans.response().getvalue() or ""
207         
208
209     def writeBody(self, **KWS):
210
211
212
213         ## CHEETAH: main method generated for this template
214         trans = KWS.get("trans")
215         if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
216             trans = self.transaction # is None unless self.awake() was called
217         if not trans:
218             trans = DummyTransaction()
219             _dummyTrans = True
220         else: _dummyTrans = False
221         write = trans.response().write
222         SL = self._CHEETAH__searchList
223         _filter = self._CHEETAH__currentFilter
224         
225         ########################################
226         ## START - generated method body
227         
228         
229         ########################################
230         ## END - generated method body
231         
232         return _dummyTrans and trans.response().getvalue() or ""
233         
234     ##################################################
235     ## CHEETAH GENERATED ATTRIBUTES
236
237
238     _CHEETAH__instanceInitialized = False
239
240     _CHEETAH_version = __CHEETAH_version__
241
242     _CHEETAH_versionTuple = __CHEETAH_versionTuple__
243
244     _CHEETAH_genTime = __CHEETAH_genTime__
245
246     _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
247
248     _CHEETAH_src = __CHEETAH_src__
249
250     _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
251
252     title = 'Список книг'
253
254     _mainCheetahMethod_for_list_books = 'writeBody'
255
256 ## END CLASS DEFINITION
257
258 if not hasattr(list_books, '_initCheetahAttributes'):
259     templateAPIClass = getattr(list_books,
260                                '_CHEETAH_templateClass',
261                                Template)
262     templateAPIClass._addCheetahPlumbingCodeToClass(list_books)
263
264
265 # CHEETAH was developed by Tavis Rudd and Mike Orr
266 # with code, advice and input from many other volunteers.
267 # For more information visit https://cheetahtemplate.org/
268
269 ##################################################
270 ## if run from command line:
271 if __name__ == '__main__':
272     from Cheetah.TemplateCmdLineIface import CmdLineIface
273     CmdLineIface(templateObj=list_books()).run()
274
275