1
1
Fork 0

Tag management validation,

posts - differentiate and hide pending on index,
UI fixes + tag rendering in "places",
post - show rating,
minor cleanups
master
Jan Kužílek 5 years ago
parent ef1484e915
commit 527c11d75e

@ -49,6 +49,11 @@
margin-bottom: 10px; margin-bottom: 10px;
} }
h3 {
margin: 0;
margin-bottom: .5em;
}
article.tags, article.post-edit { article.tags, article.post-edit {
@include media($bp-tablet) { @include media($bp-tablet) {
.tag-container /*:not(.suggest-dropdown)*/ { .tag-container /*:not(.suggest-dropdown)*/ {
@ -141,6 +146,9 @@
position: relative; position: relative;
margin: $figure-margin; margin: $figure-margin;
&[data-status="pending"] {
border: 4px solid #0044ff;
}
img { img {
display: block; display: block;

@ -51,6 +51,8 @@ def posts(page):
posts_query = posts_query.filter(~Post.id.in_(subquery)) posts_query = posts_query.filter(~Post.id.in_(subquery))
if f_tags: if f_tags:
posts_query = posts_query.filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags)) posts_query = posts_query.filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags))
if current_user.is_anonymous or not current_user.is_moderator:
posts_query = posts_query.filter_by(status=POST_STATUS.active)
posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created.desc()) posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created.desc())
posts = posts_query.paginate(page, current_app.config.get('POSTS_PER_PAGE')) posts = posts_query.paginate(page, current_app.config.get('POSTS_PER_PAGE'))
@ -58,6 +60,7 @@ def posts(page):
return render_template( return render_template(
'post/index.html', 'post/index.html',
posts=posts, posts=posts,
# posts=[p for p in posts if p.status is POST_STATUS.active] if current_user.is_anonymous or not current_user.is_moderator else posts,
tags=tags, tags=tags,
sel_tags=[tag for tag in tags if tag.content in f_tags] or Tag.query.filter(Tag.content.in_(f_tags)) sel_tags=[tag for tag in tags if tag.content in f_tags] or Tag.query.filter(Tag.content.in_(f_tags))
) )

@ -35,7 +35,7 @@ def settings():
pass_form=ChangePassForm(), pass_form=ChangePassForm(),
mail_form=ChangeMailForm(), mail_form=ChangeMailForm(),
rating_form=ChangeUserRatingForm(rating=current_user.rating.name), rating_form=ChangeUserRatingForm(rating=current_user.rating.name),
tags_form=ChangeTagBlacklistForm(tags=' '.join(t.content for t in current_user.tag_blacklist)), tags_form=ChangeTagBlacklistForm(tags=' '.join(t.content for t in current_user.tag_blacklist)), tags_form_tags=current_user.tag_blacklist,
delete_form=DeleteUserDataForm() delete_form=DeleteUserDataForm()
) )

@ -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):

File diff suppressed because one or more lines are too long

@ -61,7 +61,7 @@
</article> </article>
{% endmacro %} {% endmacro %}
{% macro render_tag_input(input_field, param_dict={}) %} {% macro render_tag_input(input_field, sel_tags=[], param_dict={}) %}
<div class="tag-input"{% for key,value in param_dict.items() %} data-{{key}}="{{value}}"{% endfor %}> <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') }}">#}
@ -69,6 +69,18 @@
<div class="tag-container suggest-dropdown"></div> <div class="tag-container suggest-dropdown"></div>
</div> </div>
<div class="tag-container tags-selected"></div> <div class="tag-container tags-selected">
{% for tag in sel_tags %}
<a class="tagselected" data-tagname="{{ tag.content }}" data-tagcat="{{ tag.category.name }}">
<span class="tag-icon">
<span class="fa fa-tag"></span>
</span>
<span class="content">{{ tag.content_deser }}</span>
<span class="tag-right">
<span class="fa fa-close close"></span>
</span>
</a>
{% endfor %}
</div>
</div> </div>
{% endmacro %} {% endmacro %}

@ -6,24 +6,17 @@
{% block main_content %} {% block main_content %}
<section class="post-list"> <section class="post-list">
<div class="posts"> <div class="posts">
{% if posts.items %}
{% for post in posts.items %} {% for post in posts.items %}
<figure style="{{ post.flex }}"> <figure style="{{ post.flex }}" data-status="{{ post.status.name }}">
<a href="{{ url_for('post.post_show', id=post.id) }}"> <a href="{{ url_for('post.post_show', id=post.id) }}">
<img src="{{ post.url(path=post.file_uri, endpoint='thumb_smol') }}" srcset="{{ post.url(path=post.file_uri, endpoint='thumb_smol') }} 512w, {{ post.url(path=post.file_uri, endpoint='thumb_big') }} 800w" alt=""> <!--sizes="(min-width: 513px) 1000w" --> <img src="{{ post.url(path=post.file_uri, endpoint='thumb_smol') }}" srcset="{{ post.url(path=post.file_uri, endpoint='thumb_smol') }} 512w, {{ post.url(path=post.file_uri, endpoint='thumb_big') }} 800w" alt="">
</a> </a>
</figure> </figure>
{% endfor %} {% endfor %}
{% else %}
<!-- <figure style="flex: 307.87 1 307.87px;"> <h4 style="margin-left: 2em;">Ooops. No content matching your filters.</h4>
<a href="#"> {% endif %}
<img src="/static/ryuzu/916993.png" alt="">
</a>
<div class="thumb-info">
<span>RyuZU²</span>
<span>1920x1080</span>
<span>1.5M</span>
</div>
</figure> -->
</div> </div>
{{ render_pagination('post.posts', posts) }} {{ render_pagination('post.posts', posts) }}
</section> </section>

@ -3,8 +3,6 @@
{% block sidebar %} {% block sidebar %}
<article class="post-desc"> <article class="post-desc">
<!-- <h4>Description</h4> -->
<!-- <img src="/static/profile.jpg" alt=""> -->
<div class="id">Id: {{ post.id }}</div> <div class="id">Id: {{ post.id }}</div>
<div class="author">Author: {{ post.author.username or "Deleted Account" }}</div> <div class="author">Author: {{ post.author.username or "Deleted Account" }}</div>
@ -14,7 +12,11 @@
<div class="status">Status: {{ post.status.name.capitalize() }}</div> <div class="status">Status: {{ post.status.name.capitalize() }}</div>
{% endif %} {% endif %}
<div class="rating">Rating: {{ post.rating.name.capitalize() }}</div>
<div class="time">Posted: {{ post.natural_created() }}</div> <div class="time">Posted: {{ post.natural_created() }}</div>
{#{% if post.created != post.updated %}
<div class="time">Last edited: {{ post.updated.date() }}</div>
{% endif %}#}
<div class="source">Source: <a href="{{ post.source }}">{{ post.source }}</a></div> <div class="source">Source: <a href="{{ post.source }}">{{ post.source }}</a></div>
<div class="size">File size: {{ post.filesize_human }}</div> <div class="size">File size: {{ post.filesize_human }}</div>
<div class="resolution">Image res: {{ post.image_resolution }}</div> <div class="resolution">Image res: {{ post.image_resolution }}</div>
@ -75,46 +77,6 @@
<section class="comments"> <section class="comments">
<h3>Comments</h3> <h3>Comments</h3>
<div class="comment-container"> <div class="comment-container">
{#<article class="comment editingable">
<form action="{{ url_for('post.comment') }}" method="post">
{{ comment.editform.csrf_token }}
{{ comment.editform.id() }}
<div class="comment-head">
<h4>{{ comment.user.username or "Deleted account" }}</h4>
<span class="controls">
{% if current_user.is_moderator %}
{% if not comment.deleted %}
<a class="control-moderate"><label>ban{{ comment.editform.ban(style="display: none;") }}</label></a>
{% else %}
<a class="control-moderate"><label>unban{{ comment.editform.unban(style="display: none;") }}</label></a>
{% endif %}
{% endif %}
{% if comment.is_author %}
<noscript class="jsoff-hide"></noscript>
<a class="notedit control-edit"><label>edit</label></a>
<a class="edit control-edit"><label>cancel</label></a>
{% endif %}
</span>
</div>
<div class="comment-editform baseform">
{% if not comment.deleted or comment.is_author or current_user.is_moderator %}
<p class="comment-content notedit">{{ comment.content }}</p>
{% endif %}
{% if comment.deleted %}
<p class="deleted">[Comment banned]</p>
{% endif %}
{% if comment.is_author %}
<noscript class="jsoff-show"></noscript>
{{ comment.editform.content(class="edit") }}
{{ comment.editform.edit(class="edit") }}
{{ comment.editform.delete(class="edit") }}
{% endif %}
</div>
</form>
</article>#}
{% for comment in comments %} {% for comment in comments %}
{{ render_comment(comment, comment.editform) }} {{ render_comment(comment, comment.editform) }}
{% endfor %} {% endfor %}

@ -7,14 +7,12 @@
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
{{ form.csrf_token }} {{ form.csrf_token }}
<div class=""> <div class="">
{#{{ form.post_img.label }}#}
{{ form.post_img() }} {{ form.post_img() }}
</div> </div>
{{ form.sauce() }} {{ form.sauce() }}
{{ render_tag_input(form.tags) }} {{ render_tag_input(form.tags) }}
<!-- {{ form.tags(placeholder="Tags") }} -->
<div> <div>
{{ form.rating.label }} {{ form.rating.label }}

@ -17,8 +17,8 @@
<div class="statistics"> <div class="statistics">
<h3>Statistics</h3> <h3>Statistics</h3>
<div class="posts">Uploaded posts: {{ post_count }}</div> <div class="posts">Uploaded posts: {{ post_count }}</div>
{% if user.is_moderator %}<div class="approves">Approved posts: {{ approved_count }}</div>{% endif %}
<div class="comments">Posted comments: {{ comment_count }}</div> <div class="comments">Posted comments: {{ comment_count }}</div>
{% if user.is_moderator %}<div class="approves">Approved comments: {{ approved_count }}</div>{% endif %}
</div> </div>
{% if user.tag_blacklist %} {% if user.tag_blacklist %}
@ -33,10 +33,8 @@
</span> </span>
<span class="content">{{ tag.content_deser }}</span> <span class="content">{{ tag.content_deser }}</span>
<span class="tag-right"> <span class="tag-right">
<span class="fa fa-plus plus"></span>
{#<span class="fa fa-close close"></span>#} {#<span class="fa fa-close close"></span>#}
</span> </span>
{#<span class="post_ids">{{ tag.post_ids }}</span>#}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>

@ -54,7 +54,7 @@
<form action="{{ url_for('user.change_tagblacklist') }}" method="post"> <form action="{{ url_for('user.change_tagblacklist') }}" method="post">
{{ tags_form.csrf_token }} {{ tags_form.csrf_token }}
{{ render_tag_input(tags_form.tags) }} {{ render_tag_input(tags_form.tags, tags_form_tags) }}
{{ tags_form.tags_submit() }} {{ tags_form.tags_submit() }}
</form> </form>

Loading…
Cancel
Save