From ecd2349c26418c8b55ec9e0d17009321b6472236 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 11 Jun 2018 01:52:26 +0300 Subject: [PATCH] Feat(web): Configure columns for author and book tables --- docs-ru/news.rst | 2 + docs/news.rst | 2 + m_librarian/web/app.py | 9 +++- m_librarian/web/views/books_by_author.py | 51 ++++++++++--------- m_librarian/web/views/books_by_author.tmpl | 9 ++-- m_librarian/web/views/list_authors.py | 44 +++++++++-------- m_librarian/web/views/list_authors.tmpl | 7 ++- m_librarian/web/views/list_books.py | 57 ++++++++++++---------- m_librarian/web/views/list_books.tmpl | 9 ++-- sample/m_librarian.conf | 10 ++++ 10 files changed, 126 insertions(+), 74 deletions(-) diff --git a/docs-ru/news.rst b/docs-ru/news.rst index 558bc5c..39c5ba0 100644 --- a/docs-ru/news.rst +++ b/docs-ru/news.rst @@ -8,6 +8,8 @@ Version 0.1.4 (2018-05-??) * Показывать список найденных книг с разбивкой по авторам и сериям. +* Конфигурация списка колонок для таблиц авторов и книг. + * Файл конфигурации, все секции и все ключи сделаны необязательными. * В файле конфигурации подставляются переменные окружения в ключах, diff --git a/docs/news.rst b/docs/news.rst index 8fd1e7b..d9dfd72 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -8,6 +8,8 @@ Version 0.1.4 (2018-06-??) * Use filters from config. +* Configure columns for author and book tables. + * Config file, all sections and all key are now completely optional. * Environment variables are expanded in paths in config file. diff --git a/m_librarian/web/app.py b/m_librarian/web/app.py index 42c5c5a..5d9285e 100644 --- a/m_librarian/web/app.py +++ b/m_librarian/web/app.py @@ -59,11 +59,13 @@ def search_authors_post(): )] authors = search_authors(search_type, case_sensitive, {}, expressions, orderBy=('surname', 'name', 'misc_name')) + columns = get_config().getlist('columns', 'author', ['fullname']) return { 'authors': list(authors), 'search_authors': value, 'search_type': search_type, 'case_sensitive': case_sensitive, + 'columns': columns, } @@ -71,6 +73,7 @@ def search_authors_post(): @cheetah_view('books_by_author.tmpl') def books_by_author(id): use_filters = get_config().getint('filters', 'use_in_books_list', 1) + columns = get_config().getlist('columns', 'book', ['title']) if use_filters: join_expressions = [] join_expressions.append(Book.j.authors) @@ -81,6 +84,7 @@ def books_by_author(id): return { 'author': Author.get(id), 'books': books, + 'columns': columns, } else: return { @@ -88,7 +92,8 @@ def books_by_author(id): 'books': Book.select( Book.j.authors & (Author.q.id == id), orderBy=['series', 'ser_no', 'title'], - ) + ), + 'columns': columns, } @@ -157,9 +162,11 @@ def search_books_post(): else: books_by_author = books_by_authors[author] = [] books_by_author.append(book) + columns = get_config().getlist('columns', 'book', ['title']) return { 'books_by_author': books_by_authors, 'search_books': value, 'search_type': search_type, 'case_sensitive': case_sensitive, + 'columns': columns, } diff --git a/m_librarian/web/views/books_by_author.py b/m_librarian/web/views/books_by_author.py index b57790c..8136ece 100644 --- a/m_librarian/web/views/books_by_author.py +++ b/m_librarian/web/views/books_by_author.py @@ -36,10 +36,10 @@ VFN=valueForName currentTime=time.time __CHEETAH_version__ = '3.1.0' __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1) -__CHEETAH_genTime__ = 1528661355.623041 -__CHEETAH_genTimestamp__ = 'Sun Jun 10 23:09:15 2018' +__CHEETAH_genTime__ = 1528670845.131662 +__CHEETAH_genTimestamp__ = 'Mon Jun 11 01:47:25 2018' __CHEETAH_src__ = 'books_by_author.tmpl' -__CHEETAH_srcLastModified__ = 'Sun Jun 10 23:09:14 2018' +__CHEETAH_srcLastModified__ = 'Mon Jun 11 01:47:23 2018' __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine' if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple: @@ -101,41 +101,48 @@ class books_by_author(layout): ''') series = None - for book in VFFSL(SL,"books",True): # generated from line 12, col 3 - if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 13, col 3 + columns1 = VFFSL(SL,"len",False)(VFFSL(SL,"columns",True))+1 + for book in VFFSL(SL,"books",True): # generated from line 13, col 3 + if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 14, col 3 series = VFFSL(SL,"book.series",True) write(u''' - ''') write(u''' - - +''') + for column in VFFSL(SL,"columns",True): # generated from line 28, col 3 + write(u''' +''') + write(u''' ''') write(u''' - +
+ ''') - if VFFSL(SL,"book.series",True): # generated from line 17, col 3 - _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 18, col 1 - if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 18, col 1. - else: # generated from line 19, col 3 + if VFFSL(SL,"book.series",True): # generated from line 18, col 3 + _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 19, col 1 + if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 19, col 1. + else: # generated from line 20, col 3 write(u'''\u0412\u043d\u0435 \u0441\u0435\u0440\u0438\u0439''') write(u'''
''') - _v = VFFSL(SL,"book.ser_no",True) # u'$book.ser_no' on line 27, col 7 - if _v is not None: write(_filter(_v, rawExpr=u'$book.ser_no')) # from line 27, col 7. - write(u''' ''') - _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"book.title",True)) # u'$cgi.escape($book.title)' on line 27, col 20 - if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($book.title)')) # from line 27, col 20. - write(u'''
''') + _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 29, col 7 + if _v is not None: write(_filter(_v, rawExpr=u"$cgi.escape(unicode($getattr($book, $column) or ''))")) # from line 29, col 7. + write(u'''
''') - else: # generated from line 35, col 1 + else: # generated from line 38, col 1 write(u'''

\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438!

''') diff --git a/m_librarian/web/views/books_by_author.tmpl b/m_librarian/web/views/books_by_author.tmpl index 61db03c..52a7eb3 100644 --- a/m_librarian/web/views/books_by_author.tmpl +++ b/m_librarian/web/views/books_by_author.tmpl @@ -9,11 +9,12 @@
#set $series = None + #set $columns1 = $len($columns)+1 #for $book in $books #if $book.series != $series #set $series = $book.series - - + #for $column in $columns + + #end for #end for - +
+ #if $book.series $cgi.escape($series, 1)#slurp #else @@ -24,11 +25,13 @@ $cgi.escape($series, 1)#slurp #end if
$book.ser_no $cgi.escape($book.title)$cgi.escape(unicode($getattr($book, $column) or ''))
diff --git a/m_librarian/web/views/list_authors.py b/m_librarian/web/views/list_authors.py index 5c70204..5ee4af0 100644 --- a/m_librarian/web/views/list_authors.py +++ b/m_librarian/web/views/list_authors.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 +import cgi from views.layout import layout from views.search_authors_form import search_authors_form @@ -36,10 +37,10 @@ VFN=valueForName currentTime=time.time __CHEETAH_version__ = '3.1.0' __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1) -__CHEETAH_genTime__ = 1523134510.111994 -__CHEETAH_genTimestamp__ = 'Sat Apr 7 23:55:10 2018' +__CHEETAH_genTime__ = 1528670903.492958 +__CHEETAH_genTimestamp__ = 'Mon Jun 11 01:48:23 2018' __CHEETAH_src__ = 'list_authors.tmpl' -__CHEETAH_srcLastModified__ = 'Sat Apr 7 23:55:07 2018' +__CHEETAH_srcLastModified__ = 'Mon Jun 11 01:48:21 2018' __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine' if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple: @@ -72,7 +73,7 @@ class list_authors(layout): - ## CHEETAH: generated from #def body at line 4, col 1. + ## CHEETAH: generated from #def body at line 5, 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 @@ -89,33 +90,38 @@ class list_authors(layout): 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. + _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'''

''') - _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. + _v = VFFSL(SL,"title",True) # u'$title' on line 10, col 5 + if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 10, col 5. write(u'''

''') - if VFFSL(SL,"authors",True): # generated from line 11, col 1 + if VFFSL(SL,"authors",True): # generated from line 12, col 1 write(u''' ''') - for author in VFFSL(SL,"authors",True): # generated from line 13, col 3 + for author in VFFSL(SL,"authors",True): # generated from line 14, col 3 write(u''' - - +''') + for column in VFFSL(SL,"columns",True): # generated from line 16, col 3 + write(u''' +''') + write(u''' ''') write(u'''
''') - _v = VFFSL(SL,"author.fullname",True) # u'$author.fullname' on line 15, col 48 - if _v is not None: write(_filter(_v, rawExpr=u'$author.fullname')) # from line 15, col 48. - write(u'''
+ ''') + _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(unicode(VFFSL(SL,"getattr",False)(VFFSL(SL,"author",True), VFFSL(SL,"column",True)) or '')) # u"$cgi.escape(unicode($getattr($author, $column) or ''))" on line 18, col 5 + if _v is not None: write(_filter(_v, rawExpr=u"$cgi.escape(unicode($getattr($author, $column) or ''))")) # from line 18, col 5. + write(u''' +
''') - else: # generated from line 19, col 1 + else: # generated from line 24, 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 f7377ba..a872afc 100644 --- a/m_librarian/web/views/list_authors.tmpl +++ b/m_librarian/web/views/list_authors.tmpl @@ -1,4 +1,5 @@ #encoding utf-8 +#import cgi #extends views.layout #attr $title = 'Список авторов' #def body @@ -12,7 +13,11 @@ $search_authors_form(searchList=$searchList) #for $author in $authors - + #for $column in $columns + + #end for #end for
$author.fullname + $cgi.escape(unicode($getattr($author, $column) or '')) +
diff --git a/m_librarian/web/views/list_books.py b/m_librarian/web/views/list_books.py index 7431a3a..0b2f8c6 100644 --- a/m_librarian/web/views/list_books.py +++ b/m_librarian/web/views/list_books.py @@ -36,10 +36,10 @@ VFN=valueForName currentTime=time.time __CHEETAH_version__ = '3.1.0' __CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1) -__CHEETAH_genTime__ = 1528661355.731921 -__CHEETAH_genTimestamp__ = 'Sun Jun 10 23:09:15 2018' +__CHEETAH_genTime__ = 1528670845.332275 +__CHEETAH_genTimestamp__ = 'Mon Jun 11 01:47:25 2018' __CHEETAH_src__ = 'list_books.tmpl' -__CHEETAH_srcLastModified__ = 'Sun Jun 10 23:09:01 2018' +__CHEETAH_srcLastModified__ = 'Mon Jun 11 01:46:57 2018' __CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine' if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple: @@ -98,47 +98,54 @@ class list_books(layout): ''') series = None - for author in VFFSL(SL,"sorted",False)(VFFSL(SL,"books_by_author",True)): # generated from line 12, col 3 + columns1 = VFFSL(SL,"len",False)(VFFSL(SL,"columns",True))+1 + for author in VFFSL(SL,"sorted",False)(VFFSL(SL,"books_by_author",True)): # generated from line 13, col 3 books = VFFSL(SL,"books_by_author",True)[VFFSL(SL,"author",True)] - for book in VFFSL(SL,"books",True): # generated from line 14, col 5 - if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 15, col 5 + for book in VFFSL(SL,"books",True): # generated from line 15, col 5 + if VFFSL(SL,"book.series",True) != VFFSL(SL,"series",True): # generated from line 16, col 5 series = VFFSL(SL,"book.series",True) write(u''' - ''') write(u''' - - +''') + for column in VFFSL(SL,"columns",True): # generated from line 31, col 3 + write(u''' +''') + write(u''' ''') write(u''' - +
+ ''') - _v = VFFSL(SL,"author",True) # u'$author' on line 19, col 3 - if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 19, col 3. + _v = VFFSL(SL,"author",True) # u'$author' on line 20, col 3 + if _v is not None: write(_filter(_v, rawExpr=u'$author')) # from line 20, col 3. write(u''' \u2014 ''') - if VFFSL(SL,"book.series",True): # generated from line 20, col 3 - _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 21, col 1 - if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 21, col 1. - else: # generated from line 22, col 3 + if VFFSL(SL,"book.series",True): # generated from line 21, col 3 + _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"series",True), 1) # u'$cgi.escape($series, 1)' on line 22, col 1 + if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($series, 1)')) # from line 22, col 1. + else: # generated from line 23, col 3 write(u'''\u0412\u043d\u0435 \u0441\u0435\u0440\u0438\u0439''') write(u'''
''') - _v = VFFSL(SL,"book.ser_no",True) # u'$book.ser_no' on line 30, col 7 - if _v is not None: write(_filter(_v, rawExpr=u'$book.ser_no')) # from line 30, col 7. - write(u''' ''') - _v = VFN(VFFSL(SL,"cgi",True),"escape",False)(VFFSL(SL,"book.title",True)) # u'$cgi.escape($book.title)' on line 30, col 20 - if _v is not None: write(_filter(_v, rawExpr=u'$cgi.escape($book.title)')) # from line 30, col 20. - write(u'''
''') + _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 32, col 7 + if _v is not None: write(_filter(_v, rawExpr=u"$cgi.escape(unicode($getattr($book, $column) or ''))")) # from line 32, col 7. + write(u'''
''') - else: # generated from line 39, col 1 + else: # generated from line 42, col 1 write(u'''

\u041d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438!

''') diff --git a/m_librarian/web/views/list_books.tmpl b/m_librarian/web/views/list_books.tmpl index 649922b..5822ce2 100644 --- a/m_librarian/web/views/list_books.tmpl +++ b/m_librarian/web/views/list_books.tmpl @@ -9,13 +9,14 @@
#set $series = None + #set $columns1 = $len($columns)+1 #for $author in $sorted($books_by_author) #set $books = $books_by_author[$author] #for $book in $books #if $book.series != $series #set $series = $book.series - - + #for $column in $columns + + #end for #end for #end for - +
+ $author — #if $book.series $cgi.escape($series, 1)#slurp @@ -27,12 +28,14 @@ $cgi.escape($series, 1)#slurp #end if
$book.ser_no $cgi.escape($book.title)$cgi.escape(unicode($getattr($book, $column) or ''))
diff --git a/sample/m_librarian.conf b/sample/m_librarian.conf index cc8f3f5..9cbf395 100644 --- a/sample/m_librarian.conf +++ b/sample/m_librarian.conf @@ -25,6 +25,16 @@ use_in_search_forms = 1 # Use filters in lists of books use_in_books_list = 1 +[columns] +# Full list of author columns: +# columns = surname name misc_name fullname count +# Default column is fullname +author = fullname count +# Full list of book columns: +# columns = title series ser_no archive file size lib_id deleted date +# Default column is just title +book = ser_no title + [download] # Download formats: # %a - author (one of) -- 2.39.2