Blame view

flaskr/models.py 1.67 KB
1b39d5ec   Goutte   Add a skeleton fo...
1
2
3
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin, AnonymousUserMixin
from werkzeug.security import generate_password_hash, check_password_hash
97fe903e   Goutte   Add the base data...
4
import enum
1b39d5ec   Goutte   Add a skeleton fo...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

db = SQLAlchemy()


class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String())
    password = db.Column(db.String())

    def __init__(self, username, password):
        self.username = username
        self.set_password(password)

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, value):
        return check_password_hash(self.password, value)

    @property
    def is_authenticated(self):
        if isinstance(self, AnonymousUserMixin):
            return False
        else:
            return True

    def is_active(self):
        return True

    def is_anonymous(self):
        if isinstance(self, AnonymousUserMixin):
            return True
        else:
            return False

    def get_id(self):
        return self.id

    def __repr__(self):
        return '<User %r>' % self.username
97fe903e   Goutte   Add the base data...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65


class StatusEnum(enum.Enum):
    pending = 'pending'
    success = 'success'
    failed = 'failed'


class Estimation(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.Unicode(1024))
    first_name = db.Column(db.Unicode(1024))  # Antoine
    last_name = db.Column(db.Unicode(1024))   # Goutenoir
    status = db.Column(db.Enum(StatusEnum))

    # destination_address = db.Column(db.Unicode(1024))

    # City, Country
    # One address per line
    origin_addresses = db.Column(db.Unicode())
    destination_addresses = db.Column(db.Unicode())