class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) repass = db.Column(db.Boolean, nullable=False, default=False) posts = db.relationship('Post', backref='author', lazy=True) submissions = db.relationship('Submission', backref='author', lazy=True) frozen_submissions = db.relationship('SubmissionFrozen', backref='author', lazy=True) def __repr__(self): return f'{self.username}'
class Post(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) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class ParkingLot(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False, unique=True) level = db.Column(db.Integer, nullable=False) slot_no = db.Column(db.Integer, nullable=False) parked = db.Column(db.Boolean, nullable=False) in_time = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) out_time = db.Column(db.DateTime, nullable=True) company = db.Column(db.String(60), nullable=False) def __repr__(self): return f"Post('{self.level}', '{self.slot_no}', '{self.in_time}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True, nullable=False, unique=True) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) company = db.Column(db.String(60), nullable=False) def get_reset_token(self, expires_sec=1800): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}')"
class Submission(db.Model): id = db.Column(db.Integer, primary_key=True) problem_id = db.Column(db.Integer, nullable=False) score = db.Column(db.Integer, nullable=False) max_score = db.Column(db.Integer, nullable=False) time_penalty = db.Column(db.Integer, nullable=False) subs_penalty = db.Column(db.Integer, nullable=False) is_first_AC = db.Column(db.Boolean, nullable=False, default=False) log = db.Column(db.String()) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Submission('{self.user_id}', {self.problem_id}, {self.max_score}, {self.score}, {self.time_penalty}, {self.subs_penalty}, {self.log}')"