mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Add options to add more detailed metadate to corpus file
This commit is contained in:
parent
96700586c8
commit
e1a8fbc531
@ -13,7 +13,7 @@ class AddCorpusFileForm(FlaskForm):
|
||||
file = FileField('File', validators=[DataRequired()])
|
||||
institution = StringField('institution', 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)])
|
||||
publishing_year = IntegerField('Publishing year', validators=[DataRequired()])
|
||||
school = StringField('School', validators=[Length(0, 255)])
|
||||
@ -33,12 +33,8 @@ class AddCorpusForm(FlaskForm):
|
||||
title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
|
||||
|
||||
|
||||
class EditCorpusFileForm(FlaskForm):
|
||||
author = StringField('Author', validators=[DataRequired(), Length(1, 64)])
|
||||
publishing_year = IntegerField('Publishing year',
|
||||
validators=[DataRequired()])
|
||||
submit = SubmitField()
|
||||
title = StringField('Title', validators=[DataRequired(), Length(1, 64)])
|
||||
class EditCorpusFileForm(AddCorpusFileForm):
|
||||
pass
|
||||
|
||||
|
||||
class QueryForm(FlaskForm):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from app import db
|
||||
from app import db, logger
|
||||
from app.models import Corpus, CorpusFile
|
||||
from flask import (abort, current_app, flash, redirect, request,
|
||||
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))
|
||||
file.save(os.path.join(current_app.config['NOPAQUE_STORAGE'],
|
||||
dir, filename))
|
||||
corpus_file = CorpusFile(author=add_corpus_file_form.author.data,
|
||||
corpus=corpus, dir=dir, filename=filename,
|
||||
publishing_year=add_corpus_file_form.publishing_year.data,
|
||||
title=add_corpus_file_form.title.data)
|
||||
ids = [field.id for field in add_corpus_file_form if not
|
||||
(field.id == 'submit'
|
||||
or field.id == "csrf_token"
|
||||
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.commit()
|
||||
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.publishing_year = edit_corpus_file_form.publishing_year.data
|
||||
corpus_file.title = edit_corpus_file_form.title.data
|
||||
corpus_file.pages = edit_corpus_file_form.pages.data
|
||||
db.session.commit()
|
||||
thread = Thread(target=edit_corpus_file_,
|
||||
args=(current_app._get_current_object(),
|
||||
|
27
app/templates/_formhelpers.html.j2
Normal file
27
app/templates/_formhelpers.html.j2
Normal 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 %}
|
@ -16,7 +16,7 @@
|
||||
<div class="col s12 m4">
|
||||
<div class="input-field">
|
||||
<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 }}
|
||||
{% for error in add_corpus_file_form.author.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
@ -26,7 +26,7 @@
|
||||
<div class="col s12 m4">
|
||||
<div class="input-field">
|
||||
<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 }}
|
||||
{% for error in add_corpus_file_form.title.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
@ -71,14 +71,30 @@
|
||||
<span>
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">person</i>
|
||||
{{ add_corpus_file_form.author(data_length='64') }}
|
||||
{{ add_corpus_file_form.author.label }}
|
||||
{% for error in add_corpus_file_form.author.errors %}
|
||||
<span class="helper-text red-text">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% from "_formhelpers.html.j2" import render_field %}
|
||||
{% for field in add_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") %}
|
||||
{{ 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>
|
||||
</span>
|
||||
|
@ -47,6 +47,31 @@
|
||||
<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>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
from app import create_app, db, socketio
|
||||
from app.models import Corpus, Job, Role, User
|
||||
from app.models import *
|
||||
from flask_migrate import Migrate
|
||||
import os
|
||||
|
||||
@ -12,7 +12,11 @@ migrate = Migrate(app, db)
|
||||
|
||||
@app.shell_context_processor
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user