class Task(db.EmbeddedDocument): title = db.StringField(verbose_name="Title", max_length=255, unique=True, required=True) details = db.StringField(verbose_name="Details") setdate = db.DateTimeField(default=datetime.datetime.now) lastdate = db.DateTimeField(verbose_name="Last Date") completed = db.BooleanField(default=False) url = db.StringField(max_length=255, unique=True)
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 Project(db.Document): project = db.StringField(verbose_name="Project", max_length=255, unique=True, required=True) description = db.StringField(verbose_name="Description") dateofcreation = db.DateTimeField(default=datetime.datetime.now) url = db.StringField(max_length=255, unique=True, required=True) tasks = db.ListField(db.EmbeddedDocumentField('Task')) @property def completed(self): projectDetails = Project.objects().get(url=self.url) count = 0 for i in projectDetails.tasks: if i.completed == True: count += 1 return count @property def remaining(self): projectDetails = Project.objects().get(url=self.url) count = 0 for i in projectDetails.tasks: if i.completed == False: count += 1 return count
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 Store(db.Document): store_name = db.StringField(required=True, unique=True) Phone_number = db.StringField(required=True) tagline = db.StringField(required=True) shop_address = db.StringField(required=True) email = db.StringField(unique=True) created = db.DateTimeField(default=datetime.datetime.utcnow) def __str__(self): return "<Store: {}>".format(self.store_name)
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 User(db.Document): phone_number = db.StringField(required=True, unique=True) first_name = db.StringField(required=True) last_name = db.StringField(required=True) email = db.StringField(required=True, unique=True) is_active = db.BooleanField(default=False) password = db.StringField(required=True) api_token = db.StringField() user_role = db.StringField(default="store_admin") reg_date = db.DateTimeField(default=datetime.datetime.utcnow) def __str__(self): return "<User: {}>".format(self.first_name)
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)
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 Prediction(db.Document): meta = {'collection': 'predictions'} predictionResults = db.ListField(required=True) rawPredictionResults = db.ListField(required=True) date = db.DateTimeField(required=True)
class Feedback(db.Document): meta = {'collection': 'feedbacks'} content = db.EmbeddedDocumentListField('FeedbackContent', required=True) date = db.DateTimeField(required=True)