class UserStore(db.Document): user_ref_id = db.ReferenceField(user.User, required=True) store_ref_id = db.ReferenceField(store.Store, required=True) def __repr__(self): return "<UserStore: {}; {}>".format(self.user_ref_id, self.store_ref_id)
class Complaint(db.Document): user_ref_id = db.ReferenceField(user.User, required=True) message = db.StringField(required=True) store_ref_code = db.ReferenceField(user_store.UserStore, required=True) status = db.StringField(default="open") timestamp = db.DateTimeField(default=datetime.datetime.utcnow) def __repr__(self): return "<Complaint: from: {}; opened: {}>".format( self.store_ref_code, self.timestamp)
class Transaction(db.Document): """ A class used to represent the transaction model ... Attributes ---------- customer_ref_id : reference a reference field to the customer amount : float the transaction amount interest : float the interest applied to the amount total_amount: float the total_amount description : str the description of the transaction transaction_name: str the name of transaction user_ref_id: reference user reference ID store_ref_id: reference store reference ID Methods ------- pre_save(cls, sender, transaction, *kw) handles time attribute(updated_at) ONLY when transaction is modified """ customer_ref_id = db.ReferenceField(customer.Customer, required=True, dbref=True) amount = db.FloatField(required=True) interest = db.FloatField(required=True) total_amount = db.FloatField(required=True) description = db.StringField(required=True) transaction_name = db.StringField(required=True) transaction_role = db.StringField(required=True) user_ref_id = db.ReferenceField(user.User, dbref=True, required=True) #store_ref_id = db.ReferenceField(user_store.Store, dbref=True, required=True) store_ref_id = db.ReferenceField(store.Store, dbref=True, required=True) created_at = db.DateTimeField(default=datetime.datetime.utcnow) updated_at = db.DateTimeField(default=datetime.datetime.utcnow) @classmethod def pre_save(cls, sender, document, **kwargs): document.updated_at = datetime.datetime.utcnow() def __str__(self): return "<Transaction Details: {}-{} by {} at {}>".format( self.transaction_name, self.transaction_role, self.user_ref_id, self.created_at)
class Show(db.Document): slug = db.StringField(required=True) title = db.StringField(required=True) artists_slug = db.ListField(StringField()) attendance_count = db.IntField(min_value=0, required=False, default=0) cover_image = db.StringField(required=False) description = db.StringField(required=False) datetime_usa = db.StringField(required=False) location = db.ReferenceField(Location, required=False, dbref=False) website = db.StringField(required=False) artists_list = None @property def artists(self): if not self.artists_list is None: return self.artists_list return Band.objects.filter(slug__in=self.artists_slug) @property def datetime(self): return datetime.strftime( datetime.strptime(self.datetime_usa[:19], "%Y-%m-%d %H:%M:%S"), '%d/%m') def __eq__(self, other): return self.slug == other.slug def __unicode__(self): return self.title
class Answer(db.EmbeddedDocument): answer = db.StringField(required=True) user = db.ReferenceField(User, required=True, dbref=False) def __eq__(self, other): return self.answer == other.answer and self.user == other.user def __unicode__(self): return self.answer
class Newsletter(db.Document): option = db.BooleanField(required=True) # Sim ou Nao tipo = db.StringField(required=True) # Shows Locais, Meus Shows, etc.. user = db.ReferenceField(User, required=True, dbref=False) def __eq__(self, other): return self.user == other.user and self.option == other.option and self.tipo == other.tipo def __unicode__(self): return u"%s - %s - %s" % (self.user, self.tipo, u"Sim" if self.option else u"Não")
class Post(db.Document): id = db.StringField(default=lambda: str(uuid.uuid4()), primary_key=True) title = db.StringField(max_length=255, required=True) slug = db.StringField(max_length=255, required=True, unique=True) date_posted = db.DateTimeField(default=datetime.datetime.now, required=True) content = db.StringField(required=True) author = db.ReferenceField(User, required=True) meta = { "allow_inheritance": False, "indexes": ["-date_posted", "slug", "title"], "ordering": ["-date_posted"], "collection": "posts", }
class DebtReminder: ts_ref_id = db.ReferenceField(transaction.Transaction, dbref=True, required=True) message = db.StringField(required=True) status = db.StringField(required=True) expected_pay_date = db.DateTimeField(default=datetime.datetime.utcnow) updated_at = db.DateTimeField(default=datetime.datetime.utcnow) @classmethod def pre_save(cls, sender, document, **kwargs): document.updated_at = datetime.datetime.utcnow() def __str__(self): return "<Debt Reminder: {}; {} at {}>".format(self.ts_ref_id, self.message, self.expected_pay_date)
class Customer(db.Document): """ A class used to represent the customer model ... Attributes ---------- store_ref_id: reference store reference ID name : str the name of the customer phone_number: str the phone number of the customer created_at: datetime str time when customer is created updated_at: datetime str time when customer is modified Methods ------- pre_save(cls, sender, customer, *kw) handles time attribute(updated_at) ONLY when customer detail is modified """ store_ref_id = db.ReferenceField(store.Store, dbref=True, required=True) name = db.StringField(required=True) phone_number = db.StringField(required=True) created_at = db.DateTimeField(default=datetime.datetime.utcnow) updated_at = db.DateTimeField(default=datetime.datetime.utcnow) @classmethod def pre_save(cls, sender, document, **kwargs): document.updated_at = datetime.datetime.utcnow() def __str__(self): return "<Customer: {}; {} at {}>".format(self.name, self.store_ref_id, self.created_at)