diff --git a/app/corpora/views.py b/app/corpora/views.py index 1a220499..dc4d4ade 100644 --- a/app/corpora/views.py +++ b/app/corpora/views.py @@ -1,4 +1,4 @@ -from flask import (abort, current_app, flash, redirect, request, +from flask import (abort, current_app, flash, make_response, redirect, request, render_template, url_for, send_from_directory) from flask_login import current_user, login_required from threading import Thread @@ -99,8 +99,8 @@ def add_corpus_file(corpus_id): for corpus_file in corpus.files: if filename == corpus_file.filename: flash('File already registered to this corpus.') - return redirect(url_for('corpora.add_corpus_file', - corpus_id=corpus_id)) + return make_response({'redirect_url': url_for('corpora.corpus', corpus_id=corpus.id)}, 500) + # return redirect(url_for('corpora.add_corpus_file', corpus_id=corpus_id)) # Save the file dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id)) file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'], @@ -125,7 +125,10 @@ def add_corpus_file(corpus_id): corpus_file.id)) thread.start() flash('Corpus file added!') - return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) + return make_response( + {'redirect_url': url_for('corpora.corpus', corpus_id=corpus.id)}, + 201) + # return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) return render_template('corpora/add_corpus_file.html.j2', add_corpus_file_form=add_corpus_file_form, corpus=corpus, title='Add corpus file') diff --git a/app/models.py b/app/models.py index f8e6fbc6..d4044e57 100644 --- a/app/models.py +++ b/app/models.py @@ -426,6 +426,24 @@ class CorpusFile(db.Model): self.corpus.status = 'unprepared' db.session.commit() + def to_dict(self): + return {'id': self.id, + 'address': self.address, + 'author': self.author, + 'booktitle': self.booktitle, + 'chapter': self.chapter, + 'dir': self.dir, + 'editor': self.editor, + 'filename': self.filename, + 'institution': self.institution, + 'journal': self.journal, + 'pages': self.pages, + 'publisher': self.publisher, + 'publishing_year': self.publishing_year, + 'school': self.school, + 'title': self.title, + 'corpus_id': self.corpus_id} + class Corpus(db.Model): """ @@ -455,6 +473,7 @@ class Corpus(db.Model): return {'id': self.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} diff --git a/app/templates/corpora/add_corpus_file.html.j2 b/app/templates/corpora/add_corpus_file.html.j2 index f792f0fe..beb46ba3 100644 --- a/app/templates/corpora/add_corpus_file.html.j2 +++ b/app/templates/corpora/add_corpus_file.html.j2 @@ -8,7 +8,7 @@