cli/main: add command to show borrowed/queued items, move `list_bookcases` to advanced
This commit is contained in:
parent
b3f80888d5
commit
fa180ca354
|
@ -61,26 +61,6 @@ class WorblehatCli(NumberedCmd):
|
|||
exit(0)
|
||||
|
||||
|
||||
def do_list_bookcases(self, _: str):
|
||||
bookcase_shelfs = self.sql_session.scalars(
|
||||
select(BookcaseShelf)
|
||||
.join(Bookcase)
|
||||
.order_by(
|
||||
Bookcase.name,
|
||||
BookcaseShelf.column,
|
||||
BookcaseShelf.row,
|
||||
)
|
||||
).all()
|
||||
|
||||
bookcase_uid = None
|
||||
for shelf in bookcase_shelfs:
|
||||
if shelf.bookcase.uid != bookcase_uid:
|
||||
print(shelf.bookcase.short_str())
|
||||
bookcase_uid = shelf.bookcase.uid
|
||||
|
||||
print(f' {shelf.short_str()} - {sum(i.amount for i in shelf.items)} items')
|
||||
|
||||
|
||||
def do_show_bookcase(self, arg: str):
|
||||
bookcase_selector = InteractiveItemSelector(
|
||||
cls = Bookcase,
|
||||
|
@ -95,6 +75,35 @@ class WorblehatCli(NumberedCmd):
|
|||
print(f' {item.name} - {item.amount} copies')
|
||||
|
||||
|
||||
def do_show_borrowed_queued(self, _: str):
|
||||
borrowed_items = self.sql_session.scalars(
|
||||
select(BookcaseItemBorrowing)
|
||||
.where(BookcaseItemBorrowing.delivered.is_(None))
|
||||
.order_by(BookcaseItemBorrowing.end_time),
|
||||
).all()
|
||||
|
||||
if len(borrowed_items) == 0:
|
||||
print('No borrowed items found.')
|
||||
else:
|
||||
print('Borrowed items:')
|
||||
for item in borrowed_items:
|
||||
print(f'- {item.username} - {item.item.name} - to be delivered by {item.end_time.strftime("%Y-%m-%d")}')
|
||||
|
||||
print()
|
||||
|
||||
queued_items = self.sql_session.scalars(
|
||||
select(BookcaseItemBorrowingQueue)
|
||||
.order_by(BookcaseItemBorrowingQueue.entered_queue_time),
|
||||
).all()
|
||||
|
||||
if len(queued_items) == 0:
|
||||
print('No queued items found.')
|
||||
else:
|
||||
print('Users in queue:')
|
||||
for item in queued_items:
|
||||
print(f'- {item.username} - {item.item.name} - entered queue at {item.entered_queue_time.strftime("%Y-%m-%d")}')
|
||||
|
||||
|
||||
def _create_bookcase_item(self, isbn: str):
|
||||
bookcase_item = create_bookcase_item_from_isbn(isbn, self.sql_session)
|
||||
if bookcase_item is None:
|
||||
|
@ -149,6 +158,8 @@ class WorblehatCli(NumberedCmd):
|
|||
if (existing_item := self.sql_session.scalars(
|
||||
select(BookcaseItem)
|
||||
.where(BookcaseItem.isbn == isbn)
|
||||
.join(BookcaseItemBorrowing)
|
||||
.join(BookcaseItemBorrowingQueue)
|
||||
).one_or_none()) is not None:
|
||||
print(f'\nFound existing item for isbn "{isbn}"')
|
||||
BookcaseItemCli(
|
||||
|
@ -185,11 +196,12 @@ class WorblehatCli(NumberedCmd):
|
|||
).all()
|
||||
|
||||
if len(slubberter) == 0:
|
||||
print('No slubberts found. Yay!')
|
||||
print('No slubberts found. Life is good.')
|
||||
return
|
||||
|
||||
for slubbert in slubberter:
|
||||
print(f'{slubbert.username} - {slubbert.item.name} - {slubbert.end_time.strftime("%Y-%m-%d")}')
|
||||
print('Slubberter:')
|
||||
print(f'- {slubbert.username} - {slubbert.item.name} - {slubbert.end_time.strftime("%Y-%m-%d")}')
|
||||
|
||||
|
||||
def do_advanced(self, _: str):
|
||||
|
@ -225,20 +237,20 @@ class WorblehatCli(NumberedCmd):
|
|||
'doc': 'Choose / Add item with its ISBN',
|
||||
},
|
||||
1: {
|
||||
'f': do_list_bookcases,
|
||||
'doc': 'List all bookcases',
|
||||
},
|
||||
2: {
|
||||
'f': do_search,
|
||||
'doc': 'Search',
|
||||
},
|
||||
3: {
|
||||
2: {
|
||||
'f': do_show_bookcase,
|
||||
'doc': 'Show a bookcase, and its items',
|
||||
},
|
||||
3: {
|
||||
'f': do_show_borrowed_queued,
|
||||
'doc': 'Show borrowed/queued items',
|
||||
},
|
||||
4: {
|
||||
'f': do_show_slabbedasker,
|
||||
'doc': 'Show a slabbedasker, and their wicked ways',
|
||||
'doc': 'Show slabbedasker',
|
||||
},
|
||||
5: {
|
||||
'f': do_save,
|
||||
|
|
|
@ -91,6 +91,26 @@ class AdvancedOptionsCli(NumberedCmd):
|
|||
self.sql_session.flush()
|
||||
|
||||
|
||||
def do_list_bookcases(self, _: str):
|
||||
bookcase_shelfs = self.sql_session.scalars(
|
||||
select(BookcaseShelf)
|
||||
.join(Bookcase)
|
||||
.order_by(
|
||||
Bookcase.name,
|
||||
BookcaseShelf.column,
|
||||
BookcaseShelf.row,
|
||||
)
|
||||
).all()
|
||||
|
||||
bookcase_uid = None
|
||||
for shelf in bookcase_shelfs:
|
||||
if shelf.bookcase.uid != bookcase_uid:
|
||||
print(shelf.bookcase.short_str())
|
||||
bookcase_uid = shelf.bookcase.uid
|
||||
|
||||
print(f' {shelf.short_str()} - {sum(i.amount for i in shelf.items)} items')
|
||||
|
||||
|
||||
def do_done(self, _: str):
|
||||
return True
|
||||
|
||||
|
@ -104,6 +124,10 @@ class AdvancedOptionsCli(NumberedCmd):
|
|||
'f': do_add_bookcase_shelf,
|
||||
'doc': 'Add bookcase shelf',
|
||||
},
|
||||
3: {
|
||||
'f': do_list_bookcases,
|
||||
'doc': 'List all bookcases',
|
||||
},
|
||||
9: {
|
||||
'f': do_done,
|
||||
'doc': 'Done',
|
||||
|
|
Loading…
Reference in New Issue