1
1
Fork 0

Purged and flashed errors :D,

management endpoint bugfix,
taginput selected autofill fixed
dev
Jan Kužílek 5 years ago
parent 305a4cea30
commit 3b568fa8a1

@ -1,14 +1,14 @@
// https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
function getJsonFromUrl(url) {
if(!url) url = location.search;
var query = url.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
// // https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
// function getJsonFromUrl(url) {
// if(!url) url = location.search;
// var query = url.substr(1);
// var result = {};
// query.split("&").forEach(function(part) {
// var item = part.split("=");
// result[item[0]] = decodeURIComponent(item[1]);
// });
// return result;
// }
function create_selection_tag(tagname) { // CLEAR
let tag = document.createElement("a")
@ -67,7 +67,6 @@ taginputs.forEach(function (tinput) {
suggest_input.removeAttribute('required')
hidden_input.setAttribute('required', '')
}
suggest_input.removeAttribute('value') // Disable prefill by browser
let suggest_dropdown = suggestroot.querySelector('.suggest-dropdown')
@ -134,12 +133,19 @@ taginputs.forEach(function (tinput) {
}
// Generate selected by url query
let query = getJsonFromUrl()
if (query['tags']) {
query['tags'].split('+').forEach((tag) => {
add_selected(tag)
})
}
// let query = getJsonFromUrl()
// if (query['tags']) {
// query['tags'].split('+').forEach((tag) => {
// add_selected(tag)
// })
// }
let vals = suggest_input.value.split(' ')
console.log(vals)
vals.forEach(tag => {
if (tag == '') return
add_selected(tag)
});
suggest_input.removeAttribute('value') // Disable prefill by browser
function render_suggestions(data) { // 3 references
let drop = suggest_dropdown

@ -4,7 +4,7 @@ from flask import Blueprint, flash, redirect, render_template, request, url_for,
from yadc import db
from yadc.forms import LoginForm, RegisterForm, ResetPasswordForm
from yadc.models import User
from yadc.utils import nextpage
from yadc.utils import nextpage, flasherrors
bp = Blueprint('auth', __name__)
@ -27,6 +27,7 @@ def login():
return redirect(nextpage())
flasherrors(form)
return render_template('auth/login.html', form=form)
@bp.route('/logout')
@ -54,6 +55,7 @@ def reset_password():
flash('Password successfully reset. Check your email.')
return redirect(url_for('.login'))
flasherrors(form)
return render_template('auth/reset_password.html', form=form)
@ -77,4 +79,5 @@ def register():
flash('Your account has been successfully registered. You can now login.')
return redirect(url_for('.login'))
flasherrors(form)
return render_template('auth/register.html', form=form)

@ -5,6 +5,7 @@ from yadc.forms import UserForm, PostForm, TagForm, CommentForm
from yadc import db
from yadc.models import User, USER_STATUS, moderator_required, admin_required, Post, Tag, TAG_CATEGORY, Comment
from yadc.utils import flasherrors
bp = Blueprint('manage', __name__)
@ -91,8 +92,7 @@ def modify_user():
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.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
@ -101,6 +101,7 @@ def modify_user():
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
flasherrors(form)
return redirect(url_for('.manage_users'))
@ -140,6 +141,7 @@ def modify_post():
flash('Approved post {}'.format(str(post)))
redirect(url_for('post.post_show', id=post.id))
flasherrors(form)
return redirect(url_for('.manage_posts'))
# Example perfect create/edit/delete form endpoint
@ -171,6 +173,7 @@ def modify_tag():
db.session.commit()
flash('Changes to {} have been applied.'.format(str(el)))
flasherrors(form)
return redirect(url_for('.manage_tags'))
# return redirect(url_for('main.index'))

@ -10,7 +10,7 @@ from sqlalchemy.orm import aliased
from yadc import db
from yadc.forms import UploadForm, CommentForm, PostForm
from yadc.models import FILETYPE, RATING, POST_STATUS, Post, Tag, Comment, moderator_required
from yadc.utils import query_replace
from yadc.utils import query_replace, flasherrors
bp = Blueprint('post', __name__)
@ -94,6 +94,7 @@ def upload():
return redirect(url_for('.posts'))
flasherrors(form)
return render_template('post/upload.html', form=form)
@bp.route('/tags')

@ -5,6 +5,7 @@ from yadc.forms import ChangeUserInfoForm, ChangePassForm, ChangeMailForm, Chang
from yadc import db
from yadc.models import User, Post, Comment
from yadc.utils import flasherrors
bp = Blueprint('user', __name__)
@ -40,6 +41,7 @@ def change_info():
db.session.commit()
flash('Your biography was updated.')
flasherrors(form)
return redirect(url_for('.settings'))
@bp.route('/change_pass', methods=['POST'])
@ -56,6 +58,7 @@ def change_pass():
db.session.commit()
flash('Password changed successfully.')
flasherrors(form)
return redirect(url_for('.settings'))
@bp.route('/change_mail', methods=['POST'])
@ -68,6 +71,7 @@ def change_mail():
db.session.commit()
flash('Your email was updated.')
flasherrors(form)
return redirect(url_for('.settings'))
@bp.route('/change_rating', methods=['POST'])
@ -80,6 +84,7 @@ def change_rating():
db.session.commit()
flash('Your rating preference was updated.')
flasherrors(form)
return redirect(url_for('.settings'))
@bp.route('/change_tagblacklist', methods=['POST'])
@ -94,6 +99,7 @@ def change_tagblacklist():
db.session.commit()
flash('Your tag blacklist was updated.')
flasherrors(form)
return redirect(url_for('.settings'))
@bp.route('/delete_data', methods=['POST'])
@ -113,4 +119,5 @@ def delete_data():
return redirect(url_for('main.index'))
flasherrors(form)
return redirect(url_for('.settings'))

@ -55,17 +55,17 @@ document.getElementById("user-menu").addEventListener('click', (ev) => {
drop.classList.remove("_drop")
}
})
// https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
function getJsonFromUrl(url) {
if(!url) url = location.search;
var query = url.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
// // https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript
// function getJsonFromUrl(url) {
// if(!url) url = location.search;
// var query = url.substr(1);
// var result = {};
// query.split("&").forEach(function(part) {
// var item = part.split("=");
// result[item[0]] = decodeURIComponent(item[1]);
// });
// return result;
// }
function create_selection_tag(tagname) { // CLEAR
let tag = document.createElement("a")
@ -124,7 +124,6 @@ taginputs.forEach(function (tinput) {
suggest_input.removeAttribute('required')
hidden_input.setAttribute('required', '')
}
suggest_input.removeAttribute('value') // Disable prefill by browser
let suggest_dropdown = suggestroot.querySelector('.suggest-dropdown')
@ -191,12 +190,19 @@ taginputs.forEach(function (tinput) {
}
// Generate selected by url query
let query = getJsonFromUrl()
if (query['tags']) {
query['tags'].split('+').forEach((tag) => {
add_selected(tag)
})
}
// let query = getJsonFromUrl()
// if (query['tags']) {
// query['tags'].split('+').forEach((tag) => {
// add_selected(tag)
// })
// }
let vals = suggest_input.value.split(' ')
console.log(vals)
vals.forEach(tag => {
if (tag == '') return
add_selected(tag)
});
suggest_input.removeAttribute('value') // Disable prefill by browser
function render_suggestions(data) { // 3 references
let drop = suggest_dropdown

@ -1,31 +0,0 @@
{% macro errors(field) %}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
<!-- DEPRECATED + wrong function name, but whatever -->
{% macro management_gen_line(field, formfield) %}
<span class="show">{{ field }}</span>
<span class="edit">{{ formfield() }}</span>
{{ errors(formfield) }}
{% endmacro %}
<!-- COPY OF genfield IN management.html -->
{% macro genfield(formfield=None) %}
{% if not formfield %}
<td>
<span>{{ caller() }}</span>
</td>
{% else %}
<td>
<span class="notedit">{{ caller() }}</span>
<span class="edit">{{ formfield() }}</span>
{{ errors(formfield) }}
</td>
{% endif %}
{% endmacro %}

@ -1,5 +1,4 @@
{% extends 'layout/base.html' %}
{% from "_formhelpers.html" import errors %}
{% block content %}
<div class="pageform">
@ -8,17 +7,14 @@
{{ form.csrf_token }}
{{ form.username(placeholder="Username") }}
{{ errors(form.username) }}
{{ form.password(placeholder="Password") }}
{{ errors(form.password) }}
<ul>
<li>
{{ form.remember_me() }}{{ form.remember_me.label }}
</li>
</ul>
{{ errors(form.remember_me) }}
<div class="row stretch">
{{ form.submit() }}
<a href="{{ url_for('auth.reset_password') }}">Forgotten password?</a>

@ -1,5 +1,4 @@
{% extends 'layout/base.html' %}
{% from "_formhelpers.html" import errors %}
{% block content %}
<div class="pageform">
@ -8,16 +7,12 @@
{{ form.csrf_token }}
{{ form.username(placeholder="Username") }}
{{ errors(form.username) }}
{{ form.email(placeholder="Email address") }}
{{ errors(form.email) }}
{{ form.password(placeholder="Password") }}
{{ errors(form.password) }}
{{ form.password_again(placeholder="Repeat password") }}
{{ errors(form.password_again) }}
<div>
{{ form.submit() }}

@ -1,5 +1,4 @@
{% extends 'layout/base.html' %}
{% from "_formhelpers.html" import errors %}
{% block content %}
<div class="pageform">
@ -9,7 +8,6 @@
{{ form.csrf_token }}
{{ form.email(placeholder="Your email address") }}
{{ errors(form.email) }}
{{ form.submit() }}
</form>

@ -13,7 +13,7 @@
<tbody>
{% for element in elements %}
<tr class="editingable">
<form action="{{ url_for('manage.modify_tag') }}" method="post">
<form action="{% block form_endpoint %}{% endblock %}" method="post">
{{ element.editform.csrf_token }}
{{ element.editform.id() }}
@ -44,7 +44,6 @@
</table>
{% endblock %}
{% from "_formhelpers.html" import errors %}
{% macro genfield(formfield=None) %}
{% if not formfield %}
<td>
@ -54,7 +53,6 @@
<td>
<span class="notedit">{{ caller() }}</span>
<span class="edit">{{ formfield() }}</span>
{{ errors(formfield) }}
</td>
{% endif %}
{% endmacro %}

@ -9,6 +9,8 @@
</section>
{% endblock %}
{% block form_endpoint %}{{ url_for('manage.modify_post') }}{% endblock %}
{% block field_headings %}
<th>ID</th>
<th>MD5</th>

@ -9,6 +9,8 @@
</section>
{% endblock %}
{% block form_endpoint %}{{ url_for('manage.modify_tag') }}{% endblock %}
{% block field_headings %}
<th>Content</th>
<th>Category</th>

@ -9,9 +9,12 @@
</section>
{% endblock %}
{% block form_endpoint %}{{ url_for('manage.modify_user') }}{% endblock %}
{% block field_headings %}
<th>ID</th>
<th>Username</th>
<th>Email address</th>
<th>User status</th>
<th>Perm level</th>
<th>Last login</th>
@ -22,10 +25,15 @@
{{ element.id }}
{% endcall %}
{% call genfield(element.editform.username) %}
{#{% call genfield(element.editform.username) %}#}
{% call genfield() %}
{{ element.username }}
{% endcall %}
{% call genfield(element.editform.email) %}
{{ element.email }}
{% endcall %}
{% call genfield(element.editform.user_status) %}
{{ element.user_status.name.capitalize() }}
{% endcall %}

@ -39,10 +39,8 @@
{{ editform.id() }}
{{ editform.source }}
{{ errors(editform.source) }}
{{ render_tag_input(editform.tags) }}
{{ errors(editform.tags) }}
{{ editform.edit() }}
</form>
@ -111,7 +109,6 @@
{{ comment_form.post_id() }}
{{ comment_form.content() }}
{{ errors(comment_form.content) }}
{{ comment_form.create(value="Send") }}
</form>

@ -1,5 +1,4 @@
{% extends 'layout/base.html' %}
{% from "_formhelpers.html" import errors %}
{% from "_includes.html" import render_tag_input %}
{% block content %}
@ -11,14 +10,11 @@
{#{{ form.post_img.label }}#}
{{ form.post_img() }}
</div>
{{ errors(form.post_img) }}
{{ form.sauce() }}
{{ errors(form.sauce) }}
{{ render_tag_input(form.tags) }}
<!-- {{ form.tags(placeholder="Tags") }} -->
{{ errors(form.tags) }}
<div>
{{ form.rating.label }}
@ -30,7 +26,6 @@
{% endfor %}
</ul>
</div>
{{ errors(form.rating) }}
{{ form.submit() }}
</form>

@ -1,5 +1,4 @@
{% extends 'layout/settings.html' %}
{% from "_formhelpers.html" import errors %}
{% block main_content %}
<section class="manage-profile">
@ -9,7 +8,6 @@
{{ userinfo_form.csrf_token }}
{{ userinfo_form.bio(placeholder="Enter your description") }}
{{ errors(userinfo_form.bio) }}
{{ userinfo_form.userinfo_submit() }}
</form>
@ -20,13 +18,10 @@
{{ pass_form.csrf_token }}
{{ pass_form.password_current(placeholder="Current password") }}
{{ errors(pass_form.password_current) }}
{{ pass_form.password(placeholder="Password") }}
{{ errors(pass_form.password) }}
{{ pass_form.password_again(placeholder="Repeat password") }}
{{ errors(pass_form.password_again) }}
{{ pass_form.pass_submit() }}
</form>
@ -37,10 +32,8 @@
{{ mail_form.csrf_token }}
{{ mail_form.email() }}
{{ errors(mail_form.email) }}
{{ mail_form.email_again() }}
{{ errors(mail_form.email_again) }}
{{ mail_form.mail_submit() }}
</form>
@ -51,11 +44,13 @@
{{ rating_form.csrf_token }}
{{ rating_form.rating() }}
{{ errors(rating_form.rating) }}
<noscript>{{ rating_form.rating_submit() }}</noscript>
</form>
</div>
<div class="pageform">
<h3>Tag blacklist</h3>
</div>
<div class="pageform">
<h3>Delete user data</h3>
<form action="{{ url_for('user.delete_data') }}" method="post">
@ -63,11 +58,9 @@
<ul>
<li>
{{ delete_form.all_comments() }}{{ delete_form.all_comments.label }}
{{ errors(delete_form.all_comments) }}
</li>
<li>
{{ delete_form.all_posts() }}{{ delete_form.all_posts.label }}
{{ errors(delete_form.all_posts) }}
</li>
</ul>

@ -21,4 +21,12 @@ def nextpage():
nextpg = request.args.get('next')
if not nextpg or url_parse(nextpg).netloc != '':
nextpg = url_for('main.index')
return nextpg
return nextpg
from flask import flash
def flasherrors(form):
for key,errs in form.errors.items():
label = form.__getattribute__(key).label.text
for err in errs:
flash('{}: {}'.format(label,err), category='error')
Loading…
Cancel
Save