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