def author(): author = Author.getone() if author is None: author = {}.fromkeys(Author.fields.values(), '') flashx.warning('Please compelte author\'s information') return render_template('author.html', active_tab='author', author=author)
def settings(): blog = Blog.getone() if blog is None: blog = {}.fromkeys(Blog.fields().values(), '') flashx.warning('You have no settings, please eidt and save') return render_template('settings.html', active_tab='settings', blog=blog)
def render_public(template, **data): models = Models(Blog, Author) query = models.select() results = query.execute() if results.count <= 0: flashx.warning('Not configure blog or author yet') return render_template('error.html') blog, author = results.one() return render_template(template, blog=blog, author=author, logged_in=logged_in(), **data)
def preview(): title = request.form["title"] title_pic = request.form["title_pic"] body = request.form["body"] if not title: flashx.warning("Title is empty!") post = dict( title=title, title_pic=title_pic, html=markdown.render(body), datetime=datetime.now(), id=None # !preview ) return render_public("post.html", post=post)
def create(): body = request.form["body"] title = request.form["title"] title_pic = request.form["title_pic"] published = bool(int(request.form["published"])) if not title: flashx.warning("Empty title") return redirect(url_for("write")) post = Post.create(title=title, title_pic=title_pic, body=body, datetime=datetime.now(), published=published) if published: flashx.success("Published successfully") return redirect(url_for("post", id=post.id)) else: flashx.success("Saved to drafts successfully") return redirect(url_for("edit", id=post.id)) # jump to edit url
def update_author(): name = request.form['name'] email = request.form['email'] url = request.form['url'] description = request.form['description'] if not name or not email: flashx.warning('Empty input') else: author = Author.getone() if author is None: # do a insert author = Author.create(name=name, email=email, url=url, description=description) flashx.success('Create author information successfully') else: # do a save author.name = name author.email = email author.url = url author.description = description author.save() flashx.success('Save author information successfully') return redirect(url_for('author'))
def update_password(): password_now = request.form['password_now'] password_new = request.form['password_new'] password_new_repeat = request.form['password_new_repeat'] if password_now and password_new and password_new_repeat: if password_new_repeat != password_new: flashx.warning('The two new passwords do not match') else: admin = Admin.getone() hashed_passwd_now = md5(password_now).hexdigest() if hashed_passwd_now != admin.passwd: flashx.warning('Incorrect password') else: admin.passwd = md5(password_new).hexdigest() admin.save() flashx.success('Save password successfully, please login again') return redirect(url_for('logout')) else: flashx.warning('Empty input!') return redirect(url_for('password'))