Add url properties to db models

This commit is contained in:
Patrick Jentsch 2020-12-04 14:16:00 +01:00
parent 29dbdc9f94
commit a2102a48ca

View File

@ -533,8 +533,13 @@ class Corpus(db.Model):
def path(self):
return os.path.join(self.creator.path, 'corpora', str(self.id))
@property
def url(self):
return url_for('corpora.corpus', corpus_id=self.id)
def to_dict(self):
return {'id': self.id,
return {'url': self.url,
'id': self.id,
'user_id': self.user_id,
'creation_date': self.creation_date.timestamp(),
'description': self.description,
@ -600,17 +605,28 @@ class QueryResult(db.Model):
query_metadata = db.Column(db.JSON())
title = db.Column(db.String(32))
@property
def download_url(self):
return url_for('corpora.download_query_result',
query_result_id=self.id)
@property
def path(self):
return os.path.join(
self.creator.path, 'query_results', str(self.id), self.filename)
@property
def url(self):
return url_for('corpora.query_result', query_result_id=self.id)
def delete(self):
shutil.rmtree(self.path, ignore_errors=True)
db.session.delete(self)
def to_dict(self):
return {'id': self.id,
return {'download_url': self.download_url,
'url': self.url,
'id': self.id,
'user_id': self.user_id,
'description': self.description,
'filename': self.filename,