class BitNote(db.DynamicDocument): owners = db.ListField(db.ReferenceField('User')) editors = db.ListField(db.ReferenceField('User')) viewers = db.ListField(db.ReferenceField('User')) public = db.BooleanField(default=False) bitfields = db.ListField(db.EmbeddedDocumentField(BitField)) created_at = db.DateTimeField(default=datetime.datetime.now, required=True) title = db.StringField(max_length=255, required=False) meta = {'allow_inheritance': True} meta = {'indexes': ['-created_at'], 'ordering': ['-created_at']} def save_to_bitbook(self, bitbook): bitbook.bitnotes.append(self) for field in self.bitfields: if field.title not in bitbook.cover_fields: bitbook.cover_fields[field.title] = field bitbook.save() def share_to(self, to_user, from_user, msg, access): #create mailbox if does not exist: fr, to = user_mail_context(from_user, to_user) manage_access(self, access, to, fr) message = BitMailItem(bitnote=self, from_user=fr, to_user=to, message=msg) message.save() to.mail.inbox.append(message) to.mail.save() fr.mail.outbox.append(message) fr.mail.save()
class BitBook(db.DynamicDocument): owners = db.ListField(db.ReferenceField('User')) editors = db.ListField(db.ReferenceField('User')) viewers = db.ListField(db.ReferenceField('User')) public = db.BooleanField(default=False) title = db.StringField(max_length=255, required=True) description = db.StringField(required=False) created_at = db.DateTimeField(default=datetime.datetime.now, required=True) cover_fields = db.DictField(required=False) bitnotes = db.ListField( db.ReferenceField(BitNote, reverse_delete_rule=db.PULL)) thumbnail = db.ImageField(size=(800, 600, True), thumbnail_size=(150, 150, True)) def share_to(self, to_user, from_user, msg, access): #create mailbox if does not exist: fr, to = user_mail_context(from_user, to_user) #manage access: manage_access(self, access, to, fr) message = BitMailItem(bitbook=self, from_user=fr, to_user=to, message=msg) message.save() to.mail.inbox.append(message) to.mail.save() fr.mail.outbox.append(message) fr.mail.save()
class BitMail(db.Document): inbox = db.ListField( db.ReferenceField(BitMailItem, reverse_delete_rule=db.PULL)) outbox = db.ListField( db.ReferenceField(BitMailItem, reverse_delete_rule=db.PULL)) trash = db.ListField( db.ReferenceField(BitMailItem, reverse_delete_rule=db.PULL))
class BitMailItem(db.Document): bitnote = db.ReferenceField('BitNote') bitbook = db.ReferenceField('BitBook') from_user = db.ReferenceField('User') to_user = db.ReferenceField('User') created_at = db.DateTimeField(default=datetime.datetime.now, required=True) red = db.BooleanField(required=True, default=False) message = db.StringField(max_length=255)
class User(db.Document, UserMixin): email = db.StringField(max_length=255, unique=True) password = db.StringField(max_length=255) active = db.BooleanField(default=True) confirmed_at = db.DateTimeField() roles = db.ListField(db.ReferenceField(Role), default=[]) bitbooks = db.ListField(db.ReferenceField('BitBook')) mail = db.ReferenceField('BitMail')
class Reservation(db.EmbeddedDocument): made_by = db.ReferenceField(User) from_time = db.DateTimeField(default=datetime.datetime.now, required=True) to_time = db.DateTimeField(required=True) def check_avilability(self, fr, to): f = Reservation.objects(from_time__lte=fr, to_time=to)
class Availib(Device): avil_from = db.DateTimeField(default=datetime.datetime.now, required=True) avail_to = db.DateTimeField(required=False) allowed_usrs = db.ListField(db.ReferenceField(User)) reservations = db.ListField(db.ReferenceField('Reservation'))
class Comment(db.EmbeddedDocument): body = db.StringField(verbose_name="Comment", required=True) author = db.ReferenceField('User')
class LinkList(BitField): linklist = db.ListField(db.ReferenceField('Link'), required=False)