From 66a2fcdb34b5c4a0262765167f84ca46fdc2f246 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Mon, 6 Apr 2020 14:09:41 +0200 Subject: [PATCH] update new forms --- app/corpora/pj_forms.py | 54 ++++++++++++++++++++++++++++++++++++++--- app/corpora/pj_views.py | 6 ++--- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/corpora/pj_forms.py b/app/corpora/pj_forms.py index ef22c55f..939f491c 100644 --- a/app/corpora/pj_forms.py +++ b/app/corpora/pj_forms.py @@ -1,15 +1,63 @@ from flask_wtf import FlaskForm -from wtforms import BooleanField, StringField, SubmitField, SelectField +from wtforms import (BooleanField, FileField, StringField, SubmitField, + ValidationError, IntegerField, SelectField) from wtforms.validators import DataRequired, Length -class PJQueryForm(FlaskForm): +class AddCorpusFileForm(FlaskForm): + address = StringField('Adress', validators=[Length(0, 255)]) + author = StringField('Author', validators=[DataRequired(), Length(1, 255)]) + booktitle = StringField('Booktitle', validators=[Length(0, 255)]) + chapter = StringField('Chapter', validators=[Length(0, 255)]) + editor = StringField('Editor', validators=[Length(0, 255)]) + 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)]) + publisher = StringField('Publisher', validators=[Length(0, 255)]) + publishing_year = IntegerField('Publishing year', + validators=[DataRequired()]) + school = StringField('School', validators=[Length(0, 255)]) + submit = SubmitField() + title = StringField('Title', validators=[DataRequired(), Length(1, 255)]) + + def validate_file(form, field): + if not field.data.filename.lower().endswith('.vrt'): + raise ValidationError('File does not have an approved extension: ' + '.vrt') + + +class EditCorpusFileForm(FlaskForm): + address = StringField('Adress', validators=[Length(0, 255)]) + author = StringField('Author', validators=[DataRequired(), Length(1, 255)]) + booktitle = StringField('Booktitle', validators=[Length(0, 255)]) + chapter = StringField('Chapter', validators=[Length(0, 255)]) + editor = StringField('Editor', validators=[Length(0, 255)]) + institution = StringField('Institution', validators=[Length(0, 255)]) + journal = StringField('Journal', 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)]) + submit = SubmitField() + title = StringField('Title', validators=[DataRequired(), Length(1, 255)]) + + +class AddCorpusForm(FlaskForm): + description = StringField('Description', + validators=[DataRequired(), Length(1, 255)]) + submit = SubmitField() + title = StringField('Title', validators=[DataRequired(), Length(1, 32)]) + + +class QueryForm(FlaskForm): query = StringField('Query', validators=[DataRequired(), Length(1, 1024)]) submit = SubmitField('Send query') -class PJDisplayOptionsForm(FlaskForm): +class DisplayOptionsForm(FlaskForm): expert_mode = BooleanField('Expert mode') result_context = SelectField('Result context', choices=[('', 'Choose your option'), diff --git a/app/corpora/pj_views.py b/app/corpora/pj_views.py index eeb3a432..5a562429 100644 --- a/app/corpora/pj_views.py +++ b/app/corpora/pj_views.py @@ -1,7 +1,7 @@ from flask import request, render_template from flask_login import login_required from . import corpora -from .pj_forms import PJDisplayOptionsForm, PJQueryForm, QueryDownloadForm +from .pj_forms import DisplayOptionsForm, QueryForm, QueryDownloadForm from .. import db from ..models import Corpus @@ -13,11 +13,11 @@ def pj_analyse_corpus(corpus_id): if corpus.status == 'prepared': corpus.status = 'start analysis' db.session.commit() - display_options_form = PJDisplayOptionsForm( + display_options_form = DisplayOptionsForm( prefix='display-options-form', result_context=request.args.get('context', 20), results_per_page=request.args.get('results_per_page', 30)) - query_form = PJQueryForm(prefix='query-form', + query_form = QueryForm(prefix='query-form', query=request.args.get('query')) query_download_form = QueryDownloadForm() return render_template('corpora/pj_analyse_corpus.html.j2',