Skip to content

Commit 44d8851

Browse files
committed
Fix saving listing changes in TUI
- The actual issue was that save_listing db method requires release_id which is not allowed to be empty in the db, even though actually the DB schema has been corrected. - Get listing details from DB, rather than Discogs. Speeds up but was not the issue. - Fix an issue where placeholder for price is a string. Remove placeholder entirely. - Contains some useless passing of release_id - not sure where anymore. Screw it.
1 parent 266ffbe commit 44d8851

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

discodos/ctrl/tui.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ def action_edit_sales_listing(self):
9494
"""Open the edit screen for a sales listing."""
9595
row_key, _ = self.table.coordinate_to_cell_key(self.table.cursor_coordinate)
9696
listing_id = self.table.get_cell(row_key, "d_sales_listing_id")
97-
listing, l_err, _ = self.fetch_sales_listing_details(listing_id, tui_view=True)
98-
if l_err:
99-
self.rlog.write(f"Error fetching sales listing details: {l_err}")
100-
return
97+
release_id = self.table.get_cell(row_key, "discogs_id")
98+
listing = self.collection.get_sales_listing_details(listing_id)
99+
if not listing:
100+
self.rlog.write("Error getting sales listing from DiscoBASE.")
101101

102102
def save_changes(**kwargs):
103103
if not self.collection.update_sales_listing(
@@ -113,6 +113,7 @@ def save_changes(**kwargs):
113113
return
114114

115115
listing["d_sales_listing_id"] = listing_id
116+
listing["d_sales_release_id"] = release_id
116117
created = self.collection.create_sales_entry(listing)
117118
if not created:
118119
self.rlog.write("Updating sales entry in DiscoBASE failed")
@@ -141,6 +142,7 @@ def save_changes(**kwargs):
141142
EditScreen(
142143
save_changes,
143144
listing_id=listing_id,
145+
release_id=listing["d_sales_release_id"],
144146
price=listing["d_sales_price"],
145147
condition=listing["d_sales_condition"],
146148
sleeve_condition=listing["d_sales_sleeve_condition"],

discodos/ctrl/tui_edit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(
1717
self,
1818
on_save,
1919
listing_id,
20+
release_id,
2021
price,
2122
condition,
2223
sleeve_condition,
@@ -28,8 +29,9 @@ def __init__(
2829
):
2930
super().__init__()
3031
self.caption = listing_id
32+
self.release_id = release_id # required for saving
3133
# Initialize text based fields with existing or default values
32-
self.price = Input(value=price or "", placeholder="Price")
34+
self.price = Input(str(price))
3335
self.location = Input(value=location or "", placeholder="Location")
3436
self.comments = Input(value=comments or "", placeholder="Public comments")
3537
self.comments_private = Input(value=comments_private or "",
@@ -94,6 +96,7 @@ def on_button_pressed(self, event):
9496
status = self.query_one("#status")
9597
allow_offers = self.query_one("#allow_offers")
9698
self.on_save(
99+
release_id=self.release_id,
97100
price=self.price.value,
98101
condition=condition.pressed_button.name,
99102
sleeve_condition=sleeve_condition.pressed_button.name,

discodos/model/discogs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def list_for_sale( # pylint: disable=too-many-positional-arguments,too-many-arg
398398
def update_sales_listing( # pylint: disable=too-many-positional-arguments,too-many-arguments
399399
self,
400400
listing_id=None,
401+
release_id=None,
401402
condition=None,
402403
sleeve_condition=None,
403404
price=None,
@@ -422,7 +423,11 @@ def update_sales_listing( # pylint: disable=too-many-positional-arguments,too-m
422423
listing.save()
423424
return True
424425
except Exception as Exc:
425-
log.error("Exception while trying to update Marketplace listing: %s", Exc)
426+
log.error(
427+
"Exception while trying to update Marketplace listing for release %s: %s",
428+
release_id,
429+
Exc,
430+
)
426431
return False
427432

428433
def remove_sales_listing(self, listing_id):

0 commit comments

Comments
 (0)