1
1
Fork 0

Fix when checking field values in form endpoints,

plus common tag filter/edit field prep
dev
Jan Kužílek 5 years ago
parent e04965c1f1
commit 7860622de7

@ -94,9 +94,9 @@ def modify_user():
elif form.edit.data: elif form.edit.data:
# if form.username.data: el.username = form.username.data # if form.username.data: el.username = form.username.data
if form.email.data: el.email = form.email.data if form.email.raw_data and form.email.data: el.email = form.email.data
if form.user_status.data: el.user_status = form.user_status.data if form.user_status.raw_data and form.user_status.data: el.user_status = form.user_status.data
if form.op_level.data: el.op_level = form.op_level.data if form.op_level.raw_data and form.op_level.data: el.op_level = form.op_level.data
db.session.commit() db.session.commit()
flash('Changes to {} have been applied.'.format(str(el))) flash('Changes to {} have been applied.'.format(str(el)))
@ -124,9 +124,14 @@ def modify_post():
db.session.commit() db.session.commit()
flash('{} deleted.'.format(str(el))) flash('{} deleted.'.format(str(el)))
elif form.edit.data: elif form.edit.data:
if form.rating.data: el.rating = form.rating.data if form.rating.raw_data and form.rating.data: el.rating = form.rating.data
if form.status.data: el.status = form.status.data if form.status.raw_data and form.status.data: el.status = form.status.data
if form.source.data: el.source = form.source.data if form.source.raw_data and form.source.data: el.source = form.source.data
if form.tags.raw_data and form.tags.raw_data:
f_tags = form.tags.data.split()
tags = Tag.query.filter(Tag.content.in_(f_tags)).all()
el.tags = tags
db.session.commit() db.session.commit()
flash('Changes to {} have been applied.'.format(str(el))) flash('Changes to {} have been applied.'.format(str(el)))
@ -168,7 +173,7 @@ def modify_tag():
flash('{} deleted.'.format(str(el))) flash('{} deleted.'.format(str(el)))
elif form.edit.data: elif form.edit.data:
# if form.content.data: el.content = form.content.data # if form.content.data: el.content = form.content.data
if form.category.data: el.category = form.category.data if form.category.raw_data and form.category.data: el.category = form.category.data
db.session.commit() db.session.commit()
flash('Changes to {} have been applied.'.format(str(el))) flash('Changes to {} have been applied.'.format(str(el)))
@ -201,7 +206,7 @@ def modify_comment():
db.session.commit() db.session.commit()
flash('{} deleted.'.format(str(el))) flash('{} deleted.'.format(str(el)))
elif form.edit.data: elif form.edit.data:
if form.content.data: el.content = form.content.data.strip() if form.content.raw_data and form.content.data: el.content = form.content.data.strip()
db.session.commit() db.session.commit()
flash('Changes to {} have been applied.'.format(str(el))) flash('Changes to {} have been applied.'.format(str(el)))

@ -31,7 +31,8 @@ def posts(page):
# PARSING ARGUMENTS # PARSING ARGUMENTS
f_tags = request.args.get('tags', '').split() f_tags = request.args.get('tags', '').split()
f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'), RATING.safe) # f_rating = {r.name : r for r in RATING}.get(request.args.get('rating'), RATING.safe)
f_rating = current_user.rating if current_user.is_authenticated else RATING.safe
m_ratings = f_rating.matched m_ratings = f_rating.matched
# filter user's blacklist # filter user's blacklist
@ -53,6 +54,9 @@ def posts(page):
@bp.route('/show/<int:id>') @bp.route('/show/<int:id>')
def post_show(id): def post_show(id):
post = Post.query.filter_by(id=id).first() post = Post.query.filter_by(id=id).first()
if not post:
flash('This post does not exist.')
return redirect(url_for('.posts'))
tags_count = db.session.query(Tag, func.count(Post.id)).join(Tag.posts).filter(Post.id==id).join(aliased(Post), Tag.posts).group_by(Tag).all() tags_count = db.session.query(Tag, func.count(Post.id)).join(Tag.posts).filter(Post.id==id).join(aliased(Post), Tag.posts).group_by(Tag).all()
for tag,tag.count in tags_count: for tag,tag.count in tags_count:
@ -61,7 +65,20 @@ def post_show(id):
for comment in post.comments: for comment in post.comments:
comment.editform = CommentForm(id=comment.id, content=comment.content) comment.editform = CommentForm(id=comment.id, content=comment.content)
return render_template('post/post.html', post=post, tags=post.tags, comments=post.comments, editform=PostForm(id=post.id), comment_form=CommentForm(post_id=post.id)) return render_template(
'post/post.html',
post=post,
tags=post.tags,
comments=post.comments,
editform=PostForm(
id=post.id,
source=post.source,
tags=" ".join([t.content for t in post.tags]),
rating=post.rating,
status=post.status
),
comment_form=CommentForm(post_id=post.id)
)
from yadc.bp import manage from yadc.bp import manage
@bp.route('/comment', methods=['POST']) @bp.route('/comment', methods=['POST'])

@ -92,7 +92,7 @@ class ChangePassForm(CSRFForm):
password = PasswordField('Password', validators=[DataRequired()], render_kw=dict(placeholder="New password")) password = PasswordField('Password', validators=[DataRequired()], render_kw=dict(placeholder="New password"))
password_again = PasswordField('Repeat password', validators=[DataRequired(), EqualTo('password')], render_kw=dict(placeholder="Repeat password")) password_again = PasswordField('Repeat password', validators=[DataRequired(), EqualTo('password')], render_kw=dict(placeholder="Repeat password"))
pass_submit = SubmitField('Change password') pass_submit = SubmitField('Change password')
class ChangeMailForm(CSRFForm): class ChangeMailForm(CSRFForm):
email = StringField('Email', validators=[DataRequired(), Email()], render_kw=dict(placeholder="Email")) email = StringField('Email', validators=[DataRequired(), Email()], render_kw=dict(placeholder="Email"))
email_again = StringField('Repeat email', validators=[DataRequired(), EqualTo('email')], render_kw=dict(placeholder="Repeat email")) email_again = StringField('Repeat email', validators=[DataRequired(), EqualTo('email')], render_kw=dict(placeholder="Repeat email"))
@ -104,7 +104,7 @@ class ChangeUserRatingForm(CSRFForm):
validators=[DataRequired()], validators=[DataRequired()],
render_kw=dict(onchange="submit()")) render_kw=dict(onchange="submit()"))
rating_submit = SubmitField('Change default rating') rating_submit = SubmitField('Change default rating')
class ChangeTagBlacklistForm(CSRFForm): class ChangeTagBlacklistForm(CSRFForm):
tags = StringField('Tags', render_kw=dict(placeholder='Tags', autocomplete='off')) tags = StringField('Tags', render_kw=dict(placeholder='Tags', autocomplete='off'))
tags_submit = SubmitField('Change blacklisted tags', validators=[DataRequired()]) tags_submit = SubmitField('Change blacklisted tags', validators=[DataRequired()])

@ -69,8 +69,8 @@
</article> </article>
{% endmacro %} {% endmacro %}
{% macro render_tag_input(input_field) %} {% macro render_tag_input(input_field, param_dict={}) %}
<div class="tag-input"> <div class="tag-input"{% for key,value in param_dict.items() %} data-{{key}}="{{value}}"{% endfor %}>
<div class="tag-suggester" data-inputname="{{ input_field.name }}"> <div class="tag-suggester" data-inputname="{{ input_field.name }}">
{#<input type="text" name="tags" autocomplete="off" value="{{ request.args.get('tags') }}">#} {#<input type="text" name="tags" autocomplete="off" value="{{ request.args.get('tags') }}">#}
{{ input_field() }} {{ input_field() }}

@ -39,7 +39,7 @@
{{ editform.source }} {{ editform.source }}
{{ render_tag_input(editform.tags) }} {{ render_tag_input(editform.tags, {'alt-selblock': 'section.sidepanel article.tags .tags-inpage'}) }}
{{ editform.edit() }} {{ editform.edit() }}
</form> </form>

Loading…
Cancel
Save