Beispiel #1
0
class User(db.Document):
    email = EmailField(required=True, unique=True)
    first_name = StringField(required=True)
    last_name = StringField()
    password_hash = StringField(required=True)
    avatar = ImageField(fs=storages["avatars"], max_size=200)
    followed = ListField(ReferenceField('self'))
    is_active = BooleanField(default=True)
    is_admin = BooleanField(default=False)

    def __init__(self, *args, **kwargs):
        if "password" in kwargs.keys():
            password = kwargs.pop("password")
            super().__init__(*args, **kwargs)
            self.password = password
        else:
            super().__init__(*args, **kwargs)

    def update(self, *args, **kwargs):
        if "password" in kwargs.keys():
            password = kwargs.pop("password")
            self.update(password_hash=generate_password_hash(password))
        if kwargs:
            super().update(*args, **kwargs)

    @property
    def password(self):
        raise AttributeError("Error: Password is not readable attribute")

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)
Beispiel #2
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=100, optimize=True)
Beispiel #3
0
 class Tester(db.Document):
     image = ImageField(fs=storage,
                        basename=lambda o: 'prefix/filename')
Beispiel #4
0
 class Tester(db.Document):
     image = ImageField(fs=storage, upload_to=lambda o: upload_to)
Beispiel #5
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=max_size)
Beispiel #6
0
 class Tester(db.Document):
     image = ImageField(fs=storage, thumbnails=sizes)
     image2 = ImageField(fs=storage)
Beispiel #7
0
 class Tester(db.Document):
     image = ImageField(fs=storage)
Beispiel #8
0
 class Tester(db.Document):
     image = ImageField(fs=self.storage, upload_to=upload_to)
Beispiel #9
0
class RoofImage(db.Document):
    image = ImageField(fs=storages["avatars"], max_size=2000, thumbnails=[200])
    date = DateTimeField(default=datetime.utcnow)
    uploaded_by = ReferenceField(User)