Exemplo n.º 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(64), nullable=False)

    def __repr__(self):
        return f"User '{self.username}'"
Exemplo n.º 2
0
class Project(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, unique=True)
    shortcut = db.Column(db.String(50), nullable=False, unique=True)
    start_date = db.Column(db.String(50), nullable=False, default=func.current_date())
    end_date = db.Column(db.String(50), nullable=False)
    phase = db.Column(db.String(50), nullable=False)
    active = db.Column(db.Boolean, default=True)
    hour = db.relationship("Hour", backref="project", passive_deletes=True)

    def __repr__(self):
        return f"Project: {self.name}"
Exemplo n.º 3
0
class Hour(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    amount = db.Column(db.Integer, nullable=False)
    work_date = db.Column(db.String(50), default=func.current_date())
    project_shortcut = db.Column(db.String(50),
                                 db.ForeignKey("project.shortcut"),
                                 nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user.id", ondelete="CASCADE"),
                        nullable=False)

    def __repr__(self):
        return f"{self.amount} hours"
Exemplo n.º 4
0
class Vacation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    vacation_date = db.Column(db.String(50), default=func.current_date())
    user_id = db.Column(
        db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), nullable=False
    )

    def __repr__(self):
        return f"Vacation day in {self.vacation_date}"
Exemplo n.º 5
0
class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(256), nullable=False)
    description = db.Column(db.Text, nullable=False)
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_completed = db.Column(db.DateTime, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship('User', backref=db.backref('todos', lazy=True))

    def __repr__(self):
        return f"Description: '{self.description}', Date: '{self.date_created}'"
Exemplo n.º 6
0
class Subject(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(126), nullable=False)
    description = db.Column(db.Text, nullable=False)
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    active = db.Column(db.Boolean, nullable=False, default=True)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship('User', backref=db.backref('subjects', lazy=True))

    def __repr__(self):
        return f"Name: '{self.name}', Date: '{self.date_created}'"
Exemplo n.º 7
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), nullable=False, unique=True)
    password_hash = db.Column(db.String(50))
    total_vacation_days = db.Column(db.Integer, default=0)
    rem_vacation_days = db.Column(db.Integer, default=0)
    hour = db.relationship("Hour", backref="user", passive_deletes=True)
    vacation = db.relationship("Vacation",
                               backref="user",
                               passive_deletes=True)

    def __repr__(self):
        return f"{self.username}"

    @property
    def password(self):
        raise AttributeError("password is not a 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)