class ForecastItem(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) employee_id = db.Column(db.Integer, db.ForeignKey('employee.id')) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) assignment_id = db.Column(db.Integer, db.ForeignKey('assignment_types.id')) description = db.Column(db.String(1024), nullable=True) status = db.Column(db.String(60), nullable=False, default='new') start_date = db.Column(db.Date) end_date = db.Column(db.Date) _timestamp = db.Column(db.TIMESTAMP, default=datetime.now()) def __repr__(self): return f'Assignment({self.id},{self.employee_id}, {self.project_id}, {self.assignment_id}, {self.start_date}, {self.end_date})'
class Project(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) project_number = db.Column(db.Integer, nullable=False) project_name = db.Column(db.String(60), nullable=False) project_status = db.Column(db.String(60), nullable=False, default='new') project_description = db.Column(db.String(1024), nullable=True) manager_id = db.Column(db.Integer, db.ForeignKey('employee.id')) forecast_item = db.relationship('ForecastItem', backref='project_item', lazy=True) _timestamp = db.Column(db.TIMESTAMP, default=datetime.now()) def __repr__(self): return f'Project({self.project_number}, {self.project_name})'
class Employee(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) first_name = db.Column(db.String(60), nullable=False) last_name = db.Column(db.String(60), nullable=False) department_id = db.Column(db.Integer, db.ForeignKey('department.id')) available_for_registration = db.Column(db.Boolean, default=True) projects = db.relationship('Project', backref='project', lazy=True) forecast_item = db.relationship('ForecastItem', backref='employee_item', lazy=True) user_item = db.relationship('User', backref='employee', lazy=True) _timestamp = db.Column(db.TIMESTAMP, default=datetime.now()) def create_admin_employee(self): exists = Employee.query.filter_by(first_name='Admin').first() if exists: pass else: employee = Employee(first_name='Admin', last_name='Admin', available_for_registration=False) db.session.add(employee) db.session.commit() def __repr__(self): return f'Employee({self.first_name}, {self.last_name}, {self.department_id})'
class Poll(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) initiator_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Event(db.Model): id = db.Column(db.Integer, primary_key=True) start = db.Column(db.DateTime, unique=False, nullable=False) end = db.Column(db.DateTime, unique=False, nullable=False) # author = Column(String(20), unique=False, nullable=False) subject = db.Column(db.String(80), unique=False, nullable=False) description = db.Column(db.String(300), unique=False, nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Event('{self.subject}', '{self.start}', '{self.end}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(60), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) role = db.Column(db.String(15), nullable=False, default='User') is_active = db.Column(db.Boolean, nullable=False, default=True) employee_id = db.Column(db.Integer, db.ForeignKey('employee.id')) project_item = db.relationship('Project', backref='project_item', lazy=True) employee_item = db.relationship('Employee', backref='employee', lazy=True) forecast_item = db.relationship('ForecastItem', backref='user_item', lazy=True) _timestamp = db.Column(db.TIMESTAMP, default=datetime.now()) def create_admin(self): # check your .env file for admin username and password hashed_password = bcrypt.generate_password_hash( ADMIN_USER_PASS).decode('utf-8') exists = User.query.filter_by(username=ADMIN_USER).first() if exists: pass else: user = User(username=ADMIN_USER, email='*****@*****.**', password=hashed_password, role='Admin', is_active=True, employee_id=1) db.session.add(user) db.session.commit() def __repr__(self): return f'User({self.email}'
class Task_recipient(db.Model): task_id = db.Column(db.Integer, db.ForeignKey('task.id'), nullable = False, primary_key = True) recipient = db.Column(db.Integer, db.ForeignKey('user.id'),nullable = False,primary_key = True) completed = db.Column(db.Integer, default = 0, nullable = False)
class Poll_recipient(db.Model): poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'), nullable = False, primary_key = True) recipient = db.Column(db.Integer, db.ForeignKey('user.id'),nullable = False,primary_key = True) completed = db.Column(db.Integer, default = 0, nullable = False) choice = db.Column(db.Text, default = 'Poll unfinished', nullable=False)
class Announcement_recipient(db.Model): announcement_id = db.Column(db.Integer, db.ForeignKey('announcement.id'), nullable = False, primary_key = True) recipient = db.Column(db.Integer, db.ForeignKey('user.id'),nullable = False,primary_key = True) read = db.Column(db.Integer, default = 0, nullable = False) def __repr__(self): return f"Announcement_recipient('{self.announcement_id}','{self.recipient}','{self.read}')"