Skip to content
Permalink
Browse files

improve confusing editor UI

  • Loading branch information...
JeffVandrewJr committed Jan 9, 2019
1 parent ba27fa0 commit 359a03fbba2de9124824524f54f646b5c13a676f
Showing with 54 additions and 20 deletions.
  1. +22 −8 app/main/routes.py
  2. +2 −2 app/tasks.py
  3. +6 −0 app/templates/blogging/editor.html
  4. +7 −4 flask_blogging_patron/forms.py
  5. +17 −6 flask_blogging_patron/views.py
@@ -1,12 +1,13 @@
from app import blog_engine, db
from app.main import bp
from app.models import BTCPayClientStore, Square, PriceLevel
from flask import redirect, url_for, flash, render_template, request
from datetime import datetime
from flask import redirect, url_for, flash, render_template, request,\
current_app
from flask_blogging_patron import PostProcessor
from flask_blogging_patron.views import page_by_id_fetched,\
page_by_id_processed
from flask_login import current_user, login_required
import traceback


@bp.route('/')
@@ -19,16 +20,29 @@ def index():
tag='public'
)
temp_post = posts[0]
post = blog_engine.storage.get_post_by_id(temp_post['post_id'])
except Exception as e:
traceback.print_tb(e.__traceback__)
flash('This site has no homepage yet. \
Please create one.', 'warning')
if current_user.is_authenticated and current_user.role == 'admin':
return redirect(url_for('blogging.editor'))
if hasattr(current_user, 'id'):
current_app.logger.info(
f'''
Automatically generated non-existent homepage due to
the following: {e}
'''
)
blog_engine.storage.save_post(
'Welcome to LibrePatron!',
text='Your homepage goes here.',
tags=['public'],
draft=False,
user_id=current_user.id,
post_date=datetime.today(),
last_modified_date=datetime.today(),
post_id=None,
)
return redirect(url_for('main.index'))
else:
return redirect(url_for('auth.register'))
config = blog_engine.config
post = blog_engine.storage.get_post_by_id(temp_post['post_id'])
meta = {}
meta['is_user_blogger'] = False
if current_user.is_authenticated:
@@ -1,4 +1,4 @@
from app import scheduler
from app import scheduler, db
from app.email import send_reminder_emails, send_failed_emails
from app.models import User, Square, PriceLevel
from datetime import datetime, timedelta, date
@@ -99,7 +99,7 @@ def renewals_square():
else:
base = user.expiration
user.expiration = base + timedelta(days=30)
scheduler.app.db.session.commit()
db.session.commit()
send_failed_emails(
scheduler.app,
failed_list=declined_list,
@@ -9,7 +9,11 @@

<fieldset>
<!-- Form Name -->
{% if form.tags.type != "RadioField" %}
<legend>Edit Homepage</legend>
{% else %}
<legend>Update Editor</legend>
{% endif %}
<!-- Text input-->
<div class="form-group">
<label>
@@ -34,13 +38,15 @@
</div>
<!-- Text input-->
<div>
{% if form.tags.type == "RadioField" %}
{% for subfield in form.tags %}
<tr>
<td>{{ subfield }}</td>
<td>{{ subfield.label }}</td>
<br>
</tr>
{% endfor %}
{% endif %}
</div>
<!-- draft input-->
<!--div class="form-group">
@@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, SubmitField, BooleanField,\
RadioField
RadioField, HiddenField
from wtforms.validators import DataRequired


@@ -10,10 +10,13 @@ class BlogEditor(FlaskForm):
tags = RadioField(
'Optional Parameters',
choices=[
('normal', 'Post this as a subscriber update and email to all subscribers.'),
('noemail', 'Post this as a subscriber update, but do not email it.'),
('public', 'Post this to the public homepage rather than updates.'),
('NORMAL', 'Post this as a subscriber update and email to all subscribers.'),
('NOEMAIL', 'Post this as a subscriber update, but do not email it.'),
]
)
draft = BooleanField("draft", default=False)
submit = SubmitField("submit")


class HomePageEditor(BlogEditor):
tags = HiddenField(default='PUBLIC')
@@ -8,7 +8,7 @@
from flask_login import login_required, current_user
from flask import Blueprint, current_app, render_template, request, redirect, \
url_for, flash, make_response
from flask_blogging_patron.forms import BlogEditor
from flask_blogging_patron.forms import BlogEditor, HomePageEditor
import math
from werkzeug.contrib.atom import AtomFeed
import datetime
@@ -228,7 +228,10 @@ def editor(post_id):
config = blogging_engine.config
storage = blogging_engine.storage
if request.method == 'POST':
form = BlogEditor(request.form)
if request.form['tags'] == 'PUBLIC':
form = HomePageEditor(request.form)
else:
form = BlogEditor(request.form)
if form.validate():
post = storage.get_post_by_id(post_id)
if (post is not None) and \
@@ -250,7 +253,10 @@ def editor(post_id):

flash("Update posted successfully!", "info")
slug = post_processor.create_slug(form.title.data)
return redirect(url_for("blogging.page_by_id", post_id=pid,
if isinstance(form, HomePageEditor):
return redirect(url_for('main.index'))
else:
return redirect(url_for("blogging.page_by_id", post_id=pid,
slug=slug))
else:
flash("There were errors in update submission", "warning")
@@ -261,9 +267,14 @@ def editor(post_id):
post = storage.get_post_by_id(post_id)
if (post is not None) and \
(PostProcessor.is_author(post, current_user)):
tags = ", ".join(post["tags"])
form = BlogEditor(title=post["title"],
text=post["text"], tags=tags)
if 'PUBLIC' in post["tags"]:
tags = "PUBLIC"
form = HomePageEditor(title=post["title"],
text=post["text"], tags=tags)
else:
tags = ", ".join(post["tags"])
form = BlogEditor(title=post["title"],
text=post["text"], tags=tags)
editor_get_fetched.send(blogging_engine.app,
engine=blogging_engine,
post_id=post_id,

0 comments on commit 359a03f

Please sign in to comment.
You can’t perform that action at this time.