From 37d5802b42accb32bc65f40b7681fce81208c0c5 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Mon, 4 Nov 2019 15:06:54 +0100
Subject: [PATCH] Update
---
.gitlab-ci.yml | 16 ++++++++--------
app/corpora/views.py | 4 +++-
app/models.py | 10 ++++++----
app/utils.py | 7 ++++++-
4 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 205d949e..b3bf5524 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -15,8 +15,8 @@ before_script:
Build:
script:
- - docker build --pull -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
+ - docker build --pull -t $CI_REGISTRY_IMAGE:tmp .
+ - docker push $CI_REGISTRY_IMAGE:tmp
stage: build
tags:
- docker
@@ -25,8 +25,8 @@ Push development:
only:
- development
script:
- - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:development
+ - docker pull $CI_REGISTRY_IMAGE:tmp
+ - docker tag $CI_REGISTRY_IMAGE:tmp $CI_REGISTRY_IMAGE:development
- docker push $CI_REGISTRY_IMAGE:development
stage: push
tags:
@@ -36,8 +36,8 @@ Push latest:
only:
- master
script:
- - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
+ - docker pull $CI_REGISTRY_IMAGE:tmp
+ - docker tag $CI_REGISTRY_IMAGE:tmp $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
stage: push
tags:
@@ -47,8 +47,8 @@ Push tag:
only:
- tags
script:
- - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
+ - docker pull $CI_REGISTRY_IMAGE:tmp
+ - docker tag $CI_REGISTRY_IMAGE:tmp $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
stage: push
tags:
diff --git a/app/corpora/views.py b/app/corpora/views.py
index aef61908..3a06b204 100644
--- a/app/corpora/views.py
+++ b/app/corpora/views.py
@@ -19,7 +19,7 @@ def add_corpus():
if add_corpus_form.validate_on_submit():
corpus = Corpus(creator=current_user,
description=add_corpus_form.description.data,
- title=add_corpus_form.title.data)
+ status='unprepared', title=add_corpus_form.title.data)
db.session.add(corpus)
db.session.commit()
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
@@ -113,6 +113,7 @@ def add_corpus_file(corpus_id):
corpus=corpus, dir=dir, filename=filename,
publishing_year=add_corpus_file_form.publishing_year.data,
title=add_corpus_file_form.title.data)
+ corpus_file.insert_metadata()
db.session.add(corpus_file)
db.session.commit()
flash('Corpus file added!')
@@ -166,6 +167,7 @@ def edit_corpus_file(corpus_id, corpus_file_id):
corpus_file.author = edit_corpus_file_form.author.data
corpus_file.publishing_year = edit_corpus_file_form.publishing_year.data
corpus_file.title = edit_corpus_file_form.title.data
+ corpus_file.insert_metadata()
db.session.commit()
flash('Corpus file edited!')
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
diff --git a/app/models.py b/app/models.py
index 77892c02..ac5578d1 100644
--- a/app/models.py
+++ b/app/models.py
@@ -424,6 +424,9 @@ class CorpusFile(db.Model):
db.session.delete(self)
db.session.commit()
+ def insert_metadata(self):
+ pass
+
class Corpus(db.Model):
"""
@@ -436,16 +439,12 @@ class Corpus(db.Model):
description = db.Column(db.String(255))
title = db.Column(db.String(32))
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
- status = db.Column(db.String(16))
# Relationships
files = db.relationship('CorpusFile',
backref='corpus',
lazy='dynamic',
cascade='save-update, merge, delete')
- def __init__(self, **kwargs):
- super(Corpus, self).__init__(**kwargs)
-
def __repr__(self):
"""
String representation of the corpus. For human readability.
@@ -482,6 +481,9 @@ class Corpus(db.Model):
db.session.delete(self)
db.session.commit()
+ def prepare(self):
+ pass
+
'''
' Flask-Login is told to use the application’s custom anonymous user by setting
diff --git a/app/utils.py b/app/utils.py
index 7c1d9638..6eae9d54 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -1,4 +1,4 @@
-from .models import Job, User, Corpus
+from .models import Job, User, Corpus, CorpusFile
from . import db
import logging
@@ -64,3 +64,8 @@ def background_delete_corpus(app, corpus_id):
logger.warning('Corpus id is: {}.'.format(corpus_id))
corpus = Corpus.query.filter_by(id=corpus_id).first()
corpus.delete()
+
+
+def background_prepare_corpus_file(app, corpus_file_id):
+ with app.app_context():
+ corpus_file = CorpusFile.query.filter_by(id=corpus_file_id).first()