portal-oddajanje-solar/portal/model.py

125 lines
5.3 KiB
Python
Raw Normal View History

from datetime import datetime
import sqlalchemy
from flask_sqlalchemy import SQLAlchemy
2021-05-05 12:26:26 +00:00
from flask_login import UserMixin
###########################################
# Model classes for describing SQL tables #
###########################################
# The "db" object gets bound to the Flask app in app.py.
db = SQLAlchemy()
# "prevodi" or "gigafida".
class UploadRegular(db.Model):
__tablename__ = 'upload_regular'
id = db.Column(db.Integer, primary_key=True)
2021-05-24 08:15:54 +00:00
upload_hash = db.Column(db.String, nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
name = db.Column(db.String, nullable=False)
org = db.Column(db.String, nullable=True)
address = db.Column(db.String, nullable=True)
zipcode = db.Column(db.String, nullable=True)
email = db.Column(db.String, nullable=False)
file_contract = db.Column(db.String, nullable=True)
upload_file_hashes = db.Column(sqlalchemy.types.ARRAY(db.String), nullable=True)
corpus_name = db.Column(db.String, nullable=False)
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)
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-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)
role = db.Column(db.String, nullable=False)
#class CooperationToken(db.Model):
# __tablename__ = 'cooperation_token'
# id = db.Column(db.Integer, primary_key=True)
# name = db.Column(db.String, nullable=False)
#
#
#class UserCooperationTokenMapping(db.Model):
# __tablename__ = 'user_cooperation_token_mapping'
# id = db.Column(db.Integer, primary_key=True)
# user = db.Column(db.Integer, sqlalchemy.ForeignKey('registered_user.id'), nullable=False)
# cooperation_token = db.Column(db.Integer, sqlalchemy.ForeignKey('cooperation_token.id'), 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-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)
original_filename = db.Column(db.String, nullable=True)