From ee485bf9817d65fb5b7641a6638b931cf7747b13 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 6 Apr 2018 00:03:30 +0300 Subject: [PATCH] Feat(web): Preserve values in form --- m_librarian/web/app.py | 7 +- m_librarian/web/views/index.py | 10 +-- m_librarian/web/views/index.tmpl | 2 +- m_librarian/web/views/layout.py | 6 +- m_librarian/web/views/list_authors.py | 29 +++--- m_librarian/web/views/list_authors.tmpl | 4 + m_librarian/web/views/search_authors.py | 10 +-- m_librarian/web/views/search_authors.tmpl | 2 +- m_librarian/web/views/search_authors_form.py | 88 +++++++++++++++++-- .../web/views/search_authors_form.tmpl | 21 +++-- 10 files changed, 139 insertions(+), 40 deletions(-) diff --git a/m_librarian/web/app.py b/m_librarian/web/app.py index e4677d3..638f152 100644 --- a/m_librarian/web/app.py +++ b/m_librarian/web/app.py @@ -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, + } diff --git a/m_librarian/web/views/index.py b/m_librarian/web/views/index.py index 1e4c4df..e039c2a 100644 --- a/m_librarian/web/views/index.py +++ b/m_librarian/web/views/index.py @@ -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'''

\u041f\u043e\u0438\u0441\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432

''') - _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''' ''') diff --git a/m_librarian/web/views/index.tmpl b/m_librarian/web/views/index.tmpl index 57c6b74..f8be6c7 100644 --- a/m_librarian/web/views/index.tmpl +++ b/m_librarian/web/views/index.tmpl @@ -5,5 +5,5 @@

Поиск авторов

#from views.search_authors_form import search_authors_form -$search_authors_form() +$search_authors_form(searchList=$searchList) #end def diff --git a/m_librarian/web/views/layout.py b/m_librarian/web/views/layout.py index 726e570..8bc236e 100644 --- a/m_librarian/web/views/layout.py +++ b/m_librarian/web/views/layout.py @@ -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: diff --git a/m_librarian/web/views/list_authors.py b/m_librarian/web/views/list_authors.py index f38c9c4..3c5245a 100644 --- a/m_librarian/web/views/list_authors.py +++ b/m_librarian/web/views/list_authors.py @@ -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'''

''') - _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'''

\u041f\u043e\u0438\u0441\u043a \u0430\u0432\u0442\u043e\u0440\u043e\u0432

+''') + _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''' + +

''') + _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'''

''') - if VFFSL(SL,"authors",True): # generated from line 7, col 1 + if VFFSL(SL,"authors",True): # generated from line 11, col 1 write(u''' ''') - 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''' ''') write(u'''
''') - _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'''
''') - else: # generated from line 15, col 1 + else: # generated from line 19, col 1 write(u'''

\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430!

''') diff --git a/m_librarian/web/views/list_authors.tmpl b/m_librarian/web/views/list_authors.tmpl index b0b20ad..9bb4176 100644 --- a/m_librarian/web/views/list_authors.tmpl +++ b/m_librarian/web/views/list_authors.tmpl @@ -2,6 +2,10 @@ #extends views.layout #attr $title = 'Список авторов' #def body +

Поиск авторов

+#from views.search_authors_form import search_authors_form +$search_authors_form(searchList=$searchList) +

$title

#if $authors diff --git a/m_librarian/web/views/search_authors.py b/m_librarian/web/views/search_authors.py index fdc4a4b..cfa9083 100644 --- a/m_librarian/web/views/search_authors.py +++ b/m_librarian/web/views/search_authors.py @@ -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''' ''') - _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''' ''') diff --git a/m_librarian/web/views/search_authors.tmpl b/m_librarian/web/views/search_authors.tmpl index b659f38..eb295c7 100644 --- a/m_librarian/web/views/search_authors.tmpl +++ b/m_librarian/web/views/search_authors.tmpl @@ -5,5 +5,5 @@

$title

#from views.search_authors_form import search_authors_form -$search_authors_form() +$search_authors_form(searchList=$searchList) #end def diff --git a/m_librarian/web/views/search_authors_form.py b/m_librarian/web/views/search_authors_form.py index 1e30443..8ab0a8b 100644 --- a/m_librarian/web/views/search_authors_form.py +++ b/m_librarian/web/views/search_authors_form.py @@ -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'''
- +
- + \u041f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 - + \u041f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0430 - + \u0422\u043e\u0447\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435
- + \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
diff --git a/m_librarian/web/views/search_authors_form.tmpl b/m_librarian/web/views/search_authors_form.tmpl index ec73155..c3aa07c 100644 --- a/m_librarian/web/views/search_authors_form.tmpl +++ b/m_librarian/web/views/search_authors_form.tmpl @@ -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 - +
- + Подстрока в начале - + Подстрока - + Точное совпадение
- + Различать прописные/строчные
-- 2.39.5