Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Patrick Jentsch 2020-01-09 16:28:00 +01:00
commit fac06310c2
6 changed files with 99 additions and 24 deletions

View File

@ -13,7 +13,7 @@ class AddCorpusFileForm(FlaskForm):
file = FileField('File', validators=[DataRequired()]) file = FileField('File', validators=[DataRequired()])
institution = StringField('institution', validators=[Length(0, 255)]) institution = StringField('institution', validators=[Length(0, 255)])
journal = StringField('Journal', validators=[Length(0, 255)]) journal = StringField('Journal', validators=[Length(0, 255)])
pages = StringField('pages', validators=[Length(0, 255)]) pages = StringField('Pages', validators=[Length(0, 255)])
publisher = StringField('Publisher', validators=[Length(0, 255)]) publisher = StringField('Publisher', validators=[Length(0, 255)])
publishing_year = IntegerField('Publishing year', validators=[DataRequired()]) publishing_year = IntegerField('Publishing year', validators=[DataRequired()])
school = StringField('School', validators=[Length(0, 255)]) school = StringField('School', validators=[Length(0, 255)])
@ -33,12 +33,8 @@ class AddCorpusForm(FlaskForm):
title = StringField('Title', validators=[DataRequired(), Length(1, 32)]) title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
class EditCorpusFileForm(FlaskForm): class EditCorpusFileForm(AddCorpusFileForm):
author = StringField('Author', validators=[DataRequired(), Length(1, 64)]) pass
publishing_year = IntegerField('Publishing year',
validators=[DataRequired()])
submit = SubmitField()
title = StringField('Title', validators=[DataRequired(), Length(1, 64)])
class QueryForm(FlaskForm): class QueryForm(FlaskForm):

View File

@ -1,4 +1,4 @@
from app import db from app import db, logger
from app.models import Corpus, CorpusFile from app.models import Corpus, CorpusFile
from flask import (abort, current_app, flash, redirect, request, from flask import (abort, current_app, flash, redirect, request,
render_template, url_for, send_from_directory) render_template, url_for, send_from_directory)
@ -97,10 +97,16 @@ def add_corpus_file(corpus_id):
dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id)) dir = os.path.join(str(corpus.user_id), 'corpora', str(corpus.id))
file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'], file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'],
dir, filename)) dir, filename))
corpus_file = CorpusFile(author=add_corpus_file_form.author.data, ids = [field.id for field in add_corpus_file_form if not
corpus=corpus, dir=dir, filename=filename, (field.id == 'submit'
publishing_year=add_corpus_file_form.publishing_year.data, or field.id == "csrf_token"
title=add_corpus_file_form.title.data) or field.id == "file")]
data = [field.data for field in add_corpus_file_form if not
(field.id == 'submit'
or field.id == "csrf_token"
or field.id == "file")]
field_dict = dict(zip(ids, data))
corpus_file = CorpusFile(**field_dict, corpus=corpus, dir=dir, filename=filename)
db.session.add(corpus_file) db.session.add(corpus_file)
db.session.commit() db.session.commit()
thread = Thread(target=edit_corpus_file_, thread = Thread(target=edit_corpus_file_,
@ -160,6 +166,7 @@ def edit_corpus_file(corpus_id, corpus_file_id):
corpus_file.author = edit_corpus_file_form.author.data corpus_file.author = edit_corpus_file_form.author.data
corpus_file.publishing_year = edit_corpus_file_form.publishing_year.data corpus_file.publishing_year = edit_corpus_file_form.publishing_year.data
corpus_file.title = edit_corpus_file_form.title.data corpus_file.title = edit_corpus_file_form.title.data
corpus_file.pages = edit_corpus_file_form.pages.data
db.session.commit() db.session.commit()
thread = Thread(target=edit_corpus_file_, thread = Thread(target=edit_corpus_file_,
args=(current_app._get_current_object(), args=(current_app._get_current_object(),

View File

@ -0,0 +1,27 @@
{% macro render_field(field) %}
<div class="input-field">
<i class="prefix">{{ field.name[0:1]|upper }}</i>
{{ field.label }}
{{ field(**kwargs)|safe }}
</div>
{% if field.errors %}
{% for error in field.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
{% endif %}
{% endmacro %}
{% macro render_field_with_value(field, corpus_file) %}
{% set field_name = field.name %}
{{ field_name }}
<div class="input-field">
<i class="prefix">{{ field.name[0:1]|upper }}</i>
{{ field.label }}
{{ field(value=corpus_file[field.name])| safe }}
</div>
{% if field.errors %}
{% for error in field.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
{% endif %}
{% endmacro %}

View File

@ -16,7 +16,7 @@
<div class="col s12 m4"> <div class="col s12 m4">
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">person</i> <i class="material-icons prefix">person</i>
{{ add_corpus_file_form.author(data_length='64') }} {{ add_corpus_file_form.author(data_length='255') }}
{{ add_corpus_file_form.author.label }} {{ add_corpus_file_form.author.label }}
{% for error in add_corpus_file_form.author.errors %} {% for error in add_corpus_file_form.author.errors %}
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
@ -26,7 +26,7 @@
<div class="col s12 m4"> <div class="col s12 m4">
<div class="input-field"> <div class="input-field">
<i class="material-icons prefix">title</i> <i class="material-icons prefix">title</i>
{{ add_corpus_file_form.title(data_length='64') }} {{ add_corpus_file_form.title(data_length='255') }}
{{ add_corpus_file_form.title.label }} {{ add_corpus_file_form.title.label }}
{% for error in add_corpus_file_form.title.errors %} {% for error in add_corpus_file_form.title.errors %}
<span class="helper-text red-text">{{ error }}</span> <span class="helper-text red-text">{{ error }}</span>
@ -71,14 +71,30 @@
<span> <span>
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
<div class="input-field"> {% from "_formhelpers.html.j2" import render_field %}
<i class="material-icons prefix">person</i> {% for field in add_corpus_file_form if not (field.name == "file"
{{ add_corpus_file_form.author(data_length='64') }} or field.name == "author"
{{ add_corpus_file_form.author.label }} or field.name == "submit"
{% for error in add_corpus_file_form.author.errors %} or field.name == "csrf_token"
<span class="helper-text red-text">{{ error }}</span> or field.name == "title"
{% endfor %} or field.name == "publishing_year") %}
</div> {{ render_field(field)}}
{% endfor %}
</div>
</div>
</span>
</div>
</li>
</ul>
<br>
<ul class="collapsible hoverable">
<li>
<div class="collapsible-header"><i class="material-icons">add</i>Add metadata with BibTex</div>
<div class="collapsible-body">
<span>
<div class="row">
<div class="col s12">
</div> </div>
</div> </div>
</span> </span>

View File

@ -47,6 +47,31 @@
<div class="card-action right-align"> <div class="card-action right-align">
<button class="btn waves-effect waves-light" id="submit" name="submit" type="submit">Submit<i class="material-icons right">send</i></button> <button class="btn waves-effect waves-light" id="submit" name="submit" type="submit">Submit<i class="material-icons right">send</i></button>
</div> </div>
<br>
<ul class="collapsible hoverable">
<li>
<div class="collapsible-header"><i class="material-icons">edit</i>Edit additional metadata</div>
<div class="collapsible-body">
<span>
<div class="row">
<div class="col s12">
{% from "_formhelpers.html.j2" import render_field_with_value %}
{% for field in edit_corpus_file_form if not (field.name == "file"
or field.name == "author"
or field.name == "submit"
or field.name == "csrf_token"
or field.name == "title"
or field.name == "publishing_year") %}
<dl>
{{ render_field_with_value(field, corpus_file)}}
</dl>
{% endfor %}
</div>
</div>
</span>
</div>
</li>
</ul>
</form> </form>
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
from app import create_app, db, socketio from app import create_app, db, socketio
from app.models import Corpus, Job, Role, User from app.models import *
from flask_migrate import Migrate from flask_migrate import Migrate
import os import os
@ -12,7 +12,11 @@ migrate = Migrate(app, db)
@app.shell_context_processor @app.shell_context_processor
def make_shell_context(): def make_shell_context():
return {'db': db, 'Corpus': Corpus, 'Job': Job, 'User': User} return {'db': db,
'Corpus': Corpus,
'Job': Job,
'User': User,
'CorpusFile': CorpusFile}
@app.cli.command() @app.cli.command()