2021-03-24 10:05:36 +00:00
|
|
|
from datetime import datetime
|
|
|
|
import sqlalchemy
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2021-05-05 12:26:26 +00:00
|
|
|
from flask_login import UserMixin
|
|
|
|
|
2021-03-24 10:05:36 +00:00
|
|
|
|
|
|
|
###########################################
|
|
|
|
# Model classes for describing SQL tables #
|
|
|
|
###########################################
|
|
|
|
|
|
|
|
# The "db" object gets bound to the Flask app in app.py.
|
|
|
|
db = SQLAlchemy()
|
|
|
|
|
|
|
|
|
2021-05-05 12:26:26 +00:00
|
|
|
class UploadSolar(db.Model):
|
|
|
|
__tablename__ = 'upload_solar'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-05-24 08:15:54 +00:00
|
|
|
upload_user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=True)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=True)
|
|
|
|
upload_hash = db.Column(db.String, nullable=False)
|
|
|
|
timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
program = db.Column(db.String, nullable=True)
|
|
|
|
subject = db.Column(db.String, nullable=True)
|
|
|
|
subject_custom = db.Column(db.String, nullable=True)
|
|
|
|
grade = db.Column(db.Integer, nullable=True)
|
|
|
|
text_type = db.Column(db.String, nullable=True)
|
|
|
|
text_type_custom = db.Column(db.String, nullable=True)
|
|
|
|
school_year = db.Column(db.String, nullable=True)
|
|
|
|
grammar_corrections = db.Column(db.String, nullable=True)
|
|
|
|
upload_file_hashes = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True)
|
|
|
|
|
|
|
|
|
|
|
|
class ContractsSolar(db.Model):
|
|
|
|
__tablename__ = 'contracts_solar'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False)
|
|
|
|
upload_user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=True)
|
|
|
|
timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
file_contract = db.Column(db.String, nullable=False)
|
2021-09-02 12:40:54 +00:00
|
|
|
original_filename = db.Column(db.String, nullable=True)
|
2021-05-24 08:15:54 +00:00
|
|
|
contract_type = db.Column(db.String, nullable=False)
|
|
|
|
|
|
|
|
|
2021-05-05 12:26:26 +00:00
|
|
|
class RegisteredUser(UserMixin, db.Model):
|
|
|
|
__tablename__ = 'registered_user'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-05-24 08:15:54 +00:00
|
|
|
name = db.Column(db.String, nullable=False)
|
2021-06-08 06:00:18 +00:00
|
|
|
email = db.Column(db.String, nullable=False, unique=True)
|
2021-05-24 08:15:54 +00:00
|
|
|
role = db.Column(db.String, nullable=False)
|
|
|
|
pass_hash = db.Column(db.String, nullable=False)
|
|
|
|
active = db.Column(db.Boolean, nullable=True)
|
|
|
|
last_login = db.Column(db.DateTime, nullable=True)
|
|
|
|
registered = db.Column(db.DateTime, nullable=True)
|
2021-09-16 15:25:20 +00:00
|
|
|
is_removed = db.Column(db.Boolean, nullable=False, default=False, server_default="false")
|
2021-06-08 06:00:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserInstitutionMapping(db.Model):
|
|
|
|
__tablename__ = 'user_institution_mapping'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=False)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False)
|
2021-09-02 12:40:54 +00:00
|
|
|
role = db.Column(db.String, nullable=False)
|
|
|
|
|
|
|
|
|
|
|
|
class UserCooperationHistory(db.Model):
|
|
|
|
__tablename__ = 'user_cooperation'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=False)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False)
|
|
|
|
role = db.Column(db.String, nullable=False)
|
|
|
|
school_year = db.Column(db.String, nullable=False)
|
|
|
|
badge_text = db.Column(db.String, nullable=True)
|
2021-05-05 12:26:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Institution(db.Model):
|
|
|
|
__tablename__ = 'institution'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-06-08 06:00:18 +00:00
|
|
|
name = db.Column(db.String, nullable=False, unique=True)
|
2021-05-24 08:15:54 +00:00
|
|
|
region = db.Column(db.String, nullable=False)
|
2021-09-16 15:25:20 +00:00
|
|
|
is_removed = db.Column(db.Boolean, nullable=False, default=False, server_default="false")
|
2021-06-08 06:00:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CorpusAccess(db.Model):
|
|
|
|
__tablename__ = 'corpus_access'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False)
|
|
|
|
corpus = db.Column(db.String, nullable=False)
|
|
|
|
|
|
|
|
|
|
|
|
class InstitutionContract(db.Model):
|
|
|
|
__tablename__ = 'institution_contract'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
institution = db.Column(db.Integer, sqlalchemy.ForeignKey('institution.id'), nullable=False)
|
|
|
|
corpus = db.Column(db.String, nullable=False)
|
|
|
|
timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
2021-05-24 08:15:54 +00:00
|
|
|
file_contract = db.Column(db.String, nullable=True)
|
2021-09-02 12:40:54 +00:00
|
|
|
original_filename = db.Column(db.String, nullable=True)
|
2021-03-24 10:05:36 +00:00
|
|
|
|