|
|
@ -1,6 +1,6 @@
|
|
|
|
from wtforms import Form
|
|
|
|
from wtforms import Form
|
|
|
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, FileField, MultipleFileField, ValidationError, RadioField, TextAreaField, HiddenField, SelectField, IntegerField
|
|
|
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField, FileField, MultipleFileField, ValidationError, RadioField, TextAreaField, HiddenField, SelectField, IntegerField
|
|
|
|
from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional, StopValidation, URL
|
|
|
|
from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional, StopValidation, URL, Regexp
|
|
|
|
|
|
|
|
|
|
|
|
from werkzeug.utils import cached_property
|
|
|
|
from werkzeug.utils import cached_property
|
|
|
|
|
|
|
|
|
|
|
@ -8,7 +8,7 @@ from flask import current_app, flash
|
|
|
|
from flask_wtf.csrf import _FlaskFormCSRF
|
|
|
|
from flask_wtf.csrf import _FlaskFormCSRF
|
|
|
|
|
|
|
|
|
|
|
|
from yadc.models import USER_STATUS, OP_LEVEL, RATING, POST_STATUS, TAG_CATEGORY
|
|
|
|
from yadc.models import USER_STATUS, OP_LEVEL, RATING, POST_STATUS, TAG_CATEGORY
|
|
|
|
from yadc.models import User, Post
|
|
|
|
from yadc.models import User, Post, Tag
|
|
|
|
|
|
|
|
|
|
|
|
class CSRFForm(Form):
|
|
|
|
class CSRFForm(Form):
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
@ -179,10 +179,16 @@ class PostForm(EditForm):
|
|
|
|
approve = SubmitField('Approve')
|
|
|
|
approve = SubmitField('Approve')
|
|
|
|
|
|
|
|
|
|
|
|
class TagForm(EditForm):
|
|
|
|
class TagForm(EditForm):
|
|
|
|
content = StringField('Content', validators=[validate_create_required], render_kw=dict(autocomplete='off'))
|
|
|
|
content = StringField('Content', validators=[optional(), validate_create_required, Regexp('^[a-zA-Z0-9\-\_\ ]+$')], render_kw=dict(autocomplete='off'))
|
|
|
|
category = SelectField('Category',
|
|
|
|
category = SelectField('Category',
|
|
|
|
choices=[(e.name, e.name.capitalize()) for e in TAG_CATEGORY],
|
|
|
|
choices=[(e.name, e.name.capitalize()) for e in TAG_CATEGORY],
|
|
|
|
validators=[optional()])
|
|
|
|
validators=[optional()]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_content(form, field):
|
|
|
|
|
|
|
|
if form.create.data and Tag.query.filter_by(content=field.data).first():
|
|
|
|
|
|
|
|
raise ValidationError('Tag already exists.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Creation/editing only through post page
|
|
|
|
# Creation/editing only through post page
|
|
|
|
class CommentForm(EditForm):
|
|
|
|
class CommentForm(EditForm):
|
|
|
|