Exemple #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)
Exemple #2
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=100, optimize=True)
Exemple #3
0
 class Tester(db.Document):
     image = ImageField(fs=storage,
                        basename=lambda o: 'prefix/filename')
Exemple #4
0
 class Tester(db.Document):
     image = ImageField(fs=storage, upload_to=lambda o: upload_to)
Exemple #5
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=max_size)
Exemple #6
0
 class Tester(db.Document):
     image = ImageField(fs=storage, thumbnails=sizes)
     image2 = ImageField(fs=storage)
Exemple #7
0
 class Tester(db.Document):
     image = ImageField(fs=storage)
 class Tester(db.Document):
     image = ImageField(fs=self.storage, upload_to=upload_to)
Exemple #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)