nopaque/app/corpora/forms.py

87 lines
2.7 KiB
Python
Raw Normal View History

from flask_wtf import FlaskForm
2022-04-12 14:11:24 +00:00
from flask_wtf.file import FileField, FileRequired
2022-11-29 14:28:10 +00:00
from wtforms import (
BooleanField,
2022-11-29 14:28:10 +00:00
StringField,
SubmitField,
TextAreaField,
ValidationError,
IntegerField
)
2022-09-02 11:07:30 +00:00
from wtforms.validators import InputRequired, Length
2022-11-29 14:28:10 +00:00
class CorpusBaseForm(FlaskForm):
description = TextAreaField(
2022-09-02 11:07:30 +00:00
'Description',
validators=[InputRequired(), Length(max=255)]
)
title = StringField('Title', validators=[InputRequired(), Length(max=32)])
submit = SubmitField()
2022-11-29 14:28:10 +00:00
class CreateCorpusForm(CorpusBaseForm):
def __init__(self, *args, **kwargs):
if 'prefix' not in kwargs:
kwargs['prefix'] = 'create-corpus-form'
super().__init__(*args, **kwargs)
class UpdateCorpusForm(CorpusBaseForm):
def __init__(self, *args, **kwargs):
if 'prefix' not in kwargs:
kwargs['prefix'] = 'update-corpus-form'
super().__init__(*args, **kwargs)
2022-09-02 11:07:30 +00:00
class CorpusFileBaseForm(FlaskForm):
author = StringField(
'Author',
validators=[InputRequired(), Length(max=255)]
)
publishing_year = IntegerField(
'Publishing year',
validators=[InputRequired()]
)
title = StringField(
'Title',
validators=[InputRequired(), Length(max=255)]
)
address = StringField('Adress', validators=[Length(max=255)])
booktitle = StringField('Booktitle', validators=[Length(max=255)])
chapter = StringField('Chapter', validators=[Length(max=255)])
editor = StringField('Editor', validators=[Length(max=255)])
institution = StringField('Institution', validators=[Length(max=255)])
journal = StringField('Journal', validators=[Length(max=255)])
pages = StringField('Pages', validators=[Length(max=255)])
publisher = StringField('Publisher', validators=[Length(max=255)])
school = StringField('School', validators=[Length(max=255)])
2020-04-06 12:09:41 +00:00
submit = SubmitField()
2022-09-02 11:07:30 +00:00
class CreateCorpusFileForm(CorpusFileBaseForm):
vrt = FileField('File', validators=[FileRequired()])
2022-11-29 14:28:10 +00:00
def __init__(self, *args, **kwargs):
if 'prefix' not in kwargs:
kwargs['prefix'] = 'create-corpus-file-form'
super().__init__(*args, **kwargs)
2022-04-12 14:11:24 +00:00
def validate_vrt(self, field):
2020-04-06 12:09:41 +00:00
if not field.data.filename.lower().endswith('.vrt'):
2022-04-12 14:11:24 +00:00
raise ValidationError('VRT files only!')
2020-04-06 12:09:41 +00:00
2022-11-29 14:28:10 +00:00
class UpdateCorpusFileForm(CorpusFileBaseForm):
def __init__(self, *args, **kwargs):
if 'prefix' not in kwargs:
kwargs['prefix'] = 'update-corpus-file-form'
super().__init__(*args, **kwargs)
2020-04-06 12:09:41 +00:00
class ChangeCorpusSettingsForm(FlaskForm):
is_public = BooleanField('Public Corpus')
submit = SubmitField()
2020-04-06 12:09:41 +00:00
class ImportCorpusForm(FlaskForm):
2022-09-02 11:07:30 +00:00
pass