Skip to content
Permalink
Browse files

Lot of things I guess. Can't remember. But change password.

  • Loading branch information...
Depado committed Jun 20, 2015
1 parent 253fca5 commit 4a50717e46976ab1aa8b7f88522e0eea19e7873b
@@ -3,4 +3,4 @@
from .login import LoginForm
from .register import RegisterForm
from .post import NewPostForm, EditPostForm
from .settings import SettingForm
from .settings import SettingForm, ChangePasswordForm
@@ -1,13 +1,39 @@
# -*- coding: utf-8 -*-

from wtforms.fields import StringField, TextAreaField, BooleanField, IntegerField, SelectField
from wtforms.validators import DataRequired, Length, URL, Optional
from flask_login import current_user

from wtforms.fields import StringField, TextAreaField, BooleanField, IntegerField, SelectField, PasswordField
from wtforms.validators import DataRequired, Length, URL, Optional, EqualTo
from wtforms import ValidationError

from .base import CustomForm
from .utils import ImageUrl
from app.models.user import SYNTAX_HIGHLIGHTER_TUPLE



class ChangePasswordForm(CustomForm):
old_password = PasswordField(
'Old Password',
validators=[DataRequired(), ],
description={'placeholder': "Old Password"}
)
new_password = PasswordField(
'New Password',
validators=[DataRequired(), ],
description={'placeholder': "New Password"}
)
repeat_new_password = PasswordField(
'Repeat New Password',
validators=[DataRequired(), EqualTo('new_password', message='Passwords must match')],
description={'placeholder': "Repeat New Password"}
)

def validate_old_password(self, field):
if not current_user.check_password(self.old_password.data):
raise ValidationError("Wrong old password")


class SettingForm(CustomForm):
blog_title = StringField(
'Blog Title',
@@ -124,6 +124,9 @@ def get_page(self, page):
else:
return list(self.posts.order_by(desc(Post.pub_date)).all())[self.blog_paginate_by * page: self.blog_paginate_by * (page+1)]

def get_all_posts(self):
return list(self.posts.order_by(desc(Post.pub_date)).all())

def save(self):
db.session.add(self)
try:
@@ -56,6 +56,6 @@ def decorated_function(*args, **kwargs):
if user_slug:
blog_user = requested_blog_user(user_slug)
if not blog_user:
return render_template("blog_404.html", blog_name=utils.escape(user_slug))
return render_template("blog/blog_404.html", blog_name=utils.escape(user_slug))
return f(*args, **kwargs)
return decorated_function
@@ -16,12 +16,12 @@ def index(user_slug):
if blog_user.blog_paginate:
posts = blog_user.get_page(0)
current_page = 1
return render_template("blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
return render_template("blog/blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
syntax_highlighter_css=generate_syntax_highlighter_css(blog_user),
paginate=True, current_page=current_page, **generate_background_css(blog_user))
else:
posts = blog_user.posts.order_by(desc(Post.pub_date)).all()
return render_template("blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
return render_template("blog/blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
syntax_highlighter_css=generate_syntax_highlighter_css(blog_user),
**generate_background_css(blog_user))

@@ -37,7 +37,7 @@ def page(user_slug, page):
if posts is None:
return redirect(url_for("blog.index", user_slug=user_slug))
current_page = page
return render_template("blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
return render_template("blog/blog_index.html", owner=blog_user == current_user, posts=posts, blog_user=blog_user,
paginate=True, current_page=current_page,
syntax_highlighter_css=generate_syntax_highlighter_css(blog_user),
**generate_background_css(blog_user))
@@ -49,8 +49,18 @@ def get(user_slug, post_slug):
blog_user = requested_blog_user(user_slug)
post = Post.query.filter_by(title_slug=post_slug).first()
if post is not None:
return render_template("blog_page.html", post=post, owner=blog_user == current_user, blog_user=blog_user,
return render_template("blog/blog_page.html", post=post, owner=blog_user == current_user, blog_user=blog_user,
syntax_highlighter_css=generate_syntax_highlighter_css(blog_user),
**generate_background_css(blog_user))
else:
return render_template("blog_page_404.html")
return render_template("blog/blog_page_404.html")


@blueprint.route("/all")
@blog_exists
def all_posts(user_slug):
blog_user = requested_blog_user(user_slug)
posts = blog_user.get_all_posts()
return render_template("blog/blog_all_posts.html", posts=posts, owner=blog_user == current_user,
blog_user=blog_user, syntax_highlighter_css=generate_background_css(blog_user),
**generate_background_css(blog_user))
@@ -0,0 +1,5 @@
{% extends "blog/blog_base.html" %}

{% block content %}

{% endblock %}
@@ -3,7 +3,7 @@

{% endblock %}
{% block content %}
{% include "blog_menu.html" %}
{% include "blog/blog_menu.html" %}
{% block inner_content %}{% endblock %}
{% endblock %}

@@ -1,4 +1,4 @@
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
@@ -1,4 +1,4 @@
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
@@ -1,5 +1,5 @@
{% from "helpers.html" import render_blog_post, render_blog_profile, render_paginator %}
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
File renamed without changes.
@@ -1,5 +1,5 @@
{% from "helpers.html" import render_blog_post, render_blog_profile %}
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
File renamed without changes.
@@ -1,5 +1,5 @@
{% from "helpers.html" import render_field, render_content_field, md_help %}
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
@@ -1,5 +1,5 @@
{% from "helpers.html" import render_field, render_content_field, md_help %}
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block inner_content %}
<div class="container-fluid">
@@ -1,9 +1,10 @@
{% from "helpers.html" import render_field %}
{% extends "blog_base.html" %}
{% extends "blog/blog_base.html" %}

{% block extra_css_resources %}
<link href="//gitcdn.github.io/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet">
{% endblock %}

{% block extrajs %}
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js"></script>
{% endblock %}
@@ -51,6 +52,20 @@ <h2>Social</h2>
</div>
</div>
</form>
<form method="post" action="">
<div class="panel panel-info">
<div class="panel-heading">
Change Password
</div>
<div class="panel-body">
{{ change_pwd_form.hidden_tag() }}
{{ render_field(change_pwd_form.old_password) }}
{{ render_field(change_pwd_form.new_password) }}
{{ render_field(change_pwd_form.repeat_new_password) }}
<button class="btn btn-lg btn-primary btn-block" name="btn" type="submit" value="{{ change_pwd_form._prefix }}btn">Save</button>
</div>
</div>
</form>
<div class="panel panel-info">
<div class="panel-heading">
Other Informations
@@ -3,4 +3,4 @@
from .main import index, logout
from .explore import explore
from .post import new
# from .curl import curl_post
from .settings import settings
@@ -15,10 +15,10 @@ def explore_context():

@app.route("/explore")
def explore():
return render_template("blog_explore.html", **explore_context())
return render_template("blog/blog_explore.html", **explore_context())


@app.route("/all")
def explore_all():
posts = Post.query.join(User).filter(User.blog_public).order_by(desc(Post.pub_date)).all()
return render_template("blog_explore_all.html", posts=posts)
return render_template("blog/blog_explore_all.html", posts=posts)
@@ -3,11 +3,11 @@
from datetime import datetime

from flask import render_template, redirect, url_for, request, flash
from flask_login import current_user, login_user, logout_user, login_required
from flask_login import current_user, login_user, logout_user

from app import app
from app.forms import LoginForm, RegisterForm, SettingForm
from app.models import User, Post
from app.forms import LoginForm, RegisterForm
from app.models import User
from app.views.explore import explore_context


@@ -28,7 +28,7 @@ def index():
# return redirect(url_for("index", _scheme="https"))

if current_user.is_authenticated():
return render_template("blog_explore.html", **explore_context())
return render_template("blog/blog_explore.html", **explore_context())

start_div = "home-div"
login_form = LoginForm(request.form, prefix="login")
@@ -60,35 +60,3 @@ def index():
def logout():
logout_user()
return redirect(url_for("index"))

@app.route("/settings", methods=['GET', 'POST'])
@login_required
def settings():
form = SettingForm(obj=current_user)
if form.has_been_submitted(request):
if form.validate_on_submit():
current_user.blog_title = form.blog_title.data
current_user.blog_description = form.blog_description.data
current_user.blog_image = form.blog_image.data
current_user.blog_image_rounded = form.blog_image_rounded.data
current_user.blog_bg = form.blog_bg.data
current_user.blog_bg_public = form.blog_bg_public.data
current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
current_user.blog_bg_override = form.blog_bg_override.data
current_user.blog_bg_repeat = form.blog_bg_repeat.data
current_user.blog_paginate = form.blog_paginate.data
current_user.blog_paginate_by = form.blog_paginate_by.data
current_user.blog_public = form.blog_public.data
current_user.blog_truncate_posts = form.blog_truncate_posts.data
current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
current_user.linkedin_url = form.linkedin_url.data
current_user.gplus_url = form.gplus_url.data
current_user.github_url = form.github_url.data
current_user.twitter_url = form.twitter_url.data
saved = current_user.save()
if saved:
flash("Saved your settings...")
return redirect(url_for("blog.index", user_slug=current_user.blog_slug))
else:
flash("Something went wrong...")
return render_template("settings.html", form=form)
@@ -60,7 +60,7 @@ def edit(post_id):
return redirect(url_for('index'))
else:
# The post has not been found
return render_template("blog_page_404", post_id=post_id)
return render_template("blog/blog_page_404", post_id=post_id)

@app.route("/delete/<int:post_id>")
def delete(post_id):
@@ -77,7 +77,7 @@ def delete(post_id):
flash("You don't have the permission to do that.")
return redirect(url_for('blog.index', user_slug=post.user.blog_slug))
else:
return render_template("blog_page_404.html", post_id=post_id)
return render_template("blog/blog_page_404.html", post_id=post_id)


@app.route("/_parse", methods=['POST'])
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-

from flask import request, flash, redirect, url_for, render_template
from flask_login import login_required, current_user

from app import app
from app.forms import SettingForm, ChangePasswordForm

@app.route("/settings", methods=['GET', 'POST'])
@login_required
def settings():
form = SettingForm(obj=current_user)
change_pwd_form = ChangePasswordForm(prefix='pwd')

if form.has_been_submitted(request):
print("Not supposed to be here")
if form.validate_on_submit():
current_user.blog_title = form.blog_title.data
current_user.blog_description = form.blog_description.data
current_user.blog_image = form.blog_image.data
current_user.blog_image_rounded = form.blog_image_rounded.data
current_user.blog_bg = form.blog_bg.data
current_user.blog_bg_public = form.blog_bg_public.data
current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
current_user.blog_bg_override = form.blog_bg_override.data
current_user.blog_bg_repeat = form.blog_bg_repeat.data
current_user.blog_paginate = form.blog_paginate.data
current_user.blog_paginate_by = form.blog_paginate_by.data
current_user.blog_public = form.blog_public.data
current_user.blog_truncate_posts = form.blog_truncate_posts.data
current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
current_user.linkedin_url = form.linkedin_url.data
current_user.gplus_url = form.gplus_url.data
current_user.github_url = form.github_url.data
current_user.twitter_url = form.twitter_url.data
saved = current_user.save()
if saved:
flash("Saved your settings.")
return redirect(url_for("blog.index", user_slug=current_user.blog_slug))
else:
flash("Something went wrong...")

elif change_pwd_form.has_been_submitted(request):
if change_pwd_form.validate_on_submit():
current_user.set_password(change_pwd_form.new_password.data)
saved = current_user.save()
if saved:
flash("Changed your password.")
else:
flash("Something went wrong...")

return render_template("settings.html", form=form, change_pwd_form=change_pwd_form)

0 comments on commit 4a50717

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