mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Sort things a bit... this should get improved in the future
This commit is contained in:
parent
2ceb53cac1
commit
b7fc804b40
@ -35,6 +35,12 @@ class Role(db.Model):
|
||||
# Relationships
|
||||
users = db.relationship('User', backref='role', lazy='dynamic')
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'default': self.default,
|
||||
'name': self.name,
|
||||
'permissions': self.permissions}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(Role, self).__init__(**kwargs)
|
||||
if self.permissions is None:
|
||||
@ -104,26 +110,42 @@ class User(UserMixin, db.Model):
|
||||
__tablename__ = 'users'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Foreign keys
|
||||
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
|
||||
# Fields
|
||||
confirmed = db.Column(db.Boolean, default=False)
|
||||
last_seen = db.Column(db.DateTime(), default=datetime.utcnow)
|
||||
email = db.Column(db.String(254), unique=True, index=True)
|
||||
password_hash = db.Column(db.String(128))
|
||||
last_seen = db.Column(db.DateTime(), default=datetime.utcnow)
|
||||
member_since = db.Column(db.DateTime(), default=datetime.utcnow)
|
||||
role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
|
||||
username = db.Column(db.String(64), unique=True, index=True)
|
||||
# Setting Fields
|
||||
password_hash = db.Column(db.String(128))
|
||||
setting_dark_mode = db.Column(db.Boolean, default=False)
|
||||
setting_job_status_mail_notifications = db.Column(db.String(16),
|
||||
default='end')
|
||||
setting_job_status_site_notifications = db.Column(db.String(16),
|
||||
default='all')
|
||||
username = db.Column(db.String(64), unique=True, index=True)
|
||||
# Relationships
|
||||
corpora = db.relationship('Corpus', backref='creator', lazy='dynamic',
|
||||
cascade='save-update, merge, delete')
|
||||
jobs = db.relationship('Job', backref='creator', lazy='dynamic',
|
||||
cascade='save-update, merge, delete')
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'confirmed': self.confirmed,
|
||||
'email': self.email,
|
||||
'last_seen': self.last_seen.timestamp(),
|
||||
'member_since': self.member_since.timestamp(),
|
||||
'role_id': self.role_id,
|
||||
'username': self.username,
|
||||
'settings': {'dark_mode': self.setting_dark_mode,
|
||||
'job_status_mail_notifications':
|
||||
self.setting_job_status_mail_notifications,
|
||||
'job_status_site_notifications':
|
||||
self.setting_job_status_site_notifications},
|
||||
'corpora': [corpus.to_dict() for corpus in self.corpora],
|
||||
'jobs': [job.to_dict() for job in self.jobs]}
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
String representation of the User. For human readability.
|
||||
@ -245,10 +267,11 @@ class JobInput(db.Model):
|
||||
__tablename__ = 'job_inputs'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Fields
|
||||
filename = db.Column(db.String(255))
|
||||
dir = db.Column(db.String(255))
|
||||
# Foreign keys
|
||||
job_id = db.Column(db.Integer, db.ForeignKey('jobs.id'))
|
||||
# Fields
|
||||
dir = db.Column(db.String(255))
|
||||
filename = db.Column(db.String(255))
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
@ -258,8 +281,8 @@ class JobInput(db.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'filename': self.filename,
|
||||
'job_id': self.job_id}
|
||||
'job_id': self.job_id,
|
||||
'filename': self.filename}
|
||||
|
||||
|
||||
class JobResult(db.Model):
|
||||
@ -269,10 +292,11 @@ class JobResult(db.Model):
|
||||
__tablename__ = 'job_results'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Fields
|
||||
filename = db.Column(db.String(255))
|
||||
dir = db.Column(db.String(255))
|
||||
# Foreign keys
|
||||
job_id = db.Column(db.Integer, db.ForeignKey('jobs.id'))
|
||||
# Fields
|
||||
dir = db.Column(db.String(255))
|
||||
filename = db.Column(db.String(255))
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
@ -282,8 +306,8 @@ class JobResult(db.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'filename': self.filename,
|
||||
'job_id': self.job_id}
|
||||
'job_id': self.job_id,
|
||||
'filename': self.filename}
|
||||
|
||||
|
||||
class Job(db.Model):
|
||||
@ -293,6 +317,8 @@ class Job(db.Model):
|
||||
__tablename__ = 'jobs'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Foreign keys
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
# Fields
|
||||
creation_date = db.Column(db.DateTime(), default=datetime.utcnow)
|
||||
description = db.Column(db.String(255))
|
||||
@ -309,7 +335,6 @@ class Job(db.Model):
|
||||
service_version = db.Column(db.String(16))
|
||||
status = db.Column(db.String(16))
|
||||
title = db.Column(db.String(32))
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
# Relationships
|
||||
inputs = db.relationship('JobInput', backref='job', lazy='dynamic',
|
||||
cascade='save-update, merge, delete')
|
||||
@ -341,6 +366,7 @@ class Job(db.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'user_id': self.user_id,
|
||||
'creation_date': self.creation_date.timestamp(),
|
||||
'description': self.description,
|
||||
'end_date': (self.end_date.timestamp() if self.end_date else
|
||||
@ -353,8 +379,7 @@ class Job(db.Model):
|
||||
'service_args': self.service_args,
|
||||
'service_version': self.service_version,
|
||||
'status': self.status,
|
||||
'title': self.title,
|
||||
'user_id': self.user_id}
|
||||
'title': self.title}
|
||||
|
||||
|
||||
class CorpusFile(db.Model):
|
||||
@ -364,6 +389,8 @@ class CorpusFile(db.Model):
|
||||
__tablename__ = 'corpus_files'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Foreign keys
|
||||
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
||||
# Fields
|
||||
address = db.Column(db.String(255))
|
||||
author = db.Column(db.String(255))
|
||||
@ -379,7 +406,6 @@ class CorpusFile(db.Model):
|
||||
publishing_year = db.Column(db.Integer)
|
||||
school = db.Column(db.String(255))
|
||||
title = db.Column(db.String(255))
|
||||
corpus_id = db.Column(db.Integer, db.ForeignKey('corpora.id'))
|
||||
|
||||
def delete(self):
|
||||
self.corpus.status = 'unprepared'
|
||||
@ -388,6 +414,7 @@ class CorpusFile(db.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'corpus_id': self.corpus_id,
|
||||
'address': self.address,
|
||||
'author': self.author,
|
||||
'booktitle': self.booktitle,
|
||||
@ -400,8 +427,7 @@ class CorpusFile(db.Model):
|
||||
'publisher': self.publisher,
|
||||
'publishing_year': self.publishing_year,
|
||||
'school': self.school,
|
||||
'title': self.title,
|
||||
'corpus_id': self.corpus_id}
|
||||
'title': self.title}
|
||||
|
||||
|
||||
class Corpus(db.Model):
|
||||
@ -411,26 +437,25 @@ class Corpus(db.Model):
|
||||
__tablename__ = 'corpora'
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Foreign keys
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
# Fields
|
||||
creation_date = db.Column(db.DateTime(), default=datetime.utcnow)
|
||||
description = db.Column(db.String(255))
|
||||
status = db.Column(db.String(16))
|
||||
title = db.Column(db.String(32))
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
analysis_container_ip = db.Column(db.String(16))
|
||||
analysis_container_name = db.Column(db.String(32))
|
||||
# Relationships
|
||||
files = db.relationship('CorpusFile', backref='corpus', lazy='dynamic',
|
||||
cascade='save-update, merge, delete')
|
||||
|
||||
def to_dict(self):
|
||||
return {'id': self.id,
|
||||
'user_id': self.user_id,
|
||||
'creation_date': self.creation_date.timestamp(),
|
||||
'description': self.description,
|
||||
'files': [file.to_dict() for file in self.files],
|
||||
'status': self.status,
|
||||
'title': self.title,
|
||||
'user_id': self.user_id}
|
||||
'files': [file.to_dict() for file in self.files]}
|
||||
|
||||
def delete(self):
|
||||
for corpus_file in self.files:
|
||||
|
Loading…
Reference in New Issue
Block a user