A few small improvements:

- Add missing flushes to cli
- Update README TODOs
- Add some documentation comments
- Rename AdvancedOptions -> AdvancedOptionsCli
This commit is contained in:
Oystein Kristoffer Tveit 2023-05-12 02:30:44 +02:00
parent fad38adc50
commit 18a1667b7b
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
7 changed files with 30 additions and 7 deletions

View File

@ -62,6 +62,7 @@ See `worblehat/config.py` for configurable settings.
- [X] Ability to queue book loans for PVV members - [X] Ability to queue book loans for PVV members
- [ ] Ability to be notified when books are available - [ ] Ability to be notified when books are available
- [ ] Ability to be notified when deadlines are due - [ ] 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 - [ ] Ascii art of monkey
- [ ] Low priority: - [ ] Low priority:
- [ ] Ability for PVV members to request book loans through the PVV website - [ ] Ability for PVV members to request book loans through the PVV website
@ -69,3 +70,4 @@ See `worblehat/config.py` for configurable settings.
- [ ] Discussion - [ ] 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? - [ ] 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. 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

View File

@ -15,7 +15,7 @@ from worblehat.models import *
from .prompt_utils import * from .prompt_utils import *
from .subclis import ( from .subclis import (
AdvancedOptions, AdvancedOptionsCli,
BookcaseItemCli, BookcaseItemCli,
select_bookcase_shelf, select_bookcase_shelf,
) )
@ -165,7 +165,7 @@ class WorblehatCli(NumberedCmd):
def do_advanced(self, _: str): def do_advanced(self, _: str):
AdvancedOptions(self.sql_session).cmdloop() AdvancedOptionsCli(self.sql_session).cmdloop()
def do_save(self, _:str): def do_save(self, _:str):

View File

@ -1,3 +1,3 @@
from .advanced_options import AdvancedOptions from .advanced_options import AdvancedOptionsCli
from .bookcase_item import BookcaseItemCli from .bookcase_item import BookcaseItemCli
from .bookcase_shelf_selector import select_bookcase_shelf from .bookcase_shelf_selector import select_bookcase_shelf

View File

@ -9,7 +9,7 @@ from worblehat.cli.prompt_utils import (
) )
from worblehat.models import Bookcase, BookcaseShelf from worblehat.models import Bookcase, BookcaseShelf
class AdvancedOptions(NumberedCmd): class AdvancedOptionsCli(NumberedCmd):
def __init__(self, sql_session: Session): def __init__(self, sql_session: Session):
super().__init__() super().__init__()
self.sql_session = sql_session self.sql_session = sql_session

View File

@ -53,6 +53,7 @@ class BookcaseItemCli(NumberedCmd):
# TODO: Remove any old authors # TODO: Remove any old authors
self.bookcase_item.authors = item.authors self.bookcase_item.authors = item.authors
self.bookcase_item.language = item.language self.bookcase_item.language = item.language
self.sql_session.flush()
def do_edit(self, arg: str): def do_edit(self, arg: str):
@ -134,7 +135,8 @@ class BookcaseItemCli(NumberedCmd):
borrowing_item = BookcaseItemBorrowing(username, self.bookcase_item) borrowing_item = BookcaseItemBorrowing(username, self.bookcase_item)
self.sql_session.add(borrowing_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): def do_deliver(self, _: str):
borrowings = self.sql_session.scalars( borrowings = self.sql_session.scalars(
@ -166,7 +168,7 @@ class BookcaseItemCli(NumberedCmd):
break break
borrowing = borrowings[selection - 1] borrowing = borrowings[selection - 1]
borrowing.delivered = True self.sql_session.flush()
print(f'Successfully delivered the item for {borrowing.username}') print(f'Successfully delivered the item for {borrowing.username}')
@ -224,6 +226,7 @@ class EditBookcaseCli(NumberedCmd):
break break
self.bookcase_item.name = name self.bookcase_item.name = name
self.sql_session.flush()
def do_isbn(self, _: str): def do_isbn(self, _: str):
@ -250,6 +253,7 @@ class EditBookcaseCli(NumberedCmd):
if prompt_yes_no('Update data from online databases?'): if prompt_yes_no('Update data from online databases?'):
self.parent.do_update_data('') self.parent.do_update_data('')
self.sql_session.flush()
def do_language(self, _: str): def do_language(self, _: str):
@ -259,6 +263,7 @@ class EditBookcaseCli(NumberedCmd):
) )
self.bookcase_item.language = language_selector.result self.bookcase_item.language = language_selector.result
self.sql_session.flush()
def do_media_type(self, _: str): def do_media_type(self, _: str):
@ -268,6 +273,7 @@ class EditBookcaseCli(NumberedCmd):
) )
self.bookcase_item.media_type = media_type_selector.result self.bookcase_item.media_type = media_type_selector.result
self.sql_session.flush()
def do_amount(self, _: str): def do_amount(self, _: str):
@ -284,6 +290,7 @@ class EditBookcaseCli(NumberedCmd):
break break
self.bookcase_item.amount = new_amount self.bookcase_item.amount = new_amount
self.sql_session.flush()
def do_shelf(self, _: str): def do_shelf(self, _: str):
@ -297,6 +304,7 @@ class EditBookcaseCli(NumberedCmd):
shelf = select_bookcase_shelf(bookcase, self.sql_session) shelf = select_bookcase_shelf(bookcase, self.sql_session)
self.bookcase_item.shelf = shelf self.bookcase_item.shelf = shelf
self.sql_session.flush()
def do_done(self, _: str): def do_done(self, _: str):

View File

@ -16,12 +16,14 @@ def is_valid_pvv_isbn(isbn: str) -> bool:
return False return False
return len(isbn) == 8 return len(isbn) == 8
def is_valid_isbn(isbn: str) -> bool: def is_valid_isbn(isbn: str) -> bool:
return any([ return any([
isbnlib.is_isbn10(isbn), isbnlib.is_isbn10(isbn),
isbnlib.is_isbn13(isbn), isbnlib.is_isbn13(isbn),
]) ])
def create_bookcase_item_from_isbn(isbn: str, sql_session: Session) -> BookcaseItem | None: def create_bookcase_item_from_isbn(isbn: str, sql_session: Session) -> BookcaseItem | None:
metadata = isbnlib.meta(isbn, 'openl') metadata = isbnlib.meta(isbn, 'openl')
if len(metadata.keys()) == 0: if len(metadata.keys()) == 0:

View File

@ -5,6 +5,17 @@ from pprint import pformat
class Config: 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 _config = None
_expected_config_file_locations = [ _expected_config_file_locations = [
Path('./config.toml'), Path('./config.toml'),