#!/usr/bin/env python

from flask import Flask, render_template, flash, request
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField

import menu_gen
import recipe as drink_recipe

# app config
app = Flask(__name__)
app.config.from_object(__name__)
with open('local_secret') as fp:
    app.config['SECRET_KEY'] = fp.read().strip()


class MixMindServer():
    def __init__(self):
        base_recipes = menu_gen.load_recipe_json(['recipes.json'])
        self.recipes = {name:drink_recipe.DrinkRecipe(name, recipe) for name, recipe in base_recipes.iteritems()}

mms = MixMindServer()


class ReusableForm(Form):
    name = TextField('Name:', validators=[validators.required()])

    def reset(self):
        blankData = MultiDict([ ('csrf', self.reset_csrf() ) ])
        self.process(blankData)


@app.route("/", methods=['GET', 'POST'])
def hello():
    form = ReusableForm(request.form)

    print form.errors
    if request.method == 'POST':
        name = request.form['name']
        print name

        if form.validate():
            # Save the comment here.
            flash('Hello ' + name)
        else:
            flash('All the form fields are required. ')

    return render_template('hello.html', form=form)


@app.route('/json/<recipe_name>')
def recipe_json(recipe_name):
    try:
        return str(mms.recipes[recipe_name])
    except KeyError:
        return "{} not found".format(recipe_name)




@@ -706,16 +706,226 @@
 ired()%5D)
+%0A    email = TextField('Email:', validators=%5Bvalidators.required(), validators.Length(min=6, max=35)%5D)%0A    password = TextField('Password:', validators=%5Bvalidators.required(), validators.Length(min=3, max=35)%5D)
 %0A%0A    de
@@ -1201,150 +1201,321 @@
 name
- = request.form%5B'name'%5D%0A        print name%0A%0A        if form.validate():%0A            # Save the comment here.%0A            flash('Hello ' + name
+=request.form%5B'name'%5D%0A        password=request.form%5B'password'%5D%0A        email=request.form%5B'email'%5D%0A        print name, %22 %22, email, %22 %22, password%0A%0A        if form.validate():%0A            # Save the comment here.%0A            flash('Thanks for registration ' + name)%0A            drink = str(mms.recipes%5Brecipe_name%5D
 )%0A  
@@ -1545,16 +1545,23 @@
  flash('
+Error: 
 All the 
@@ -1640,16 +1640,29 @@
 orm=form
+, drink=drink
 )%0A%0A%0A@app

Update hello with some extra fields