From bd3c6fa0af3f78c5d6cdd02a26d44cb276b1c82b Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 26 Sep 2018 08:06:47 -0500 Subject: [PATCH] Shops selling 0 items for a price now go to the bottom of the ?selling list --- geoffrey/DatabaseModels.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/geoffrey/DatabaseModels.py b/geoffrey/DatabaseModels.py index 87417a7..cf03bb9 100644 --- a/geoffrey/DatabaseModels.py +++ b/geoffrey/DatabaseModels.py @@ -1,11 +1,12 @@ import enum from difflib import SequenceMatcher +from sys import maxsize from sqlalchemy import Column, Integer, String, ForeignKey, Enum, create_engine, exists from sqlalchemy.exc import IntegrityError, DataError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, column_property, sessionmaker -from sqlalchemy.sql import expression +from sqlalchemy.sql import expression, case from sqlalchemy.ext.hybrid import hybrid_property from geoffrey.BotErrors import * @@ -252,7 +253,6 @@ class Shop(Location): } def inv_to_str(self): - if len(self.inventory.limit(25).all()) != 0: inv = '\n**Inventory**:' str_format = '{}\n{}' @@ -300,7 +300,9 @@ class ItemListing(SQL_Base): @normalized_price.expression def normalized_price(cls): - return cls.price / cls.amount + return case([ + (cls.amount != 0, cls.price / cls.amount), + ], else_=maxsize) def listing_str(self): return '**{}** **{}** for **{}D**'.format(self.amount, self.name, self.price)