mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Extend CorpusList for use in public corpora route
This commit is contained in:
parent
5491cb184a
commit
c8d7de434f
@ -31,14 +31,17 @@ def user_can_delete_corpus(user, corpus):
|
||||
@bp.route('')
|
||||
@login_required
|
||||
def corpora():
|
||||
corpora = Corpus.query.filter(Corpus.user_id == current_user.id | Corpus.is_public == True).all()
|
||||
return render_template('corpora/corpora.html', corpora=corpora)
|
||||
query = Corpus.query.filter(
|
||||
(Corpus.user_id == current_user.id) | (Corpus.is_public == True)
|
||||
)
|
||||
corpora = [c.to_json_serializeable() for c in query.all()]
|
||||
return render_template('corpora/corpora.html.j2', corpora=corpora, title='Corpora')
|
||||
|
||||
|
||||
@bp.route('/create', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def create_corpus():
|
||||
form = CreateCorpusForm(prefix='create-corpus-form')
|
||||
form = CreateCorpusForm()
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
corpus = Corpus.create(
|
||||
@ -150,7 +153,7 @@ def create_corpus_file(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not user_can_update_corpus(current_user, corpus):
|
||||
abort(403)
|
||||
form = CreateCorpusFileForm(prefix='create-corpus-file-form')
|
||||
form = CreateCorpusFileForm()
|
||||
if form.is_submitted():
|
||||
if not form.validate():
|
||||
response = {'errors': form.errors}
|
||||
@ -197,10 +200,7 @@ def corpus_file(corpus_id, corpus_file_id):
|
||||
corpus_file = CorpusFile.query.filter_by(corpus_id = corpus_id, id=corpus_file_id).first_or_404()
|
||||
if not (corpus_file.corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
form = UpdateCorpusFileForm(
|
||||
data=corpus_file.to_json_serializeable(),
|
||||
prefix='edit-corpus-file-form'
|
||||
)
|
||||
form = UpdateCorpusFileForm(data=corpus_file.to_json_serializeable())
|
||||
if form.validate_on_submit():
|
||||
form.populate_obj(corpus_file)
|
||||
if db.session.is_modified(corpus_file):
|
||||
|
@ -1,4 +1,12 @@
|
||||
class CorpusList extends RessourceList {
|
||||
static instances = [];
|
||||
|
||||
static getInstance(elem) {
|
||||
return CorpusList.instances.find((instance) => {
|
||||
return instance.listjs.list === elem;
|
||||
});
|
||||
}
|
||||
|
||||
static autoInit() {
|
||||
for (let corpusListElement of document.querySelectorAll('.corpus-list:not(.no-autoinit)')) {
|
||||
new CorpusList(corpusListElement);
|
||||
@ -59,6 +67,7 @@ class CorpusList extends RessourceList {
|
||||
|
||||
constructor(listElement, options = {}) {
|
||||
super(listElement, {...CorpusList.options, ...options});
|
||||
CorpusList.instances.push(this);
|
||||
}
|
||||
|
||||
init(user) {
|
||||
|
28
app/templates/corpora/corpora.html.j2
Normal file
28
app/templates/corpora/corpora.html.j2
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends "base.html.j2" %}
|
||||
|
||||
{% block page_content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<h1 id="title">{{ title }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="col s12" id="corpora">
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<div class="corpus-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock page_content %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
let corpusList = CorpusList.getInstance(document.querySelector('#corpora .corpus-list .list'));
|
||||
corpusList._init({{ corpora|tojson }});
|
||||
</script>
|
||||
{% endblock scripts %}
|
Loading…
Reference in New Issue
Block a user