Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
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)
Beispiel #4
0
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')
Beispiel #5
0
class Switch(BitField):
    state = db.BooleanField(default=False)