From 18a1667b7b5563c8619988bc5f33306308ae3800 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 12 May 2023 02:30:44 +0200 Subject: [PATCH] A few small improvements: - Add missing flushes to cli - Update README TODOs - Add some documentation comments - Rename AdvancedOptions -> AdvancedOptionsCli --- README.md | 4 +++- worblehat/cli/main.py | 4 ++-- worblehat/cli/subclis/__init__.py | 2 +- worblehat/cli/subclis/advanced_options.py | 2 +- worblehat/cli/subclis/bookcase_item.py | 12 ++++++++++-- worblehat/services/bookcase_item.py | 2 ++ worblehat/services/config.py | 11 +++++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2ca97ae..cf94a38 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,12 @@ See `worblehat/config.py` for configurable settings. - [X] Ability to queue book loans for PVV members - [ ] Ability to be notified when books are available - [ ] Ability to be notified when deadlines are due + - [ ] Ability to print PVV-specific labels for items without a label, or for any other reason needs a new one - [ ] Ascii art of monkey - [ ] Low priority: - [ ] Ability for PVV members to request book loans through the PVV website - [ ] Ability for PVV members to search for books through the PVV website - [ ] Discussion - [ ] Should this project run in a separate tty-instance on Dibblers interface, or should they share the tty with some kind of switching ability? - After some discussion with other PVV members, we came up with an idea where we run the programs in separate ttys, and use a set of large mechanical switches connected to a QMK-flashed microcontroller to switch between them. \ No newline at end of file + After some discussion with other PVV members, we came up with an idea where we run the programs in separate ttys, and use a set of large mechanical switches connected to a QMK-flashed microcontroller to switch between them. + - [ ] Workaround for not being able to represent items with same ISBN and different owner: if you are absolutely adamant about placing your item at PVV while still owning it, even though PVV already owns a copy of this item, please print out a new label with a "PVV-ISBN" for it \ No newline at end of file diff --git a/worblehat/cli/main.py b/worblehat/cli/main.py index 277d9b3..c82eb99 100644 --- a/worblehat/cli/main.py +++ b/worblehat/cli/main.py @@ -15,7 +15,7 @@ from worblehat.models import * from .prompt_utils import * from .subclis import ( - AdvancedOptions, + AdvancedOptionsCli, BookcaseItemCli, select_bookcase_shelf, ) @@ -165,7 +165,7 @@ class WorblehatCli(NumberedCmd): def do_advanced(self, _: str): - AdvancedOptions(self.sql_session).cmdloop() + AdvancedOptionsCli(self.sql_session).cmdloop() def do_save(self, _:str): diff --git a/worblehat/cli/subclis/__init__.py b/worblehat/cli/subclis/__init__.py index 4f714a8..2bef689 100644 --- a/worblehat/cli/subclis/__init__.py +++ b/worblehat/cli/subclis/__init__.py @@ -1,3 +1,3 @@ -from .advanced_options import AdvancedOptions +from .advanced_options import AdvancedOptionsCli from .bookcase_item import BookcaseItemCli from .bookcase_shelf_selector import select_bookcase_shelf \ No newline at end of file diff --git a/worblehat/cli/subclis/advanced_options.py b/worblehat/cli/subclis/advanced_options.py index 12c30ec..6cd7f1c 100644 --- a/worblehat/cli/subclis/advanced_options.py +++ b/worblehat/cli/subclis/advanced_options.py @@ -9,7 +9,7 @@ from worblehat.cli.prompt_utils import ( ) from worblehat.models import Bookcase, BookcaseShelf -class AdvancedOptions(NumberedCmd): +class AdvancedOptionsCli(NumberedCmd): def __init__(self, sql_session: Session): super().__init__() self.sql_session = sql_session diff --git a/worblehat/cli/subclis/bookcase_item.py b/worblehat/cli/subclis/bookcase_item.py index 795fed3..a27d714 100644 --- a/worblehat/cli/subclis/bookcase_item.py +++ b/worblehat/cli/subclis/bookcase_item.py @@ -53,6 +53,7 @@ class BookcaseItemCli(NumberedCmd): # TODO: Remove any old authors self.bookcase_item.authors = item.authors self.bookcase_item.language = item.language + self.sql_session.flush() def do_edit(self, arg: str): @@ -134,7 +135,8 @@ class BookcaseItemCli(NumberedCmd): borrowing_item = BookcaseItemBorrowing(username, self.bookcase_item) self.sql_session.add(borrowing_item) - print(f'Successfully delivered the item. Please deliver it back by {format_date(borrowing_item.end_time)}') + self.sql_session.flush() + print(f'Successfully borrowed the item. Please deliver it back by {format_date(borrowing_item.end_time)}') def do_deliver(self, _: str): borrowings = self.sql_session.scalars( @@ -166,7 +168,7 @@ class BookcaseItemCli(NumberedCmd): break borrowing = borrowings[selection - 1] - borrowing.delivered = True + self.sql_session.flush() print(f'Successfully delivered the item for {borrowing.username}') @@ -224,6 +226,7 @@ class EditBookcaseCli(NumberedCmd): break self.bookcase_item.name = name + self.sql_session.flush() def do_isbn(self, _: str): @@ -250,6 +253,7 @@ class EditBookcaseCli(NumberedCmd): if prompt_yes_no('Update data from online databases?'): self.parent.do_update_data('') + self.sql_session.flush() def do_language(self, _: str): @@ -259,6 +263,7 @@ class EditBookcaseCli(NumberedCmd): ) self.bookcase_item.language = language_selector.result + self.sql_session.flush() def do_media_type(self, _: str): @@ -268,6 +273,7 @@ class EditBookcaseCli(NumberedCmd): ) self.bookcase_item.media_type = media_type_selector.result + self.sql_session.flush() def do_amount(self, _: str): @@ -284,6 +290,7 @@ class EditBookcaseCli(NumberedCmd): break self.bookcase_item.amount = new_amount + self.sql_session.flush() def do_shelf(self, _: str): @@ -297,6 +304,7 @@ class EditBookcaseCli(NumberedCmd): shelf = select_bookcase_shelf(bookcase, self.sql_session) self.bookcase_item.shelf = shelf + self.sql_session.flush() def do_done(self, _: str): diff --git a/worblehat/services/bookcase_item.py b/worblehat/services/bookcase_item.py index 1e96e39..769c8c0 100644 --- a/worblehat/services/bookcase_item.py +++ b/worblehat/services/bookcase_item.py @@ -16,12 +16,14 @@ def is_valid_pvv_isbn(isbn: str) -> bool: return False return len(isbn) == 8 + def is_valid_isbn(isbn: str) -> bool: return any([ isbnlib.is_isbn10(isbn), isbnlib.is_isbn13(isbn), ]) + def create_bookcase_item_from_isbn(isbn: str, sql_session: Session) -> BookcaseItem | None: metadata = isbnlib.meta(isbn, 'openl') if len(metadata.keys()) == 0: diff --git a/worblehat/services/config.py b/worblehat/services/config.py index e2f4206..384b472 100644 --- a/worblehat/services/config.py +++ b/worblehat/services/config.py @@ -5,6 +5,17 @@ from pprint import pformat class Config: + """ + This class is a singleton which holds the configuration for the + application. It is initialized by calling `Config.load_configuration()` + with a dictionary of arguments. The arguments are usually the result + of calling `vars(arg_parser.parse_args())` where `arg_parser` i s the + argument parser from `worblehat/services/argument_parser.py`. + + The class also provides some utility functions for accessing several + kinds of values that depend on the configuration. + """ + _config = None _expected_config_file_locations = [ Path('./config.toml'),