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:
# if form.username.data: el.username = form.username.data
if form.email.data: el.email = form.email.data
if 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.email.raw_data and form.email.data: el.email = form.email.data
if form.user_status.raw_data and form.user_status.data: el.user_status = form.user_status.data
if form.op_level.raw_data and form.op_level.data: el.op_level = form.op_level.data
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
@ -124,9 +124,14 @@ def modify_post():
db.session.commit()
flash('{} deleted.'.format(str(el)))
elif form.edit.data:
if form.rating.data: el.rating = form.rating.data
if form.status.data: el.status = form.status.data
if form.source.data: el.source = form.source.data
if form.rating.raw_data and form.rating.data: el.rating = form.rating.data
if form.status.raw_data and form.status.data: el.status = form.status.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()
flash('Changes to {} have been applied.'.format(str(el)))
@ -168,7 +173,7 @@ def modify_tag():
flash('{} deleted.'.format(str(el)))
elif form.edit.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()
flash('Changes to {} have been applied.'.format(str(el)))
@ -201,7 +206,7 @@ def modify_comment():
db.session.commit()
flash('{} deleted.'.format(str(el)))
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()
flash('Changes to {} have been applied.'.format(str(el)))

@ -31,7 +31,8 @@ def posts(page):
# PARSING ARGUMENTS
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
# filter user's blacklist
@ -53,6 +54,9 @@ def posts(page):
@bp.route('/show/<int:id>')
def post_show(id):
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()
for tag,tag.count in tags_count:
@ -61,7 +65,20 @@ def post_show(id):
for comment in post.comments:
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
@bp.route('/comment', methods=['POST'])

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

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

Loading…
Cancel
Save