]> git.phdru.name Git - m_librarian.git/commitdiff
Feat(web): Preserve values in form
authorOleg Broytman <phd@phdru.name>
Thu, 5 Apr 2018 21:03:30 +0000 (00:03 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 5 Apr 2018 21:24:17 +0000 (00:24 +0300)
m_librarian/web/app.py
m_librarian/web/views/index.py
m_librarian/web/views/index.tmpl
m_librarian/web/views/layout.py
m_librarian/web/views/list_authors.py
m_librarian/web/views/list_authors.tmpl
m_librarian/web/views/search_authors.py
m_librarian/web/views/search_authors.tmpl
m_librarian/web/views/search_authors_form.py
m_librarian/web/views/search_authors_form.tmpl

index e4677d317f10e7b6cb9204766b30500c2ba7b51e..638f1528e3826c41e102d164d4aa4ac7d8789aa1 100644 (file)
@@ -52,4 +52,9 @@ def search_authors_post():
     open_db()
     authors = search_authors(search_type, case_sensitive, {}, expressions,
                              orderBy=('surname', 'name', 'misc_name'))
-    return {'authors': list(authors)}
+    return {
+        'authors': list(authors),
+        'search_authors': value,
+        'search_type': search_type,
+        'case_sensitive': case_sensitive,
+    }
index 1e4c4dfab5355e963beecf790c5df0c45e26b565..e039c2a5c2e82ad45f9ec393bc536e21e0576588 100644 (file)
@@ -36,10 +36,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '3.1.0'
 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1522958547.022135
-__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:02:27 2018'
+__CHEETAH_genTime__ = 1522961823.924543
+__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:57:03 2018'
 __CHEETAH_src__ = 'index.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:02:23 2018'
+__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:54:01 2018'
 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
@@ -90,8 +90,8 @@ class index(layout):
         write(u'''<h1>\u041f\u043e\u0438\u0441\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432</h1>
 
 ''')
-        _v = VFFSL(SL,"search_authors_form",False)() # u'$search_authors_form()' on line 8, col 1
-        if _v is not None: write(_filter(_v, rawExpr=u'$search_authors_form()')) # from line 8, col 1.
+        _v = VFFSL(SL,"search_authors_form",False)(searchList=VFFSL(SL,"searchList",True)) # u'$search_authors_form(searchList=$searchList)' on line 8, col 1
+        if _v is not None: write(_filter(_v, rawExpr=u'$search_authors_form(searchList=$searchList)')) # from line 8, col 1.
         write(u'''
 ''')
         
index 57c6b74f81a116bc4c5b457b7588035fad06a466..f8be6c70b4a751a3bfab8f4fe8821bbf634b64c8 100644 (file)
@@ -5,5 +5,5 @@
 <h1>Поиск авторов</h1>
 
 #from views.search_authors_form import search_authors_form
-$search_authors_form()
+$search_authors_form(searchList=$searchList)
 #end def
index 726e57028a4a62de8e22470814fa4e61beecfd78..8bc236ee26976fe999e83f2db543e24759a25657 100644 (file)
@@ -34,10 +34,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '3.1.0'
 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1522953148.995817
-__CHEETAH_genTimestamp__ = 'Thu Apr  5 21:32:28 2018'
+__CHEETAH_genTime__ = 1522960530.67886
+__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:35:30 2018'
 __CHEETAH_src__ = 'layout.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr  5 21:32:27 2018'
+__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:35:06 2018'
 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
index f38c9c4a436df8134d19faf59f01bb0e212698d3..3c5245a92a31e5bc6b1ca6f0b79265cb211ac15e 100644 (file)
@@ -26,6 +26,7 @@ import Cheetah.Filters as Filters
 import Cheetah.ErrorCatchers as ErrorCatchers
 from Cheetah.compat import unicode
 from views.layout import layout
+from views.search_authors_form import search_authors_form
 
 ##################################################
 ## MODULE CONSTANTS
@@ -35,10 +36,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '3.1.0'
 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1522957487.491209
-__CHEETAH_genTimestamp__ = 'Thu Apr  5 22:44:47 2018'
+__CHEETAH_genTime__ = 1522961824.042332
+__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:57:04 2018'
 __CHEETAH_src__ = 'list_authors.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr  5 22:42:57 2018'
+__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:54:11 2018'
 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
@@ -86,26 +87,32 @@ class list_authors(layout):
         ########################################
         ## START - generated method body
         
-        write(u'''<h1>''')
-        _v = VFFSL(SL,"title",True) # u'$title' on line 5, col 5
-        if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 5, col 5.
+        write(u'''<h1>\u041f\u043e\u0438\u0441\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432</h1>
+''')
+        _v = VFFSL(SL,"search_authors_form",False)(searchList=VFFSL(SL,"searchList",True)) # u'$search_authors_form(searchList=$searchList)' on line 7, col 1
+        if _v is not None: write(_filter(_v, rawExpr=u'$search_authors_form(searchList=$searchList)')) # from line 7, col 1.
+        write(u'''
+
+<h1>''')
+        _v = VFFSL(SL,"title",True) # u'$title' on line 9, col 5
+        if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 9, col 5.
         write(u'''</h1>
 
 ''')
-        if VFFSL(SL,"authors",True): # generated from line 7, col 1
+        if VFFSL(SL,"authors",True): # generated from line 11, col 1
             write(u'''  <table>
 ''')
-            for author in VFFSL(SL,"authors",True): # generated from line 9, col 3
+            for author in VFFSL(SL,"authors",True): # generated from line 13, col 3
                 write(u'''  <tr>
     <td>''')
-                _v = VFFSL(SL,"author.fullname",True) # u'$author.fullname' on line 11, col 9
-                if _v is not None: write(_filter(_v, rawExpr=u'$author.fullname')) # from line 11, col 9.
+                _v = VFFSL(SL,"author.fullname",True) # u'$author.fullname' on line 15, col 9
+                if _v is not None: write(_filter(_v, rawExpr=u'$author.fullname')) # from line 15, col 9.
                 write(u'''</td>
   </tr>
 ''')
             write(u'''  </table>
 ''')
-        else: # generated from line 15, col 1
+        else: # generated from line 19, col 1
             write(u'''  <p>\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430!</p>
 ''')
         
index b0b20ad08d4e22e6f316bab92da85381f38ded23..9bb417624c361fa33198ed6ebdfbfc157bfda95e 100644 (file)
@@ -2,6 +2,10 @@
 #extends views.layout
 #attr $title = 'Список авторов'
 #def body
+<h1>Поиск авторов</h1>
+#from views.search_authors_form import search_authors_form
+$search_authors_form(searchList=$searchList)
+
 <h1>$title</h1>
 
 #if $authors
index fdc4a4be5ed76f01b8e1407a57ea8c5509e0818c..cfa90831135ea074d8472e2ae144d34ab30c3d6c 100644 (file)
@@ -36,10 +36,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '3.1.0'
 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1522952816.408144
-__CHEETAH_genTimestamp__ = 'Thu Apr  5 21:26:56 2018'
+__CHEETAH_genTime__ = 1522961824.208664
+__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:57:04 2018'
 __CHEETAH_src__ = 'search_authors.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr  5 21:26:43 2018'
+__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:54:16 2018'
 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
@@ -93,8 +93,8 @@ class search_authors(layout):
         write(u'''</h1>
 
 ''')
-        _v = VFFSL(SL,"search_authors_form",False)() # u'$search_authors_form()' on line 8, col 1
-        if _v is not None: write(_filter(_v, rawExpr=u'$search_authors_form()')) # from line 8, col 1.
+        _v = VFFSL(SL,"search_authors_form",False)(searchList=VFFSL(SL,"searchList",True)) # u'$search_authors_form(searchList=$searchList)' on line 8, col 1
+        if _v is not None: write(_filter(_v, rawExpr=u'$search_authors_form(searchList=$searchList)')) # from line 8, col 1.
         write(u'''
 ''')
         
index b659f38aa798ba1786abec33c0c4ecdbbf34772e..eb295c7ce1ecd0d2d17517bc8e06b417d739fef5 100644 (file)
@@ -5,5 +5,5 @@
 <h1>$title</h1>
 
 #from views.search_authors_form import search_authors_form
-$search_authors_form()
+$search_authors_form(searchList=$searchList)
 #end def
index 1e304437900683b865de2300769518fc75273c40..8ab0a8bafce32419d8cb6af912d3d5dca11b8cb8 100644 (file)
@@ -25,6 +25,7 @@ from Cheetah.CacheRegion import CacheRegion
 import Cheetah.Filters as Filters
 import Cheetah.ErrorCatchers as ErrorCatchers
 from Cheetah.compat import unicode
+from bottle import html_escape
 
 ##################################################
 ## MODULE CONSTANTS
@@ -34,10 +35,10 @@ VFN=valueForName
 currentTime=time.time
 __CHEETAH_version__ = '3.1.0'
 __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
-__CHEETAH_genTime__ = 1522958937.217914
-__CHEETAH_genTimestamp__ = 'Thu Apr  5 23:08:57 2018'
+__CHEETAH_genTime__ = 1522963362.420098
+__CHEETAH_genTimestamp__ = 'Fri Apr  6 00:22:42 2018'
 __CHEETAH_src__ = 'search_authors_form.tmpl'
-__CHEETAH_srcLastModified__ = 'Thu Apr  5 23:08:55 2018'
+__CHEETAH_srcLastModified__ = 'Fri Apr  6 00:22:40 2018'
 __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
 
 if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
@@ -66,6 +67,62 @@ class search_authors_form(Template):
             self._initCheetahInstance(**cheetahKWArgs)
         
 
+    def search_type_checked(self, value, **KWS):
+
+
+
+        ## CHEETAH: generated from #def $search_type_checked($value) at line 3, col 1.
+        trans = KWS.get("trans")
+        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
+            trans = self.transaction # is None unless self.awake() was called
+        if not trans:
+            trans = DummyTransaction()
+            _dummyTrans = True
+        else: _dummyTrans = False
+        write = trans.response().write
+        SL = self._CHEETAH__searchList
+        _filter = self._CHEETAH__currentFilter
+        
+        ########################################
+        ## START - generated method body
+        
+        if VFFSL(SL,"getVar",False)('search_type', '') == VFFSL(SL,"value",True): # generated from line 4, col 1
+            write(u'''checked''')
+        
+        ########################################
+        ## END - generated method body
+        
+        return _dummyTrans and trans.response().getvalue() or ""
+        
+
+    def case_sensitive_checked(self, **KWS):
+
+
+
+        ## CHEETAH: generated from #def $case_sensitive_checked at line 8, col 1.
+        trans = KWS.get("trans")
+        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
+            trans = self.transaction # is None unless self.awake() was called
+        if not trans:
+            trans = DummyTransaction()
+            _dummyTrans = True
+        else: _dummyTrans = False
+        write = trans.response().write
+        SL = self._CHEETAH__searchList
+        _filter = self._CHEETAH__currentFilter
+        
+        ########################################
+        ## START - generated method body
+        
+        if VFFSL(SL,"getVar",False)('case_sensitive', None): # generated from line 9, col 1
+            write(u'''checked''')
+        
+        ########################################
+        ## END - generated method body
+        
+        return _dummyTrans and trans.response().getvalue() or ""
+        
+
     def respond(self, trans=None):
 
 
@@ -85,16 +142,31 @@ class search_authors_form(Template):
         ## START - generated method body
         
         write(u'''<form action="/search_authors/" method="POST">
-  <input name="search_authors" type="text" style="width: 80%">
+  <input name="search_authors" value="''')
+        _v = VFFSL(SL,"html_escape",False)(VFFSL(SL,"getVar",False)('search_authors', '')) # u"$html_escape($getVar('search_authors', ''))" on line 14, col 39
+        if _v is not None: write(_filter(_v, rawExpr=u"$html_escape($getVar('search_authors', ''))")) # from line 14, col 39.
+        write(u'''" type="text" style="width: 80%">
   <br>
-  <input name="search_type" value="start" type="radio">
+  <input name="search_type" value="start" ''')
+        _v = VFFSL(SL,"search_type_checked",False)('start') # u"$search_type_checked('start')" on line 16, col 43
+        if _v is not None: write(_filter(_v, rawExpr=u"$search_type_checked('start')")) # from line 16, col 43.
+        write(u''' type="radio">
   \u041f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435
-  <input name="search_type" value="substring" type="radio">
+  <input name="search_type" value="substring" ''')
+        _v = VFFSL(SL,"search_type_checked",False)('substring') # u"$search_type_checked('substring')" on line 18, col 47
+        if _v is not None: write(_filter(_v, rawExpr=u"$search_type_checked('substring')")) # from line 18, col 47.
+        write(u''' type="radio">
   \u041f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430
-  <input name="search_type" value="full" type="radio">
+  <input name="search_type" value="full" ''')
+        _v = VFFSL(SL,"search_type_checked",False)('full') # u"$search_type_checked('full')" on line 20, col 42
+        if _v is not None: write(_filter(_v, rawExpr=u"$search_type_checked('full')")) # from line 20, col 42.
+        write(u''' type="radio">
   \u0422\u043e\u0447\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435
   <br>
-  <input name="case_sensitive" type="checkbox">
+  <input name="case_sensitive" type="checkbox" ''')
+        _v = VFFSL(SL,"case_sensitive_checked",True) # u'$case_sensitive_checked' on line 23, col 48
+        if _v is not None: write(_filter(_v, rawExpr=u'$case_sensitive_checked')) # from line 23, col 48.
+        write(u'''>
   \u0420\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u043d\u044b\u0435/\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0435
   <br>
   <input name="submit" type="submit">
index ec731552518d70a1a90d044d40ebfe243e2d9c66..c3aa07ce027ed8fe7c8f9fcfd43255e8100edd58 100644 (file)
@@ -1,15 +1,26 @@
 #encoding utf-8
+#from bottle import html_escape
+#def $search_type_checked($value)
+#if $getVar('search_type', '') == $value
+checked#slurp
+#end if
+#end def
+#def $case_sensitive_checked
+#if $getVar('case_sensitive', None)
+checked#slurp
+#end if
+#end def
 <form action="/search_authors/" method="POST">
-  <input name="search_authors" type="text" style="width: 80%">
+  <input name="search_authors" value="$html_escape($getVar('search_authors', ''))" type="text" style="width: 80%">
   <br>
-  <input name="search_type" value="start" type="radio">
+  <input name="search_type" value="start" $search_type_checked('start') type="radio">
   Подстрока в начале
-  <input name="search_type" value="substring" type="radio">
+  <input name="search_type" value="substring" $search_type_checked('substring') type="radio">
   Подстрока
-  <input name="search_type" value="full" type="radio">
+  <input name="search_type" value="full" $search_type_checked('full') type="radio">
   Точное совпадение
   <br>
-  <input name="case_sensitive" type="checkbox">
+  <input name="case_sensitive" type="checkbox" $case_sensitive_checked>
   Различать прописные/строчные
   <br>
   <input name="submit" type="submit">