diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..24fcade489642f87d73ebcf485f171c1b9ab5cd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Personal virtualenv +.hodor diff --git a/hodor/__init__.py b/hodor/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e73a1ec25b07cd92e1c258ef0b8544f87ce2db38 --- /dev/null +++ b/hodor/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +__version__ = '0.1' +from flask import Flask +from flask_debugtoolbar import DebugToolbarExtension +app = Flask('project') +app.config['SECRET_KEY'] = 'random' +app.debug = True +toolbar = DebugToolbarExtension(app) +from project.controllers import * diff --git a/hodor/__init__.pyc b/hodor/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b3e858bb2e0baa73ac56f54c1b8df5e3b637a185 Binary files /dev/null and b/hodor/__init__.pyc differ diff --git a/hodor/controllers/__init__.py b/hodor/controllers/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..844f750f54360e5f8678aa187f03c6b7d558d13b --- /dev/null +++ b/hodor/controllers/__init__.py @@ -0,0 +1,4 @@ +import os +import glob +__all__ = [os.path.basename( + f)[:-3] for f in glob.glob(os.path.dirname(__file__) + "/*.py")] diff --git a/hodor/controllers/__init__.pyc b/hodor/controllers/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7711f137498825fd5ebcddfd733b1a840f979595 Binary files /dev/null and b/hodor/controllers/__init__.pyc differ diff --git a/hodor/controllers/printer.py b/hodor/controllers/printer.py new file mode 100644 index 0000000000000000000000000000000000000000..0da47df3feeb8bf446b226a83773387741dc08b1 --- /dev/null +++ b/hodor/controllers/printer.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from project import app +from flask import render_template, request +from flask_wtf import FlaskForm +from wtforms import StringField +from wtforms.validators import DataRequired + + +class CreateForm(FlaskForm): + text = StringField('name', validators=[DataRequired()]) + + +@app.route('/') +def start(): + return render_template('printer/index.html') + + +@app.route('/print', methods=['GET', 'POST']) +def printer(): + form = CreateForm(request.form) + if request.method == 'POST' and form.validate(): + from project.models.Printer import Printer + printer = Printer() + printer.show_string(form.text.data) + return render_template('printer/index.html') + return render_template('printer/print.html', form=form) diff --git a/hodor/controllers/printer.pyc b/hodor/controllers/printer.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3cab4ce1008dbc50b8b7f7acda97448592f482b7 Binary files /dev/null and b/hodor/controllers/printer.pyc differ diff --git a/hodor/models/Printer.py b/hodor/models/Printer.py new file mode 100644 index 0000000000000000000000000000000000000000..54ff974e8265b86ebd6b8f0cc04bbf29faec7988 --- /dev/null +++ b/hodor/models/Printer.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from flask import flash + + +class Printer(object): + + def show_string(self, text): + if text == '': + flash("You didn't enter any text to flash") + else: + flash(text + "!!!") diff --git a/hodor/models/Printer.pyc b/hodor/models/Printer.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d32f52d671695991007c380483dd1f059fad3196 Binary files /dev/null and b/hodor/models/Printer.pyc differ diff --git a/hodor/models/__init__.py b/hodor/models/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/hodor/models/__init__.pyc b/hodor/models/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a72112d105cd02ad89fe253f200a059151aec919 Binary files /dev/null and b/hodor/models/__init__.pyc differ diff --git a/hodor/static/css/style.css b/hodor/static/css/style.css new file mode 100644 index 0000000000000000000000000000000000000000..dcbbde0d5ebb604aeccc10df8bc2141259d8766c --- /dev/null +++ b/hodor/static/css/style.css @@ -0,0 +1,71 @@ +body { + font-family: sans-serif; + background: #eee; +} + +a,h1,h2 { + color: #377BA8; +} + +h1,h2 { + font-family: 'Georgia', serif; + margin: 0; +} + +h1 { + border-bottom: 2px solid #eee; +} + +h2 { + font-size: 1.2em; +} + +.page { + margin: 2em auto; + width: 35em; + border: 5px solid #ccc; + padding: 0.8em; + background: white; +} + +.entries { + list-style: none; + margin: 0; + padding: 0; +} + +.entries li { + margin: 0.8em 1.2em; +} + +.entries li h2 { + margin-left: -1em; +} + +.add-entry { + font-size: 0.9em; + border-bottom: 1px solid #ccc; +} + +.add-entry dl { + font-weight: bold; +} + +.metanav { + text-align: right; + font-size: 0.8em; + padding: 0.3em; + margin-bottom: 1em; + background: #fafafa; +} + +.flash { + background: #CEE5F5; + padding: 0.5em; + border: 1px solid #AACBE2; +} + +.error { + background: #F0D6D6; + padding: 0.5em; +} \ No newline at end of file diff --git a/hodor/templates/layout/layout.html b/hodor/templates/layout/layout.html new file mode 100644 index 0000000000000000000000000000000000000000..a026d6c7608c1dae7f1c6ef598826fc0bc79c62c --- /dev/null +++ b/hodor/templates/layout/layout.html @@ -0,0 +1,22 @@ +<!doctype html> + <head> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}"> + <title>Flask-MVC</title> + </head> + <body> + <a style="text-align:center" href="{{ url_for('start') }}">Home</a> + <a style="text-align:center" href="http://salimane.com">About</a> + <div class="page"> + <h1>Flask MVC Boilerplate</h1> + {% for message in get_flashed_messages() %} + <div class="flash">{{ message }}</div> + {% endfor %} + {% macro render_error(field) %} + {% if field.errors %} + {% for error in field.errors %}<span class='error'>{{ error }}</span>{% endfor %} + {% endif %} + {% endmacro %} + {% block body %}{% endblock %} + </div> + </body> +</html> diff --git a/hodor/templates/printer/index.html b/hodor/templates/printer/index.html new file mode 100644 index 0000000000000000000000000000000000000000..00e9c5e8162012901bda0d21bb8f00d4f814a85b --- /dev/null +++ b/hodor/templates/printer/index.html @@ -0,0 +1,8 @@ +{% extends "layout/layout.html" %} +{% block body %} + <ul> + <p> + <a href="{{ url_for('printer') }}">Click here to print!</a> + </p> + </ul> +{% endblock %} diff --git a/hodor/templates/printer/print.html b/hodor/templates/printer/print.html new file mode 100644 index 0000000000000000000000000000000000000000..6053f5488a5102a507d1bff1f9b0dba9bfe45629 --- /dev/null +++ b/hodor/templates/printer/print.html @@ -0,0 +1,10 @@ +{% extends "layout/layout.html" %} +{% block body %} + <form action="{{ url_for('printer') }}" method="post"> + {{ form.csrf_token }} + <dl> + <dd>{{ form.text.label }} {{ form.text(size=20) }} {{ render_error(form.text) }}</dd> + <dd><input type="submit" value="Flash"/></dd> + </dl> + </form> +{% endblock %}