Shops selling 0 items for a price now go to the bottom of the ?selling

list
doc_update
Joey Hines 2018-09-26 08:06:47 -05:00
parent 2b6db04d28
commit bd3c6fa0af
1 changed files with 5 additions and 3 deletions

View File

@ -1,11 +1,12 @@
import enum import enum
from difflib import SequenceMatcher from difflib import SequenceMatcher
from sys import maxsize
from sqlalchemy import Column, Integer, String, ForeignKey, Enum, create_engine, exists from sqlalchemy import Column, Integer, String, ForeignKey, Enum, create_engine, exists
from sqlalchemy.exc import IntegrityError, DataError from sqlalchemy.exc import IntegrityError, DataError
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, column_property, sessionmaker 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 sqlalchemy.ext.hybrid import hybrid_property
from geoffrey.BotErrors import * from geoffrey.BotErrors import *
@ -252,7 +253,6 @@ class Shop(Location):
} }
def inv_to_str(self): def inv_to_str(self):
if len(self.inventory.limit(25).all()) != 0: if len(self.inventory.limit(25).all()) != 0:
inv = '\n**Inventory**:' inv = '\n**Inventory**:'
str_format = '{}\n{}' str_format = '{}\n{}'
@ -300,7 +300,9 @@ class ItemListing(SQL_Base):
@normalized_price.expression @normalized_price.expression
def normalized_price(cls): def normalized_price(cls):
return cls.price / cls.amount return case([
(cls.amount != 0, cls.price / cls.amount),
], else_=maxsize)
def listing_str(self): def listing_str(self):
return '**{}** **{}** for **{}D**'.format(self.amount, self.name, self.price) return '**{}** **{}** for **{}D**'.format(self.amount, self.name, self.price)