# -*- coding: utf-8 -*-
"""Public section, including homepage and signup."""
from flask import Blueprint, flash, redirect, render_template, request, url_for
from flask_login import login_required, login_user, logout_user

from myflaskapp.extensions import login_manager
from myflaskapp.public.forms import LoginForm, ToDoListForm
from myflaskapp.user.forms import RegisterForm
from myflaskapp.user.models import User
from myflaskapp.utils import flash_errors

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


@login_manager.user_loader
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))


@blueprint.route('/', methods=['GET', 'POST'])
def home():
    """Home page."""
    login_form = LoginForm(request.form, prefix='login')
    todo_form = ToDoListForm(request.form, prefix='todo')
    # Handle logging in
    if request.method == 'POST':
        if login_form.validate_on_submit():
            login_user(login_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)
    return render_template('public/home.html', form=login_form)



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


@blueprint.route('/register/', methods=['GET', 'POST'])
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        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():
    """About page."""
    form = LoginForm(request.form)
    return render_template('public/about.html', form=form)


@blueprint.route('/to-do/', methods=['GET', 'POST'])
def to_do():
    """To-Do page."""
    todo_form = ToDoListForm(request.form, prefix='todo')
    login_form = LoginForm(request.form, prefix='login')
    return render_template('todo.html', form=todo_form)

@@ -149,17 +149,26 @@
  url_for
+, session
 %0A
-
 from fla
@@ -794,66 +794,8 @@
 n')%0A
-    todo_form = ToDoListForm(request.form, prefix='todo')%0A
     
@@ -1134,32 +1134,38 @@
    flash_errors(
+login_
 form)%0A    return
@@ -1220,17 +1220,16 @@
 form)%0A%0A%0A
-%0A
 @bluepri
@@ -2176,24 +2176,31 @@
 Do page.%22%22%22%0A
+    #%0A%0A
     todo_for
@@ -2249,63 +2249,797 @@
 o')%0A
+%0A
     
-login_form = LoginForm(request.form, prefix='login'
+searchword = request.args.get('key', '')%0A    print('searchword',searchword)%0A    if searchword == 'clear':%0A        try:%0A            session%5B'list_items'%5D = %5B%5D%0A            return render_template('todo.html', form=todo_form)%0A        except:%0A            pass%0A%0A    if 'list_items' not in session:%0A        print(%22We have no list items%22)%0A        session%5B'list_items'%5D = %5B%5D%0A    else:%0A        pass%0A%0A    if todo_form.validate_on_submit():%0A        print(%22On entry have list items%22, session%5B'list_items'%5D)%0A        print(%22Form data%22, str(todo_form.item.data))%0A        session%5B'list_items'%5D.append(str(todo_form.item.data))%0A        session.modified = True%0A        print(%22After append have list items%22, session%5B'list_items'%5D)%0A        print(%22*%22 * 5)%0A%0A%0A%0A%0A    #print(%22list_items%22, session%5B'list_items'%5D
 )%0A  
@@ -3070,30 +3070,74 @@
 ('todo.html', form=todo_form
+,%0A                           session=session
 )%0A

Add session, do first attempt at session storing list data