1
1
Fork 0

Completely rewritten basically all form endpoints,

some minor changes
dev
Jan Kužílek 5 years ago
parent cafe8130c2
commit 3ebe1c0b67

@ -50,10 +50,11 @@ def create_app():
# admin.add_view(ModelView(models.Tag, db.session, endpoint='admin_tag')) # admin.add_view(ModelView(models.Tag, db.session, endpoint='admin_tag'))
# admin.add_view(ModelView(models.Comment, db.session, endpoint='admin_comment')) # admin.add_view(ModelView(models.Comment, db.session, endpoint='admin_comment'))
from yadc.bp import main, post, auth, user, api from yadc.bp import main, post, auth, manage, user, api
app.register_blueprint(main.bp) app.register_blueprint(main.bp)
app.register_blueprint(post.bp, url_prefix='/post') app.register_blueprint(post.bp, url_prefix='/post')
app.register_blueprint(auth.bp, url_prefix='/auth') app.register_blueprint(auth.bp, url_prefix='/auth')
app.register_blueprint(manage.bp, url_prefix='/manage')
app.register_blueprint(user.bp, url_prefix='/user') app.register_blueprint(user.bp, url_prefix='/user')
app.register_blueprint(api.bp) app.register_blueprint(api.bp)

@ -0,0 +1,178 @@
from flask import (Blueprint, abort, current_app, flash, redirect,
render_template, request, send_from_directory, url_for)
from flask_login import login_required, current_user
from yadc.forms import UserForm, PostForm, TagForm, CommentForm
from yadc import db
from yadc.models import User, USER_STATUS, Post, Tag, TAG_CATEGORY, Comment
bp = Blueprint('manage', __name__)
@bp.route('/users', defaults={'page': 1})
@bp.route('/users/<int:page>')
@login_required
def manage_users(page):
users = User.query.order_by(User.id.desc()).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
for user in users.items:
user.editform = UserForm(
id=user.id,
username=user.username,
email=user.email,
op_level=user.op_level.name,
user_status=user.user_status.name)
return render_template('manage/users.html', users=users, createform=UserForm())
@bp.route('/posts', defaults={'page': 1})
@bp.route('/posts/<int:page>')
@login_required
def manage_posts(page):
posts = Post.query.order_by(Post.id.desc()).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
for post in posts.items:
post.editform = PostForm(
id=post.id,
rating=post.rating.name,
status=post.status.name,
source=post.source)
return render_template('manage/posts.html', posts=posts)
@bp.route('/tags', defaults={'page': 1})
@bp.route('/tags/<int:page>')
@login_required
def manage_tags(page):
tags = Tag.query.order_by(Tag.content).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
for tag in tags.items:
tag.editform = TagForm(
id=tag.id,
content=tag.content_deser,
category=tag.category.name)
return render_template('manage/tags.html', tags=tags, createform=TagForm())
@bp.route('/modify_user', methods=['POST'])
@login_required
def modify_user():
form = UserForm(request.form)
flash(str(request.form))
if form.validate():
if form.create.data:
el = User(username=form.username.data)
db.session.add(el)
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
db.session.commit()
flash('New {} has been created.'.format(str(el)))
else:
el = User.query.filter_by(id=form.id.data).first()
if form.delete.data:
db.session.delete(el)
db.session.commit()
flash('{} deleted.'.format(str(el)))
elif form.edit.data:
print(form.username)
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
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
return redirect(url_for('.manage_users'))
@bp.route('/modify_post', methods=['POST'])
@login_required
def modify_post():
form = PostForm(request.form)
flash(str(request.form))
if form.validate():
if form.create.data:
pass
else:
el = Post.query.filter_by(id=form.id.data).first()
if form.delete.data:
db.session.delete(el)
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
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
return redirect(url_for('.manage_posts'))
# Example perfect create/edit/delete form endpoint
@bp.route('/modify_tag', methods=['POST'])
@login_required
def modify_tag():
form = TagForm(request.form)
flash(str(request.form))
if form.validate():
if form.create.data:
el = Tag(content_deser=form.content.data)
db.session.add(el)
if form.category.data: el.category = form.category.data
db.session.commit()
flash('New {} has been created.'.format(str(el)))
else:
el = Tag.query.filter_by(id=form.id.data).first()
if form.delete.data:
db.session.delete(el)
db.session.commit()
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
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
return redirect(url_for('.manage_tags'))
# return redirect(url_for('main.index'))
# Creation/editing only through post page
@bp.route('/modify_comment', methods=['POST'])
@login_required
def modify_comment():
form = CommentForm(request.form)
flash(str(request.form))
if form.validate():
if form.create.data:
el = Comment(content=form.content.data, post_id=form.post_id.data, user=current_user)
db.session.add(el)
db.session.commit()
flash('Successfully submitted {}'.format(str(el)))
return redirect(url_for('.post_show', id=form.post_id.data))
else:
el = Comment.query.filter_by(id=form.id.data).first()
if form.delete.data:
db.session.delete(el)
db.session.commit()
flash('{} deleted.'.format(str(el)))
elif form.edit.data:
if form.content.data: el.content = form.content.data
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
return redirect(url_for('.post_show', id=el.post_id))
return redirect(url_for('main.posts'))

@ -9,7 +9,7 @@ from sqlalchemy import func
from sqlalchemy.orm import aliased from sqlalchemy.orm import aliased
from yadc import db from yadc import db
from yadc.forms import UploadForm, CommentForm, EditCommentForm from yadc.forms import UploadForm, CommentForm#, EditCommentForm
from yadc.models import FILETYPE, RATING, Post, Tag, Comment from yadc.models import FILETYPE, RATING, Post, Tag, Comment
from yadc.utils import query_replace from yadc.utils import query_replace
@ -38,17 +38,15 @@ def posts(page):
posts_query = Post.query posts_query = Post.query
if f_tags: if f_tags:
posts_query = posts_query.join(Post.tags).group_by(Post.id).filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags)) posts_query = posts_query.join(Post.tags).group_by(Post.id).filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags))
posts_query = posts_query.filter(Post.rating.in_(m_ratings)).order_by(Post.created) #.offset((page-1)*posts_on_page).limit(posts_on_page) 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'))
tags = tags_prepare(posts.items) tags = tags_prepare(posts.items)
flash(f_tags) # flash(f_tags)
flash(m_ratings) # flash(m_ratings)
# flash(posts.items)
# flash(tags)
return render_template('post/index.html', posts=posts.items, tags=tags, pagination=posts) return render_template('post/index.html', posts=posts, tags=tags)
@bp.route('/show/<int:id>') @bp.route('/show/<int:id>')
def post_show(id): def post_show(id):
@ -59,46 +57,16 @@ def post_show(id):
for tag,tag.count in tags_count: for tag,tag.count in tags_count:
tag.endpoint = query_replace({'tags': tag.content}, url_for('.posts')) tag.endpoint = query_replace({'tags': tag.content}, url_for('.posts'))
form = CommentForm(post_id=post.id)
for comment in post.comments: for comment in post.comments:
comment.editform = EditCommentForm(comment_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, comment_form=form) return render_template('post/post.html', post=post, tags=post.tags, comments=post.comments, comment_form=CommentForm(post_id=post.id))
@bp.route('comment', methods=['POST']) from yadc.bp import manage
@bp.route('/comment', methods=['POST'])
@login_required @login_required
def comment(): def comment():
form = CommentForm(request.form) return manage.modify_comment()
if request.method == 'POST' and form.validate():
comment = Comment(content=form.content.data, post_id=form.post_id.data, user=current_user)
db.session.add(comment)
db.session.commit()
flash('Successfully submitted {}'.format(str(comment)))
return redirect(url_for('.post_show', id=form.post_id.data))
return redirect(url_for('.posts'))
@bp.route('edit_comment', methods=['POST'])
@login_required
def comment_edit():
form = EditCommentForm(request.form)
flash(str(request.form))
if request.method == 'POST' and form.validate():
comment = Comment.query.filter_by(id=form.comment_id.data).first()
comment.content = form.content.data
db.session.commit()
flash('Successfully edited {}'.format(str(comment)))
return redirect(url_for('.post_show', id=comment.post_id))
return redirect(url_for('.posts'))
@bp.route('/upload', methods=['GET', 'POST']) @bp.route('/upload', methods=['GET', 'POST'])
@login_required @login_required

@ -1,10 +1,10 @@
from flask import (Blueprint, abort, current_app, flash, redirect, from flask import (Blueprint, abort, current_app, flash, redirect,
render_template, request, send_from_directory, url_for) render_template, request, send_from_directory, url_for)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from yadc.forms import ChangePassForm, EditUserForm, EditPostForm from yadc.forms import ChangePassForm
from yadc import db from yadc import db
from yadc.models import User, USER_STATUS, Post from yadc.models import User
bp = Blueprint('user', __name__) bp = Blueprint('user', __name__)
@ -35,90 +35,3 @@ def settings():
return redirect(url_for('.settings')) return redirect(url_for('.settings'))
return render_template('manage/profile.html', form=form) return render_template('manage/profile.html', form=form)
@bp.route('/manage_users', defaults={'page': 1})
@bp.route('/manage_users/<int:page>')
@login_required
def manage_users(page):
users = User.query.order_by(User.created.desc()).paginate(page, current_app.config.get('MANAGE_USERS_PER_PAGE'))
for user in users.items:
user.editform = EditUserForm(
user_id=user.id,
username=user.username,
email=user.email,
op_level=user.op_level.name,
user_status=user.user_status.name)
return render_template('manage/users.html', users=users.items, pagination=users)
@bp.route('/manage_posts', defaults={'page': 1})
@bp.route('/manage_posts/<int:page>')
@login_required
def manage_posts(page):
posts = Post.query.order_by(Post.created.desc()).paginate(page, current_app.config.get('MANAGE_POSTS_PER_PAGE'))
for post in posts.items:
post.editform = EditPostForm(
post_id=post.id,
rating=post.rating.name,
status=post.status.name,
source=post.source)
return render_template('manage/posts.html', posts=posts.items, pagination=posts)
@bp.route('user_modify', methods=['POST'])
@login_required
def modify_user():
form = EditUserForm(request.form)
flash(str(request.form))
if request.method == 'POST' and form.validate():
user = User.query.filter_by(id=form.user_id.data).first()
if form.delete.data:
# user.user_status = USER_STATUS.inactive
#db.session.delete(user)
#db.session.commit()
flash('User {} deleted.'.format(str(user)))
elif form.edit.data:
if form.username.data:
user.username = form.username.data
if form.email.data:
user.email = form.email.data
if form.user_status.data:
user.user_status = form.user_status.data
if form.op_level.data:
user.op_level = form.op_level.data
db.session.commit()
flash('Changes to {} has been applied.'.format(str(user)))
return redirect(url_for('.manage_users'))
return redirect(url_for('main.index'))
@bp.route('post_modify', methods=['POST'])
@login_required
def modify_post():
form = EditPostForm(request.form)
flash(str(request.form))
if request.method == 'POST' and form.validate():
post = Post.query.filter_by(id=form.post_id.data).first()
if form.delete.data:
# user.user_status = USER_STATUS.inactive
#db.session.delete(post)
#db.session.commit()
flash('User {} deleted.'.format(str(user)))
elif form.edit.data:
if form.rating.data:
post.rating = form.rating.data
if form.status.data:
post.status = form.status.data
if form.source.data:
post.source = form.source.data
db.session.commit()
flash('Changes to {} has been applied.')
return redirect(url_for('.manage_posts'))
return redirect(url_for('main.index'))

@ -10,5 +10,4 @@ MAX_CONTENT_LENGTH = 10*1024*1024
POST_LIST_THUMB_HEIGHT = 200 POST_LIST_THUMB_HEIGHT = 200
POSTS_PER_PAGE = 8 POSTS_PER_PAGE = 8
MANAGE_USERS_PER_PAGE = 8 MANAGE_PER_PAGE = 8
MANAGE_POSTS_PER_PAGE = 8

@ -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 from wtforms import StringField, PasswordField, BooleanField, SubmitField, FileField, MultipleFileField, ValidationError, RadioField, TextAreaField, HiddenField, SelectField
from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional from wtforms.validators import DataRequired, InputRequired, Email, EqualTo, AnyOf, optional, StopValidation
from werkzeug.utils import cached_property from werkzeug.utils import cached_property
@ -80,10 +80,6 @@ class UploadForm(CSRFForm):
if client_mimetype not in ['image/png','image/jpeg']: if client_mimetype not in ['image/png','image/jpeg']:
raise ValidationError('Please select an image file of PNG or JPEG format') raise ValidationError('Please select an image file of PNG or JPEG format')
class CommentForm(CSRFForm):
post_id = HiddenField(validators=[DataRequired()])
content = TextAreaField('Comment', validators=[DataRequired()], render_kw={'autocomplete':'off'})
submit = SubmitField('Send')
class ChangePassForm(CSRFForm): class ChangePassForm(CSRFForm):
password_current = PasswordField('Current password', validators=[DataRequired()]) password_current = PasswordField('Current password', validators=[DataRequired()])
@ -92,36 +88,53 @@ class ChangePassForm(CSRFForm):
submit = SubmitField('Change password') submit = SubmitField('Change password')
class EditUserForm(CSRFForm): from yadc.models import USER_STATUS, OP_LEVEL, RATING, POST_STATUS, TAG_CATEGORY
user_id = HiddenField(validators=[DataRequired()])
username = StringField('Username') class EditForm(CSRFForm):
id = HiddenField('ID')
create = SubmitField('Create')
edit = SubmitField('Modify')
delete = SubmitField('Delete')
def validate_id(form, field):
if (form.edit.data or form.delete.data) and not field.data:
raise ValidationError('ID must be defined to be able to modify.')
def validate_create_required(form, field):
if form.create.data and not field.data:
raise ValidationError('Please fill out this field.')
class UserForm(EditForm):
username = StringField('Username', validators=[validate_create_required])
email = StringField('E-mail', validators=[optional(), Email()]) email = StringField('E-mail', validators=[optional(), Email()])
user_status = SelectField('User status', user_status = SelectField('User status',
choices=[('active', 'Active'), ('inactive', 'Inactive'), ('banned', 'Banned')], choices=[(e.name, e.name.capitalize()) for e in USER_STATUS],
validators=[optional()]) validators=[optional()])
op_level = SelectField('Permission level', op_level = SelectField('Permission level',
choices=[('user', 'User'), ('creator', 'Creator'), ('moderator', 'Moderator'), ('admin', 'Admin')], choices=[(e.name, e.name.capitalize()) for e in OP_LEVEL],
validators=[optional()]) validators=[optional()])
edit = SubmitField('Modify') class PostForm(EditForm):
delete = SubmitField('Delete')
class EditPostForm(CSRFForm):
post_id = HiddenField(validators=[DataRequired()])
rating = SelectField('Rating', rating = SelectField('Rating',
choices=[('safe', 'Safe'), ('questionable', 'Questionable'), ('explicit', 'Explicit')], choices=[(e.name, e.name.capitalize()) for e in RATING],
validators=[optional()]) validators=[optional()])
status = SelectField('Status', status = SelectField('Status',
choices=[('pending', 'Pending'), ('active', 'Active'), ('deleted', 'Deleted')], choices=[(e.name, e.name.capitalize()) for e in POST_STATUS],
validators=[optional()]) validators=[optional()])
source = StringField('Source', render_kw={'autocomplete':'off'}) source = StringField('Source', render_kw={'autocomplete':'off'})
edit = SubmitField('Modify') class TagForm(EditForm):
delete = SubmitField('Delete') content = StringField('Content', validators=[validate_create_required], render_kw={'autocomplete':'off'})
category = SelectField('Category',
choices=[(e.name, e.name.capitalize()) for e in TAG_CATEGORY],
validators=[optional()])
# Creation/editing only through post page
class CommentForm(EditForm):
post_id = HiddenField(validators=[validate_create_required])
content = TextAreaField('Comment', render_kw={'autocomplete':'off'})
class EditCommentForm(CSRFForm): def validate_content(form, field):
comment_id = HiddenField(validators=[DataRequired()]) if (form.create.data or form.edit.data) and not field.data:
content = TextAreaField('Comment', validators=[DataRequired()]) raise ValidationError('Please fill out this field.')
submit = SubmitField('Edit')

@ -227,14 +227,16 @@ class Post(TimestampMixin, db.Model):
class Tag(TimestampMixin, db.Model): class Tag(TimestampMixin, db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(128), unique=True, nullable=False) content = db.Column(db.String(128), unique=True, nullable=False)
category = db.Column(db.Enum(TAG_CATEGORY), default=TAG_CATEGORY.general) category = db.Column(db.Enum(TAG_CATEGORY), default=TAG_CATEGORY.general, nullable=False)
#posts = db.relationship('Post', secondary=post_tags, back_populates='tags')
@property @property
def content_deser(self): def content_deser(self):
return self.content.replace('_',' ') return self.content.replace('_',' ')
@content_deser.setter
def content_deser(self, value):
self.content = value.replace(' ', '_')
def __repr__(self): def __repr__(self):
return '<Tag {}, {}>'.format(self.content, self.category.name) return '<Tag {}, {}>'.format(self.content, self.category.name)
@ -247,7 +249,7 @@ class Comment(TimestampMixin, db.Model):
delete_reason = db.Column(db.String(512)) delete_reason = db.Column(db.String(512))
post_id = db.Column(db.Integer, db.ForeignKey('post.id')) post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
post = db.relationship('Post', backref=db.backref('comments', lazy=True)) post = db.relationship('Post', backref=db.backref('comments', order_by='Comment.id', lazy=True))
user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
user = db.relationship('User', backref=db.backref('comments', lazy=True)) user = db.relationship('User', backref=db.backref('comments', lazy=True))

File diff suppressed because one or more lines are too long

@ -0,0 +1,17 @@
let comment_container = document.querySelector('section.comments .comment_container')
let comments = comment_container.querySelectorAll('.comment')
function triggerEdit(comment) {
let form = comment.querySelector('form.editingable')
if (!form.classList.contains('time-to-edit')) {
form.classList.add('time-to-edit')
} else {
form.classList.remove('time-to-edit')
}
}
comments.forEach((comment) => {
// comment.querySelector('p.comment_content').addEventListener('dblclick', (event) => triggerEdit(comment))
comment.querySelector('.comment_head .control_edit').addEventListener('click', (event) => triggerEdit(comment))
})

@ -482,7 +482,7 @@ header {
max-width: 500px; max-width: 500px;
article { article.comment {
overflow: hidden; overflow: hidden;
margin-bottom: 1em; margin-bottom: 1em;
} }
@ -501,7 +501,7 @@ header {
} }
} }
.head { .comment_head {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
@ -542,9 +542,9 @@ header {
th { th {
background-color: #606060; background-color: #606060;
} }
&:nth-child(even) { // &:nth-child(even) {
background-color: #303030; background-color: #303030;
} // }
th, td { th, td {
padding: 6px 10px; padding: 6px 10px;
@ -564,7 +564,7 @@ header {
display: none; display: none;
} }
} }
input[type=submit] { input[type=submit]:not([name=create]) {
display: none; display: none;
} }

@ -10,5 +10,10 @@
{% macro management_gen_line(field, formfield) %} {% macro management_gen_line(field, formfield) %}
<span class="show">{{ field }}</span> <span class="show">{{ field }}</span>
<span class="edit">{{ formfield() }}{{ errors(formfield) }}</span> <span class="edit">{{ formfield() }}</span>
{{ errors(formfield) }}
{% endmacro %}
{% macro management_row_gen(field_formfield) %}
{% endmacro %} {% endmacro %}

@ -1,5 +1,5 @@
<!-- https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/#flask_sqlalchemy.Pagination.iter_pages --> <!-- https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/#flask_sqlalchemy.Pagination.iter_pages -->
{% macro render_pagination(endpoint) %} {% macro render_pagination(endpoint, pagination) %}
<div class="pagin"> <div class="pagin">
{% if pagination.has_prev %} {% if pagination.has_prev %}
<a href="{{ utils.query_replace({}, url_for(endpoint, page=pagination.prev_num)) }}"><span class="fa fa-chevron-left"></span></a> <a href="{{ utils.query_replace({}, url_for(endpoint, page=pagination.prev_num)) }}"><span class="fa fa-chevron-left"></span></a>

@ -2,10 +2,10 @@
{% block sidebar %} {% block sidebar %}
<article class="tags tag_input"> <article class="tags tag_input">
<form action="{{ url_for('post.posts') }}" method="get"> <form action="{% block search_endpoint %}{{ url_for('post.posts') }}{% endblock %}" method="get">
<h3>Search</h3> <h3>Search</h3>
<div class="tag_suggester" data-inputname="tags"> <div class="tag_suggester" data-inputname="tags">
<input type="text" name="tags" autocomplete="off" value="{{ request.args.get('tags') }}"> <input type="text" name="tags" autocomplete="off" value="{{ request.args.get('tags', '') }}">
<div class="tag_container tag_suggest_dropdown"></div> <div class="tag_container tag_suggest_dropdown"></div>
</div> </div>
<input type="submit" value="Search"> <input type="submit" value="Search">

@ -12,22 +12,20 @@
<th>Rating</th> <th>Rating</th>
<th>Status</th> <th>Status</th>
<th>Source</th> <th>Source</th>
<th>Original Filename</th>
<th>Manage</th> <th>Manage</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for post in posts %} {% for post in posts.items %}
<form action="{{ url_for('user.modify_post') }}" method="post"> <form action="{{ url_for('manage.modify_post') }}" method="post">
{{ post.editform.csrf_token }} {{ post.editform.csrf_token }}
{{ post.editform.post_id() }} {{ post.editform.id() }}
<tr> <tr>
<td>{{ post.id }}</td> <td>{{ post.id }}</td>
<td><pre style="margin: 0;">{{ post.md5[:7] }}</pre></td> <td><pre style="margin: 0;">{{ post.md5[:7] }}</pre></td>
<td>{{ management_gen_line(post.rating.name.capitalize(), post.editform.rating) }}</td> <td>{{ management_gen_line(post.rating.name.capitalize(), post.editform.rating) }}</td>
<td>{{ management_gen_line(post.status.name.capitalize(), post.editform.status) }}</td> <td>{{ management_gen_line(post.status.name.capitalize(), post.editform.status) }}</td>
<td>{{ management_gen_line(post.source, post.editform.source) }}</td> <td>{{ management_gen_line(post.source, post.editform.source) }}</td>
<td>{{ post.origin_filename }}</td>
<td> <td>
<label class="show to-edit"><span class="fa fa-edit"></span></label> <label class="show to-edit"><span class="fa fa-edit"></span></label>
<label class="edit to-close"><span class="fa fa-close"></span></label> <label class="edit to-close"><span class="fa fa-close"></span></label>
@ -39,6 +37,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{{ render_pagination('user.manage_posts') }} {{ render_pagination('manage.manage_posts', posts) }}
</section> </section>
{% endblock %} {% endblock %}

@ -0,0 +1,47 @@
{% extends 'layout/settings.html' %}
{% from '_includes.html' import render_pagination %}
{% from "_formhelpers.html" import management_gen_line, errors %}
{% block main_content %}
<section class="management_table manage_posts">
<table>
<thead>
<tr>
<!-- <th>ID</th> -->
<th>Content</th>
<th>Category</th>
<th>Manage</th>
</tr>
</thead>
<tbody>
{% for tag in tags.items %}
<form action="{{ url_for('manage.modify_tag') }}" method="post">
{{ tag.editform.csrf_token }}
{{ tag.editform.id() }}
<tr>
<!-- <td>{{ tag.id }}</td> -->
<td>{{ tag.content_deser }}</td>
<td>{{ management_gen_line(tag.category.name.capitalize(), tag.editform.category) }}</td>
<td>
<label class="show to-edit"><span class="fa fa-edit"></span></label>
<label class="edit to-close"><span class="fa fa-close"></span></label>
<label class="edit"><span class="fa fa-check"></span>{{ tag.editform.edit() }}</label>
<label><span class="fa fa-trash-o"></span>{{ tag.editform.delete() }}</label>
</td>
</tr>
</form>
{% endfor %}
<form action="{{ url_for('manage.modify_tag') }}" method="post">
{{ createform.csrf_token }}
<tr>
<!-- <td></td> -->
<td>{{ createform.content() }}</td>
<td>{{ createform.category() }}</td>
<td>{{ createform.create() }}</td>
</tr>
</form>
</tbody>
</table>
{{ render_pagination('manage.manage_tags', tags) }}
</section>
{% endblock %}

@ -16,16 +16,16 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for user in users %} {% for user in users.items %}
<form action="{{ url_for('user.modify_user') }}" method="post"> <form action="{{ url_for('manage.modify_user') }}" method="post">
{{ user.editform.csrf_token }} {{ user.editform.csrf_token }}
{{ user.editform.user_id() }} {{ user.editform.id() }}
<tr> <tr>
<td>{{ user.id }}</td> <td>{{ user.id }}</td>
<td>{{ management_gen_line(user.username, user.editform.username) }}</td> <td>{{ management_gen_line(user.username, user.editform.username) }}</td>
<td>{{ management_gen_line(user.user_status.name.capitalize(), user.editform.user_status) }}</td> <td>{{ management_gen_line(user.user_status.name.capitalize(), user.editform.user_status) }}</td>
<td>{{ management_gen_line(user.op_level.name.capitalize(), user.editform.op_level) }}</td> <td>{{ management_gen_line(user.op_level.name.capitalize(), user.editform.op_level) }}</td>
<td>{{ user.last_login.strftime('%I:%M %p %d %b, %Y') }}</td> <td>{{ user.last_login.strftime('%I:%M %p %d %b, %Y') if user.last_login else 'Not yet logged in' }}</td>
<td> <td>
<label class="show to-edit"><span class="fa fa-edit"></span></label> <label class="show to-edit"><span class="fa fa-edit"></span></label>
<label class="edit to-close"><span class="fa fa-close"></span></label> <label class="edit to-close"><span class="fa fa-close"></span></label>
@ -35,8 +35,20 @@
</tr> </tr>
</form> </form>
{% endfor %} {% endfor %}
{#<!-- <form action="{{ url_for('manage.modify_user') }}" method="post">
{{ createform.csrf_token }}
{{ createform.id() }}
<tr>
<td></td>
<td>{{ createform.username() }}</td>
<td>{{ createform.user_status() }}</td>
<td>{{ createform.op_level() }}</td>
<td></td>
<td>{{ createform.create() }}</td>
</tr>
</form> -->#}
</tbody> </tbody>
</table> </table>
{{ render_pagination('user.manage_users') }} {{ render_pagination('manage.manage_users', users) }}
</section> </section>
{% endblock %} {% endblock %}

@ -1,10 +1,12 @@
{% extends 'layout/base_sidebar_tags.html' %} {% extends 'layout/base_sidebar_tags.html' %}
{% from '_includes.html' import render_pagination with context %} {% from '_includes.html' import render_pagination with context %}
{% block search_endpoint %}{% endblock %}
{% block main_content %} {% block main_content %}
<section class="post_list"> <section class="post_list">
<div class="posts"> <div class="posts">
{% for post in posts %} {% for post in posts.items %}
<figure style="{{ post.flex }}"> <figure style="{{ post.flex }}">
<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.image_url, endpoint='thumb') }}" srcset="{{ post.url(path=post.image_url, endpoint='thumb') }} 512w, {{ post.url(path=post.image_url, endpoint='sample') }} 800w" alt=""> <!--sizes="(min-width: 513px) 1000w" --> <img src="{{ post.url(path=post.image_url, endpoint='thumb') }}" srcset="{{ post.url(path=post.image_url, endpoint='thumb') }} 512w, {{ post.url(path=post.image_url, endpoint='sample') }} 800w" alt=""> <!--sizes="(min-width: 513px) 1000w" -->
@ -23,6 +25,6 @@
</div> </div>
</figure> --> </figure> -->
</div> </div>
{{ render_pagination('post.posts') }} {{ render_pagination('post.posts', posts) }}
</section> </section>
{% endblock %} {% endblock %}

@ -52,23 +52,25 @@
<h3>Comments</h3> <h3>Comments</h3>
<div class="comment_container"> <div class="comment_container">
{% for comment in comments %} {% for comment in comments %}
<article> <article class="comment">
<div class="head"> <div class="comment_head">
<h4>{{ comment.user.username }}</h4> <h4>{{ comment.user.username }}</h4>
{% if comment.can_edit %} {% if comment.can_edit %}
<span class="controls">edit</span> <span class="controls">
<span class="control_edit">edit</span>
</span>
{% endif %} {% endif %}
</div> </div>
{% if not comment.deleted %} {% if not comment.deleted %}
<form class="editingable" action="{{ url_for('post.comment_edit') }}" method="post"> <form class="comment_editform editingable" action="{{ url_for('post.comment') }}" method="post">
{{ comment.editform.csrf_token }} {{ comment.editform.csrf_token }}
{{ comment.editform.comment_id() }} {{ comment.editform.id() }}
<p class="notedit">{{ comment.content }}</p> <p class="comment_content notedit">{{ comment.content }}</p>
{{ comment.editform.content(class="edit") }} {{ comment.editform.content(class="edit") }}
{{ comment.editform.submit(class="edit") }} {{ comment.editform.edit(class="edit") }}
</form> </form>
{% else %} {% else %}
@ -82,7 +84,7 @@
<p>No comments so far.</p> <p>No comments so far.</p>
{% endif %} {% endif %}
</div> </div>
<script src="{{ url_for('static', filename="comment.js") }}"></script>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<div class="form"> <div class="form">
@ -94,7 +96,7 @@
{{ comment_form.content() }} {{ comment_form.content() }}
{{ errors(comment_form.content) }} {{ errors(comment_form.content) }}
</div> </div>
<div>{{ comment_form.submit() }}</div> <div>{{ comment_form.create() }}</div>
</form> </form>
</div> </div>
{% else %} {% else %}

Loading…
Cancel
Save