Created
January 11, 2013 18:35
-
-
Save diiq/4512897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mongoengine import * | |
from mongoengine import signals | |
__all__ = ["SellOrderItem"] | |
REJECTION_REASONS = [ | |
"Hole", | |
"Staining", | |
"Overall wear", | |
"Loose hem", | |
"Discoloration", | |
"Iron marks", | |
"Not authentic", | |
"Pulled seams", | |
"Dated", | |
"Missing buttons", | |
"Broken zipper", | |
"Separated seam", | |
"Alteration", | |
"Overstocked", | |
"Snag", | |
"Runs", | |
"Pilling"] | |
class SellOrderItem(Document): | |
category = StringField() | |
brand = StringField() | |
disp_category = StringField() | |
disp_brand = StringField() | |
est_lower = IntField() | |
est_upper = IntField() | |
offer_price = IntField() | |
sellability = IntField() | |
# True if this item was listed in the original sell order submission | |
is_listed = BooleanField() | |
# True if the user ended up sending this item in with the sell order | |
is_received = BooleanField() | |
# These two fields aren't relevant until the SellOrder has advanced past | |
# RECEIVED stage | |
is_accepted = BooleanField() | |
rejection_reason = StringField() | |
meta = {"allow_inheritance": False} | |
@property | |
def disp_dict(self): | |
return { | |
"id": str(self.id), | |
"name": self.name, | |
"brand": self.brand, | |
"category": self.category, | |
"estLower": self.est_lower, | |
"estUpper": self.est_upper, | |
"offerPrice": self.offer_price, | |
"sellability": self.sellability, | |
"isAccepted": self.is_accepted, | |
"isListed": self.is_listed, | |
"isReceived": self.is_received, | |
"rejectionReason": self.rejection_reason | |
} | |
def is_complete(self): | |
return (self.brand and | |
self.category and | |
((self.sellability and self.offer_price) or | |
(self.is_accepted is False))) | |
@property | |
def name(self): | |
if self.disp_brand and self.disp_category: | |
return self.disp_brand + " " + self.disp_category | |
else: | |
return None | |
@classmethod | |
def set_disps(cls, sender, document, **kwargs): | |
if document.brand: | |
brand_obj = ItemDataPresets.objects(type="brand", | |
can_name=document.brand).first() | |
disp_brand = brand_obj.can_data.disp_name | |
document.disp_brand = disp_brand | |
if document.category: | |
disp_category = {"tops": "top", | |
"dresses": "dress", | |
"skirts": "skirt", | |
"jeans": "jeans", | |
"pants": "pants"}[document.category] | |
document.disp_category = disp_category | |
signals.pre_save.connect(SellOrderItem.set_disps, sender=SellOrderItem) | |
from twiceweb.common.models import ItemDataPresets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment