diff --git a/yadc/assets/js/taginput.js b/yadc/assets/js/taginput.js index c45961b..9cd10bf 100644 --- a/yadc/assets/js/taginput.js +++ b/yadc/assets/js/taginput.js @@ -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 diff --git a/yadc/bp/auth.py b/yadc/bp/auth.py index c8e8639..df9ab24 100644 --- a/yadc/bp/auth.py +++ b/yadc/bp/auth.py @@ -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) diff --git a/yadc/bp/manage.py b/yadc/bp/manage.py index 1a89ac5..7854d96 100644 --- a/yadc/bp/manage.py +++ b/yadc/bp/manage.py @@ -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')) diff --git a/yadc/bp/post.py b/yadc/bp/post.py index 1fabad1..60c901d 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -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') diff --git a/yadc/bp/user.py b/yadc/bp/user.py index 4bc20a9..1f4ab57 100644 --- a/yadc/bp/user.py +++ b/yadc/bp/user.py @@ -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')) \ No newline at end of file diff --git a/yadc/static/all.js b/yadc/static/all.js index 2383d15..eccb6fb 100644 --- a/yadc/static/all.js +++ b/yadc/static/all.js @@ -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 diff --git a/yadc/templates/_formhelpers.html b/yadc/templates/_formhelpers.html deleted file mode 100644 index 0267cdc..0000000 --- a/yadc/templates/_formhelpers.html +++ /dev/null @@ -1,31 +0,0 @@ -{% macro errors(field) %} -{% if field.errors %} -