コード例 #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)
コード例 #2
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=100, optimize=True)
コード例 #3
0
 class Tester(db.Document):
     image = ImageField(fs=storage,
                        basename=lambda o: 'prefix/filename')
コード例 #4
0
 class Tester(db.Document):
     image = ImageField(fs=storage, upload_to=lambda o: upload_to)
コード例 #5
0
 class Tester(db.Document):
     image = ImageField(fs=storage, max_size=max_size)
コード例 #6
0
 class Tester(db.Document):
     image = ImageField(fs=storage, thumbnails=sizes)
     image2 = ImageField(fs=storage)
コード例 #7
0
 class Tester(db.Document):
     image = ImageField(fs=storage)
コード例 #8
0
 class Tester(db.Document):
     image = ImageField(fs=self.storage, upload_to=upload_to)
コード例 #9
0
ファイル: roofs.py プロジェクト: ActiveChooN/nizhny-roofs
class RoofImage(db.Document):
    image = ImageField(fs=storages["avatars"], max_size=2000, thumbnails=[200])
    date = DateTimeField(default=datetime.utcnow)
    uploaded_by = ReferenceField(User)