From db98454950a41dd53399a1f564f456f5afbbee83 Mon Sep 17 00:00:00 2001
From: "Sachin S. Kamath" <sskamath96@gmail.com>
Date: Sat, 30 Sep 2017 14:37:33 +0530
Subject: [PATCH] Refactor boilerplate template

Signed-off-by: Sachin S. Kamath <sskamath96@gmail.com>
---
 .gitignore                         |   2 +
 hodor/__init__.py                  |   9 ++++
 hodor/__init__.pyc                 | Bin 0 -> 489 bytes
 hodor/controllers/__init__.py      |   4 ++
 hodor/controllers/__init__.pyc     | Bin 0 -> 349 bytes
 hodor/controllers/printer.py       |  26 +++++++++++
 hodor/controllers/printer.pyc      | Bin 0 -> 1515 bytes
 hodor/models/Printer.py            |  11 +++++
 hodor/models/Printer.pyc           | Bin 0 -> 687 bytes
 hodor/models/__init__.py           |   0
 hodor/models/__init__.pyc          | Bin 0 -> 147 bytes
 hodor/static/css/style.css         |  71 +++++++++++++++++++++++++++++
 hodor/templates/layout/layout.html |  22 +++++++++
 hodor/templates/printer/index.html |   8 ++++
 hodor/templates/printer/print.html |  10 ++++
 15 files changed, 163 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 hodor/__init__.py
 create mode 100644 hodor/__init__.pyc
 create mode 100644 hodor/controllers/__init__.py
 create mode 100644 hodor/controllers/__init__.pyc
 create mode 100644 hodor/controllers/printer.py
 create mode 100644 hodor/controllers/printer.pyc
 create mode 100644 hodor/models/Printer.py
 create mode 100644 hodor/models/Printer.pyc
 create mode 100644 hodor/models/__init__.py
 create mode 100644 hodor/models/__init__.pyc
 create mode 100644 hodor/static/css/style.css
 create mode 100644 hodor/templates/layout/layout.html
 create mode 100644 hodor/templates/printer/index.html
 create mode 100644 hodor/templates/printer/print.html

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..24fcade
--- /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 0000000..e73a1ec
--- /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
GIT binary patch
literal 489
zcmZSn%*!Pib3QVe0ScHI7#JKF7#NC^7#J8*7#N}$7*ZG+QkWQW7#VVz7^0XM7(sky
zh8$*wTo#5X76!&tCWaIihGs^FC{~6PR)$nohAcLQ6gCE%RCW+2o`WHk1;hZU-~^k-
z&XB{!5R$^d5UjxovI}IXfu3RJ|NsC0YcMh}FqE(|Ffh2~Bo=2wxS|XU3@)ijrRgF0
z`8i36MXnVksd>ej`FSPm3=9kfMfq8&$t5Lh3=9lKiFqmcxg}f-3=F}p&Oxpr@!qbH
z5JNx)Yx!w#gUkmJ@$qG;MIb}s<H7c&f$R$cg+qxD0|Nt?8=nHQwFF{o5XgiQkYf`I
z3c$7{=jWwmrkAiVFffD^m8OD?f#?9a3#zR|7~w{}<ovvnqWqkk)S_YykW~nx*pz{R
zK|douH&wqlJ25x0BtswSv10v<{FMA6{p9?VRG654e0*kJW=VX!UO{CE2Ll6xO>TZl
dX-=vg6DUCW7#JAX7zG#w7<m|Z895nw7y-2BZCn5V

literal 0
HcmV?d00001

diff --git a/hodor/controllers/__init__.py b/hodor/controllers/__init__.py
new file mode 100644
index 0000000..844f750
--- /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
GIT binary patch
literal 349
zcmZSn%*!Pib3QVe0SZ_c7#JKF7#ND<7#J8*7#LC*8FCmHqTp;shA2jcbOwf0Musd#
zhExWIEGC95W`<N2hGs^F6eb4oW<~~=SQ&;WR+uCkLn<p+l9@pvj)|erf+30>WNfeo
z$ga%)|NsB@D`sV2V9?jnE2zx;`~Uxc4Gsndh7u+Q28R6N5|FC&octs(qad*)ql6vg
zw9KNs#N5;pkjnV@w9K5;`1le=1_p*SuuxKBaVl6Iq&7Z2F()TJUIXMs1X1h=vNIz;
zH&wqlJ25x0BtyTTC_gJTxujS>BR?g-NIyA0B^4&7pPZjpQk0*QlUh`)A0MBYmst`Y
fuUAkBw#_CtKczG$)edBTF&hH|0}mq)BQqla(h5(c

literal 0
HcmV?d00001

diff --git a/hodor/controllers/printer.py b/hodor/controllers/printer.py
new file mode 100644
index 0000000..0da47df
--- /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
GIT binary patch
literal 1515
zcmZSn%*!Pib3QVe0SZ_d7#JKF7#NDzFfcHrFfgPrGUPBY<T5fuF)}cM_)H8rObofq
z3{lJsxhxD(ED%v<h8$LgTsDR%HVB`EA%~qImxCdS1Hxxz$l+wj<zk59Vqi>RV@PFV
zNMmG3VP|MzU}$Dw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ff --git a/hodor/models/Printer.py b/hodor/models/Printer.py
new file mode 100644
index 0000000..54ff974
--- /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
GIT binary patch
literal 687
zcmZSn%*!Pib3QVe0ScHI7#JKF7#NDR7#J8*7#LC*8FCmHav2$-7#SE-m>5!-7}6LS
zQkWT97#Nxv7$T#X8B$mnf;Ctf7#K4D|NsAAgOP!Op#;QD%SkNGC}C${U<fG6%qvMP
zf?EPo;smlpkb!|Al>uaS3IoW*C?<xWV6X|vObiSRAPjPlGf1sA0|P@1BgjG7ObkVm
z3?&Q<DNGE_j0}u<d>{@;j+sFmB#^?u5Ujz%z`)>F0`gX|5(5K6WPYhaN@hx)dWk|R
z$T13ud6fz!sTCy(CHV?qrxt^(QdCp~+aCndr~z_73CN)0)SNUh1EfO(EC(Wrtr-{?
z^fU5vQ}v6p6LS+wGV}|I^0QKtON#X~@>BAQ^po>bQek5Hx%nxnImP<W;Lt0mEa3+E
zEF-@>zPO|)GcO$!SjB80lNos!d6_goE-K+*U|@)k&r8frjgK$k0&{ZnQ%ZAE<Ku%s
z;f!z&m_@0Zf<UnYGPfAydp0INa7e;qG#eZ;B_K!UCxLtlRu8rrK~U-ju%B%pzO(~5
J1MC(7W&joZl?wm>

literal 0
HcmV?d00001

diff --git a/hodor/models/__init__.py b/hodor/models/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/hodor/models/__init__.pyc b/hodor/models/__init__.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..a72112d105cd02ad89fe253f200a059151aec919
GIT binary patch
literal 147
zcmZSn%*!Pib3QVe0SXuy7#JKF7#NCK7#J8*7#M;zKq7t`AZawB*oJ|DK|douH&wql
zJ25x0BtyTTC_gJTxujS>BR?g-NIyA0B^4&7pPQeOnp3PFAD@|*SrQ+wS5R5P!N9;^
RlbfGXnv-e=vZfeh3jp!HAs_$%

literal 0
HcmV?d00001

diff --git a/hodor/static/css/style.css b/hodor/static/css/style.css
new file mode 100644
index 0000000..dcbbde0
--- /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 0000000..a026d6c
--- /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 0000000..00e9c5e
--- /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 0000000..6053f54
--- /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 %}
-- 
GitLab