2023-02-21 15:18:04 +00:00
|
|
|
from datetime import datetime, timedelta
|
2022-02-08 11:26:20 +00:00
|
|
|
from flask import (
|
|
|
|
abort,
|
|
|
|
current_app,
|
|
|
|
flash,
|
2023-02-20 15:15:17 +00:00
|
|
|
make_response,
|
2022-09-02 11:07:30 +00:00
|
|
|
Markup,
|
2022-02-08 11:26:20 +00:00
|
|
|
redirect,
|
|
|
|
render_template,
|
2023-01-31 07:59:42 +00:00
|
|
|
request,
|
2023-02-21 15:18:04 +00:00
|
|
|
send_from_directory,
|
|
|
|
url_for
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
2020-04-06 12:12:22 +00:00
|
|
|
from flask_login import current_user, login_required
|
2022-09-02 11:07:30 +00:00
|
|
|
from threading import Thread
|
2023-02-10 08:37:31 +00:00
|
|
|
import jwt
|
2020-04-06 12:12:22 +00:00
|
|
|
import os
|
2023-03-01 13:09:15 +00:00
|
|
|
from .decorators import corpus_follower_permission_required, corpus_owner_or_admin_required
|
2023-01-31 07:59:42 +00:00
|
|
|
from app import db, hashids
|
2023-02-15 15:17:25 +00:00
|
|
|
from app.models import (
|
|
|
|
Corpus,
|
|
|
|
CorpusFile,
|
|
|
|
CorpusFollowerAssociation,
|
2023-02-20 09:40:33 +00:00
|
|
|
CorpusFollowerPermission,
|
2023-02-23 12:05:04 +00:00
|
|
|
CorpusFollowerRole,
|
2023-02-15 15:17:25 +00:00
|
|
|
CorpusStatus,
|
|
|
|
User
|
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
from . import bp
|
2023-02-15 09:56:54 +00:00
|
|
|
from .forms import (
|
|
|
|
CreateCorpusFileForm,
|
|
|
|
CreateCorpusForm,
|
|
|
|
UpdateCorpusFileForm
|
|
|
|
)
|
|
|
|
|
2023-02-21 15:23:10 +00:00
|
|
|
@bp.route('/fake-add')
|
|
|
|
@login_required
|
|
|
|
def fake_add():
|
|
|
|
pjentsch = User.query.filter_by(username='pjentsch').first()
|
|
|
|
alice = Corpus.query.filter_by(title='Alice in Wonderland').first()
|
|
|
|
pjentsch.follow_corpus(alice)
|
|
|
|
db.session.commit()
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
2023-02-20 09:40:33 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/is_public/enable', methods=['POST'])
|
2023-02-15 09:56:54 +00:00
|
|
|
@login_required
|
2023-03-01 13:09:15 +00:00
|
|
|
@corpus_owner_or_admin_required()
|
2023-02-15 09:56:54 +00:00
|
|
|
def enable_corpus_is_public(corpus_id):
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
corpus.is_public = True
|
|
|
|
db.session.commit()
|
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
2023-02-20 09:40:33 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/is_public/disable', methods=['POST'])
|
2023-02-15 09:56:54 +00:00
|
|
|
@login_required
|
2023-03-01 13:09:15 +00:00
|
|
|
@corpus_owner_or_admin_required()
|
2023-02-15 09:56:54 +00:00
|
|
|
def disable_corpus_is_public(corpus_id):
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
corpus.is_public = False
|
|
|
|
db.session.commit()
|
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
2023-02-21 15:18:04 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/follow/<token>')
|
|
|
|
@login_required
|
|
|
|
def follow_corpus(corpus_id, token):
|
2023-03-02 08:57:43 +00:00
|
|
|
if current_user.follow_corpus_by_token(token):
|
2023-02-22 15:00:04 +00:00
|
|
|
db.session.commit()
|
|
|
|
flash(f'You are following {corpus.title} now', category='corpus')
|
2023-03-02 08:57:43 +00:00
|
|
|
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
|
|
|
abort(403)
|
2022-11-29 14:28:10 +00:00
|
|
|
|
|
|
|
|
2023-02-20 15:15:17 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/unfollow', methods=['POST'])
|
2022-11-29 14:28:10 +00:00
|
|
|
@login_required
|
2023-02-20 15:15:17 +00:00
|
|
|
def unfollow_corpus(corpus_id, follower_id):
|
2023-02-21 10:05:09 +00:00
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
follower = User.query.get_or_404(follower_id)
|
|
|
|
if not (corpus.user == current_user or follower == current_user or current_user.is_administrator()):
|
2023-02-15 09:56:54 +00:00
|
|
|
abort(403)
|
2023-02-21 10:05:09 +00:00
|
|
|
if not follower.is_following_corpus(corpus):
|
2023-02-20 15:15:17 +00:00
|
|
|
abort(409) # 'User is not following the corpus'
|
2023-02-21 10:05:09 +00:00
|
|
|
follower.unfollow_corpus(corpus)
|
2023-02-20 15:15:17 +00:00
|
|
|
db.session.commit()
|
2023-02-21 10:05:09 +00:00
|
|
|
flash(f'{follower.username} is not following {corpus.title} anymore', category='corpus')
|
2023-02-20 15:15:17 +00:00
|
|
|
return '', 204
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/<hashid:corpus_id>/unfollow', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
def current_user_unfollow_corpus(corpus_id):
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
if not current_user.is_following_corpus(corpus):
|
|
|
|
abort(409) # 'You are not following the corpus'
|
|
|
|
current_user.unfollow_corpus(corpus)
|
2023-02-15 09:56:54 +00:00
|
|
|
db.session.commit()
|
|
|
|
flash(f'You are not following {corpus.title} anymore', category='corpus')
|
2023-02-15 15:17:25 +00:00
|
|
|
return '', 204
|
2023-02-15 09:56:54 +00:00
|
|
|
|
|
|
|
|
2023-02-23 12:05:04 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['POST'])
|
2023-03-01 13:09:15 +00:00
|
|
|
@corpus_follower_permission_required('REMOVE_FOLLOWER', 'UPDATE_FOLLOWER')
|
2023-02-23 12:05:04 +00:00
|
|
|
def add_permission(corpus_id, follower_id):
|
2023-02-21 10:05:09 +00:00
|
|
|
corpus_follower_association = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
|
|
|
if not (corpus_follower_association.corpus.user == current_user or current_user.is_administrator()):
|
2023-02-15 15:17:25 +00:00
|
|
|
abort(403)
|
2023-02-23 12:05:04 +00:00
|
|
|
role_name = request.json.get('role')
|
|
|
|
if role_name is None:
|
|
|
|
abort(400)
|
|
|
|
corpus_follower_role = CorpusFollowerRole.query.filter_by(name=role_name).first_or_404()
|
|
|
|
corpus_follower_association.role = corpus_follower_role
|
2023-02-15 15:17:25 +00:00
|
|
|
db.session.commit()
|
|
|
|
return '', 204
|
2023-02-15 09:56:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/public')
|
|
|
|
@login_required
|
|
|
|
def public_corpora():
|
|
|
|
corpora = [
|
|
|
|
c.to_json_serializeable()
|
|
|
|
for c in Corpus.query.filter(Corpus.is_public == True).all()
|
|
|
|
]
|
|
|
|
return render_template(
|
|
|
|
'corpora/public_corpora.html.j2',
|
|
|
|
corpora=corpora,
|
|
|
|
title='Corpora'
|
2022-11-30 13:58:45 +00:00
|
|
|
)
|
2020-04-06 12:12:22 +00:00
|
|
|
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
@bp.route('/create', methods=['GET', 'POST'])
|
2020-04-06 12:12:22 +00:00
|
|
|
@login_required
|
2022-09-02 11:07:30 +00:00
|
|
|
def create_corpus():
|
2022-11-30 13:58:45 +00:00
|
|
|
form = CreateCorpusForm()
|
2020-11-13 09:01:51 +00:00
|
|
|
if form.validate_on_submit():
|
2020-04-06 12:12:22 +00:00
|
|
|
try:
|
2022-09-02 11:07:30 +00:00
|
|
|
corpus = Corpus.create(
|
|
|
|
title=form.title.data,
|
|
|
|
description=form.description.data,
|
|
|
|
user=current_user
|
|
|
|
)
|
|
|
|
except OSError:
|
2020-11-13 09:01:51 +00:00
|
|
|
abort(500)
|
2022-02-03 11:39:16 +00:00
|
|
|
db.session.commit()
|
2022-09-02 11:07:30 +00:00
|
|
|
message = Markup(
|
|
|
|
f'Corpus "<a href="{corpus.url}">{corpus.title}</a>" created'
|
2021-11-16 14:23:57 +00:00
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
flash(message, 'corpus')
|
|
|
|
return redirect(corpus.url)
|
2022-02-08 11:26:20 +00:00
|
|
|
return render_template(
|
2022-09-02 11:07:30 +00:00
|
|
|
'corpora/create_corpus.html.j2',
|
2022-02-08 11:26:20 +00:00
|
|
|
form=form,
|
2022-09-02 11:07:30 +00:00
|
|
|
title='Create corpus'
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
2020-10-29 14:20:30 +00:00
|
|
|
|
|
|
|
|
2023-02-21 15:18:04 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>')
|
2020-04-06 12:12:22 +00:00
|
|
|
@login_required
|
|
|
|
def corpus(corpus_id):
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
2023-02-21 15:18:04 +00:00
|
|
|
exp_date = (datetime.utcnow() + timedelta(days=7)).strftime('%b %d, %Y')
|
2023-02-24 14:22:26 +00:00
|
|
|
roles = [x.name for x in CorpusFollowerRole.query.all()]
|
2023-02-15 09:56:54 +00:00
|
|
|
if corpus.user == current_user or current_user.is_administrator():
|
2023-02-09 10:05:27 +00:00
|
|
|
return render_template(
|
|
|
|
'corpora/corpus.html.j2',
|
|
|
|
corpus=corpus,
|
2023-02-21 15:18:04 +00:00
|
|
|
exp_date=exp_date,
|
2023-02-24 14:22:26 +00:00
|
|
|
roles=roles,
|
2023-02-09 10:05:27 +00:00
|
|
|
title='Corpus'
|
|
|
|
)
|
2023-02-15 09:56:54 +00:00
|
|
|
if current_user.is_following_corpus(corpus) or corpus.is_public:
|
2023-03-02 08:57:43 +00:00
|
|
|
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first_or_404()
|
2023-02-09 11:02:00 +00:00
|
|
|
corpus_files = [x.to_json_serializeable() for x in corpus.files]
|
2023-02-24 14:22:26 +00:00
|
|
|
owner = corpus.user.to_json_serializeable()
|
2023-02-09 10:05:27 +00:00
|
|
|
return render_template(
|
2023-02-15 09:56:54 +00:00
|
|
|
'corpora/public_corpus.html.j2',
|
2023-02-09 10:05:27 +00:00
|
|
|
corpus=corpus,
|
2023-02-09 11:02:00 +00:00
|
|
|
corpus_files=corpus_files,
|
2023-03-02 08:57:43 +00:00
|
|
|
cfa=cfa,
|
2023-02-24 14:22:26 +00:00
|
|
|
owner=owner,
|
|
|
|
title='Corpus',
|
2023-02-09 10:05:27 +00:00
|
|
|
)
|
2023-02-15 09:56:54 +00:00
|
|
|
abort(403)
|
2022-11-29 14:28:10 +00:00
|
|
|
|
2023-02-21 15:18:04 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/generate-corpus-share-link', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
2023-02-28 09:27:10 +00:00
|
|
|
@corpus_follower_permission_required('GENERATE_SHARE_LINK')
|
2023-02-21 15:18:04 +00:00
|
|
|
def generate_corpus_share_link(corpus_id):
|
|
|
|
data = request.get_json('data')
|
2023-02-24 14:22:26 +00:00
|
|
|
role = data['role']
|
2023-02-22 15:00:04 +00:00
|
|
|
exp_data = data['expiration']
|
|
|
|
expiration = datetime.strptime(exp_data, '%b %d, %Y')
|
2023-02-24 14:22:26 +00:00
|
|
|
token = current_user.generate_follow_corpus_token(corpus_id, role, expiration)
|
2023-02-21 15:18:04 +00:00
|
|
|
link = url_for('corpora.follow_corpus', corpus_id=corpus_id, token=token, _external=True)
|
|
|
|
return link
|
|
|
|
|
2022-11-29 14:28:10 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
|
|
|
@login_required
|
2023-03-01 13:09:15 +00:00
|
|
|
@corpus_owner_or_admin_required()
|
2022-09-02 11:07:30 +00:00
|
|
|
def delete_corpus(corpus_id):
|
|
|
|
def _delete_corpus(app, corpus_id):
|
|
|
|
with app.app_context():
|
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
corpus.delete()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
thread = Thread(
|
|
|
|
target=_delete_corpus,
|
|
|
|
args=(current_app._get_current_object(), corpus_id)
|
|
|
|
)
|
|
|
|
thread.start()
|
|
|
|
return {}, 202
|
|
|
|
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/analyse')
|
2021-11-16 14:23:57 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_follower_permission_required('VIEW')
|
2021-11-16 14:23:57 +00:00
|
|
|
def analyse_corpus(corpus_id):
|
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
|
|
|
return render_template(
|
|
|
|
'corpora/analyse_corpus.html.j2',
|
|
|
|
corpus=corpus,
|
|
|
|
title=f'Analyse Corpus {corpus.title}'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/build', methods=['POST'])
|
2022-04-19 09:48:44 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_owner_or_admin_required()
|
2022-04-19 09:48:44 +00:00
|
|
|
def build_corpus(corpus_id):
|
2022-09-02 11:07:30 +00:00
|
|
|
def _build_corpus(app, corpus_id):
|
|
|
|
with app.app_context():
|
|
|
|
corpus = Corpus.query.get(corpus_id)
|
|
|
|
corpus.build()
|
|
|
|
db.session.commit()
|
2022-04-19 09:48:44 +00:00
|
|
|
|
2020-04-06 12:12:22 +00:00
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
2023-02-09 10:05:27 +00:00
|
|
|
if not (corpus.user == current_user or current_user.is_administrator()):
|
2020-04-06 12:12:22 +00:00
|
|
|
abort(403)
|
2022-09-02 11:07:30 +00:00
|
|
|
# Check if the corpus has corpus files
|
|
|
|
if not corpus.files.all():
|
|
|
|
response = {'errors': {'message': 'Corpus file(s) required'}}
|
|
|
|
return response, 409
|
|
|
|
thread = Thread(
|
|
|
|
target=_build_corpus,
|
|
|
|
args=(current_app._get_current_object(), corpus_id)
|
|
|
|
)
|
|
|
|
thread.start()
|
|
|
|
return {}, 202
|
2020-04-06 12:12:22 +00:00
|
|
|
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/files/create', methods=['GET', 'POST'])
|
2022-04-19 09:48:44 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_follower_permission_required('ADD_CORPUS_FILE')
|
2022-09-02 11:07:30 +00:00
|
|
|
def create_corpus_file(corpus_id):
|
2022-04-19 09:48:44 +00:00
|
|
|
corpus = Corpus.query.get_or_404(corpus_id)
|
2023-02-09 10:05:27 +00:00
|
|
|
if not (corpus.user == current_user or current_user.is_administrator()):
|
2022-04-19 09:48:44 +00:00
|
|
|
abort(403)
|
2022-11-30 13:58:45 +00:00
|
|
|
form = CreateCorpusFileForm()
|
2022-09-02 11:07:30 +00:00
|
|
|
if form.is_submitted():
|
|
|
|
if not form.validate():
|
|
|
|
response = {'errors': form.errors}
|
|
|
|
return response, 400
|
|
|
|
try:
|
|
|
|
corpus_file = CorpusFile.create(
|
|
|
|
form.vrt.data,
|
|
|
|
address=form.address.data,
|
|
|
|
author=form.author.data,
|
|
|
|
booktitle=form.booktitle.data,
|
|
|
|
chapter=form.chapter.data,
|
|
|
|
editor=form.editor.data,
|
|
|
|
institution=form.institution.data,
|
|
|
|
journal=form.journal.data,
|
|
|
|
pages=form.pages.data,
|
|
|
|
publisher=form.publisher.data,
|
|
|
|
publishing_year=form.publishing_year.data,
|
|
|
|
school=form.school.data,
|
|
|
|
title=form.title.data,
|
|
|
|
mimetype='application/vrt+xml',
|
|
|
|
corpus=corpus
|
|
|
|
)
|
2022-10-11 09:32:50 +00:00
|
|
|
except (AttributeError, OSError):
|
2022-09-02 11:07:30 +00:00
|
|
|
abort(500)
|
|
|
|
corpus.status = CorpusStatus.UNPREPARED
|
|
|
|
db.session.commit()
|
|
|
|
message = Markup(
|
|
|
|
'Corpus file'
|
|
|
|
f'"<a href="{corpus_file.url}">{corpus_file.filename}</a>" added'
|
|
|
|
)
|
|
|
|
flash(message, category='corpus')
|
|
|
|
return {}, 201, {'Location': corpus.url}
|
|
|
|
return render_template(
|
|
|
|
'corpora/create_corpus_file.html.j2',
|
|
|
|
corpus=corpus,
|
|
|
|
form=form,
|
|
|
|
title='Add corpus file'
|
2022-04-19 09:48:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-29 14:28:10 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/files/<hashid:corpus_file_id>', methods=['GET', 'POST'])
|
2022-04-19 09:48:44 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_follower_permission_required('ADD_CORPUS_FILE', 'UPDATE_CORPUS_FILE', 'REMOVE_CORPUS_FILE')
|
2022-04-19 09:48:44 +00:00
|
|
|
def corpus_file(corpus_id, corpus_file_id):
|
2022-11-29 14:28:10 +00:00
|
|
|
corpus_file = CorpusFile.query.filter_by(corpus_id = corpus_id, id=corpus_file_id).first_or_404()
|
2022-11-30 13:58:45 +00:00
|
|
|
form = UpdateCorpusFileForm(data=corpus_file.to_json_serializeable())
|
2022-04-19 09:48:44 +00:00
|
|
|
if form.validate_on_submit():
|
2022-11-17 09:46:16 +00:00
|
|
|
form.populate_obj(corpus_file)
|
|
|
|
if db.session.is_modified(corpus_file):
|
2022-09-02 11:07:30 +00:00
|
|
|
corpus_file.corpus.status = CorpusStatus.UNPREPARED
|
2022-11-17 09:46:16 +00:00
|
|
|
db.session.commit()
|
|
|
|
message = Markup(f'Corpus file "<a href="{corpus_file.url}">{corpus_file.filename}</a>" updated')
|
|
|
|
flash(message, category='corpus')
|
2022-09-02 11:07:30 +00:00
|
|
|
return redirect(corpus_file.corpus.url)
|
2022-04-19 09:48:44 +00:00
|
|
|
return render_template(
|
|
|
|
'corpora/corpus_file.html.j2',
|
|
|
|
corpus=corpus_file.corpus,
|
|
|
|
corpus_file=corpus_file,
|
|
|
|
form=form,
|
|
|
|
title='Edit corpus file'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/files/<hashid:corpus_file_id>', methods=['DELETE'])
|
2020-04-06 12:12:22 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_follower_permission_required('REMOVE_CORPUS_FILE')
|
2020-04-06 12:12:22 +00:00
|
|
|
def delete_corpus_file(corpus_id, corpus_file_id):
|
2022-09-02 11:07:30 +00:00
|
|
|
def _delete_corpus_file(app, corpus_file_id):
|
|
|
|
with app.app_context():
|
|
|
|
corpus_file = CorpusFile.query.get(corpus_file_id)
|
|
|
|
corpus_file.delete()
|
|
|
|
db.session.commit()
|
|
|
|
|
2022-11-29 14:28:10 +00:00
|
|
|
corpus_file = CorpusFile.query.filter_by(corpus_id = corpus_id, id=corpus_file_id).first_or_404()
|
2022-09-02 11:07:30 +00:00
|
|
|
if not (corpus_file.corpus.user == current_user or current_user.is_administrator()):
|
2020-04-06 12:12:22 +00:00
|
|
|
abort(403)
|
2022-09-02 11:07:30 +00:00
|
|
|
thread = Thread(
|
|
|
|
target=_delete_corpus_file,
|
|
|
|
args=(current_app._get_current_object(), corpus_file_id)
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
thread.start()
|
|
|
|
return {}, 202
|
2020-04-06 12:12:22 +00:00
|
|
|
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
@bp.route('/<hashid:corpus_id>/files/<hashid:corpus_file_id>/download')
|
2020-04-06 12:12:22 +00:00
|
|
|
@login_required
|
2023-03-01 14:14:51 +00:00
|
|
|
@corpus_follower_permission_required('VIEW')
|
2020-04-06 12:12:22 +00:00
|
|
|
def download_corpus_file(corpus_id, corpus_file_id):
|
2022-11-29 14:28:10 +00:00
|
|
|
corpus_file = CorpusFile.query.filter_by(corpus_id = corpus_id, id=corpus_file_id).first_or_404()
|
2022-09-02 11:07:30 +00:00
|
|
|
if not (corpus_file.corpus.user == current_user or current_user.is_administrator()):
|
2020-04-06 12:12:22 +00:00
|
|
|
abort(403)
|
2022-02-08 11:26:20 +00:00
|
|
|
return send_from_directory(
|
2022-09-02 11:07:30 +00:00
|
|
|
os.path.dirname(corpus_file.path),
|
|
|
|
os.path.basename(corpus_file.path),
|
2022-02-08 11:26:20 +00:00
|
|
|
as_attachment=True,
|
2022-04-12 14:11:24 +00:00
|
|
|
attachment_filename=corpus_file.filename,
|
2022-09-02 11:07:30 +00:00
|
|
|
mimetype=corpus_file.mimetype
|
2022-07-08 09:46:47 +00:00
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/import', methods=['GET', 'POST'])
|
|
|
|
@login_required
|
|
|
|
def import_corpus():
|
|
|
|
abort(503)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/<hashid:corpus_id>/export')
|
|
|
|
@login_required
|
|
|
|
def export_corpus(corpus_id):
|
|
|
|
abort(503)
|