<filename>kraken/public/views.py
# -*- coding: utf-8 -*-
'''Public section, including homepage and signup.'''
from flask import (Blueprint, request, render_template, flash, url_for,
                    redirect, session)
from flask.ext.login import login_user, login_required, logout_user

from kraken.extensions import login_manager
from kraken.user.models import User
from kraken.public.forms import LoginForm
from kraken.user.forms import RegisterForm
from kraken.grade.models import Grade
from kraken.utils import flash_errors
from kraken.database import db

from kraken.helpers.Skynet import Skynet

blueprint = Blueprint('public', __name__, static_folder="../static")

@login_manager.user_loader
def load_user(id):
    return User.get_by_id(int(id))


@blueprint.route("/", methods=["GET", "POST"])
def home():
    skynet = Skynet()
    messages = []
    data = skynet.get_my_events()
    if data and 'events' in data:
        for event in data['events']:
            if event and 'message' in event:
                print("MESSAGE :: %s " % event['message'])
                messages.append(event['message'])
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.members")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    grades = Grade.get_recent(100, "created_at DESC");
    return render_template("public/home.html", form=form, grades = grades, messages=messages)

@blueprint.route('/logout/')
@login_required
def logout():
    logout_user()
    flash('You are logged out.', 'info')
    return redirect(url_for('public.home'))

@blueprint.route("/register/", methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                        email=form.email.data,
                        password=form.password.data,
                        active=True)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)

@blueprint.route("/about/")
def about():
    form = LoginForm(request.form)
    return render_template("public/about.html", form=form)

<filename>kraken/public/views.py
# -*- coding: utf-8 -*-
'''Public section, including homepage and signup.'''
from flask import (Blueprint, request, render_template, flash, url_for,
                    redirect, session)
from flask.ext.login import login_user, login_required, logout_user

from kraken.extensions import login_manager
from kraken.user.models import User
from kraken.public.forms import LoginForm
from kraken.user.forms import RegisterForm
from kraken.grade.models import Grade
from kraken.utils import flash_errors
from kraken.database import db

from kraken.helpers.Skynet import Skynet

blueprint = Blueprint('public', __name__, static_folder="../static")

@login_manager.user_loader
def load_user(id):
    return User.get_by_id(int(id))


@blueprint.route("/", methods=["GET", "POST"])
def home():
    skynet = Skynet()
    messages = []
    data = skynet.get_my_events()
    if data and 'events' in data:
        for event in data['events']:
            if event and 'message' in event:
                print("MESSAGE :: %s " % event['message'])
                messages.append(event['message'])
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.members")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    grades = Grade.get_recent(100, "created_at DESC");
    return render_template("public/home.html", form=form, grades = grades, messages=messages)

@blueprint.route('/logout/')
@login_required
def logout():
    logout_user()
    flash('You are logged out.', 'info')
    return redirect(url_for('public.home'))

@blueprint.route("/register/", methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                        email=form.email.data,
                        password=form.password.data,
                        active=True)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)

@blueprint.route("/about/")
def about():
    form = LoginForm(request.form)
    return render_template("public/about.html", form=form)

# -*- coding: utf-8 -*- Public section, including homepage and signup. # Handle logging in