From 99544a809a6eeca54aabf7a24dd8029a6a43625a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lombra=C3=B1a=20Gonz=C3=A1lez?= Date: Tue, 22 May 2012 08:55:38 +0200 Subject: [PATCH] New version of the applcation. Renamed to minimal. This commit changes the name of the application to minimal, as well as it uses a Blueprint for serving the static files. This last change solves the problem of dealing with the static files via Apache Alias directives. --- README.md | 42 +++++++++++++++--- contrib/apache2/minimal-site | 14 ++++++ contrib/minimal.wsgi | 9 ++++ contrib/minimal.wsgi.template | 10 +++++ {web => minimal}/__init__.py | 0 {web => minimal}/app.py | 21 ++++----- {web => minimal}/settings_local.py.tmpl | 0 .../bootstrap/css/bootstrap-responsive.css | 0 .../css/bootstrap-responsive.min.css | 0 .../static/bootstrap/css/bootstrap.css | 0 .../static/bootstrap/css/bootstrap.min.css | 0 .../img/glyphicons-halflings-white.png | Bin .../bootstrap/img/glyphicons-halflings.png | Bin .../static/bootstrap/js/bootstrap.js | 0 .../static/bootstrap/js/bootstrap.min.js | 0 minimal/static/css/style.css | 3 ++ {web => minimal}/static/js/jquery.min.js | 0 .../templates/helpers/_carousel.html | 0 .../templates/helpers/_carousel.js | 0 .../templates/helpers/_googleanalytics.html | 0 .../templates/helpers/_herounit.html | 0 .../templates/index.html.template | 0 .../templates/layout/_footer.html | 1 + .../templates/layout/_topbar.html | 0 {web => minimal}/templates/layout/base.html | 19 ++++---- minimal/views/__init__.py | 0 minimal/views/assets.py | 3 ++ minimal/views/static/prueba.css | 2 + test/base.py | 4 +- test/tests.py | 6 ++- 30 files changed, 102 insertions(+), 32 deletions(-) create mode 100644 contrib/apache2/minimal-site create mode 100644 contrib/minimal.wsgi create mode 100644 contrib/minimal.wsgi.template rename {web => minimal}/__init__.py (100%) rename {web => minimal}/app.py (73%) rename {web => minimal}/settings_local.py.tmpl (100%) rename {web => minimal}/static/bootstrap/css/bootstrap-responsive.css (100%) rename {web => minimal}/static/bootstrap/css/bootstrap-responsive.min.css (100%) rename {web => minimal}/static/bootstrap/css/bootstrap.css (100%) rename {web => minimal}/static/bootstrap/css/bootstrap.min.css (100%) rename {web => minimal}/static/bootstrap/img/glyphicons-halflings-white.png (100%) rename {web => minimal}/static/bootstrap/img/glyphicons-halflings.png (100%) rename {web => minimal}/static/bootstrap/js/bootstrap.js (100%) rename {web => minimal}/static/bootstrap/js/bootstrap.min.js (100%) create mode 100644 minimal/static/css/style.css rename {web => minimal}/static/js/jquery.min.js (100%) rename {web => minimal}/templates/helpers/_carousel.html (100%) rename {web => minimal}/templates/helpers/_carousel.js (100%) rename {web => minimal}/templates/helpers/_googleanalytics.html (100%) rename {web => minimal}/templates/helpers/_herounit.html (100%) rename {web => minimal}/templates/index.html.template (100%) rename {web => minimal}/templates/layout/_footer.html (60%) rename {web => minimal}/templates/layout/_topbar.html (100%) rename {web => minimal}/templates/layout/base.html (57%) create mode 100644 minimal/views/__init__.py create mode 100644 minimal/views/assets.py create mode 100644 minimal/views/static/prueba.css diff --git a/README.md b/README.md index df38e5d..39d1a5e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,38 @@ -Simple Flask web application to create web page prototypes using Twitter -Bootstrap as the CSS framework. +Minimal is a small web application that allows you to create web pages +really fast and easily with a beautiful interface thanks to [Bootstrap](http://twitter.github.com/bootstrap/.) This application saves you time creating a prototype, as you will not have to -write every header, footer, etc. Everything is configured using global -variables and different partials: _navbar.html, _footer.html, etc. +write every header, footer, etc for every HTML page. Everything is configured using global +variables and different partials: _navbar.html, _footer.html, etc. take +a look at the templates folder -Take a look at the templates (it uses Jinja2), and copy and paste the -index.html to create new pages. Then, all you have to do is add more routes in -web.py. +For example, by default Minimal serves an index page that can be overriden just +copying and pasting the index.html.template into a file named index.html. +Adding a new page is as simple as creating a new file in the template folder, +and requesting it via the URL http://domain/newpage.html + +Minimal allows you to focus just in the HTML content, as the header and the +footer are already provided by the application. + +Minimal it also has support for Google Analytics, so you only have to paste the +tracking code in the configuration file for tracking all the pages that you +have created. + +Finally, as Minimal is created using the micro-framework [Flask](http://flask.pocoo.org/) it is really easy to extend the application, as there are several plugins that can enhance the user experience. + +# Installation + +In order to install it you have to follow the next steps: + + * Clone the repository + * Create a virtualenv for the application: virtualenv env + * Activate it: . env/bin/activate + * Install the required libraries in the virtualenv: pip install -r + requirements.txt + * Create a settings file for the server: cp settings_local.py.tmpl to + settings_local.py + * Launch the demo server: python minimal/app.py + +If you want to deploy it using Apache2, you only have to check the **contrib** +folder, where you will find the WSGI application and the Apache2 configuration +site. diff --git a/contrib/apache2/minimal-site b/contrib/apache2/minimal-site new file mode 100644 index 0000000..1c06bf2 --- /dev/null +++ b/contrib/apache2/minimal-site @@ -0,0 +1,14 @@ + + ServerName example.com + + DocumentRoot /home/user/minimal + WSGIDaemonProcess pybossa user=user1 group=group1 threads=5 + WSGIScriptAlias / /home/user/pybossa/contrib/minimal.wsgi + + + WSGIProcessGroup minimal + WSGIApplicationGroup %{GLOBAL} + Order deny,allow + Allow from all + + diff --git a/contrib/minimal.wsgi b/contrib/minimal.wsgi new file mode 100644 index 0000000..a12617d --- /dev/null +++ b/contrib/minimal.wsgi @@ -0,0 +1,9 @@ +# Activate the virtual env +activate_this = '/home/teleyinex/Proyectos/public_html/minimal/env/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) +# Import sys to add the path of minimal +import sys +sys.path.insert(0,'/home/teleyinex/Proyectos/minimal') +# Run the web-app +from minimal.app import app as application +application.debug = True diff --git a/contrib/minimal.wsgi.template b/contrib/minimal.wsgi.template new file mode 100644 index 0000000..78e962a --- /dev/null +++ b/contrib/minimal.wsgi.template @@ -0,0 +1,10 @@ +# Activate the virtual env +activate_this = '/home/user/minimal/env/bin/activate_this.py' +execfile(activate_this, dict(__file__=activate_this)) +# Import sys to add the path of minimal +import sys +sys.path.insert(0,'/home/user/minimal') +# Run the web-app +from minimal.app import app as application +# Uncomment to see the errors in the Apache log file +# application.debug = True diff --git a/web/__init__.py b/minimal/__init__.py similarity index 100% rename from web/__init__.py rename to minimal/__init__.py diff --git a/web/app.py b/minimal/app.py similarity index 73% rename from web/app.py rename to minimal/app.py index bbf7f3d..dfad380 100644 --- a/web/app.py +++ b/minimal/app.py @@ -1,34 +1,31 @@ -# This file is part of flask-web. +# This file is part of minimal. # -# flask-web is free software: you can redistribute it and/or modify +# minimal is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# flask-web is distributed in the hope that it will be useful, +# minimal is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with flask-web. If not, see . +# along with minimal. If not, see . import os from flask import Flask, render_template, abort, request from datetime import datetime +from views.assets import assets app = Flask(__name__) +print assets.static_folder +app.register_blueprint(assets, url_prefix="/assets") import settings_local as settings # Set up the configuration values for the application -def configure_app(app): - app.config.from_object(settings) - # parent directory - here = os.path.dirname(os.path.abspath( __file__ )) - config_path = os.path.join(os.path.dirname(here), 'settings_local.py') - if os.path.exists(config_path): - app.config.from_pyfile(config_path) +app.config.from_object(settings) # Pass all these variables to all the views @app.context_processor @@ -63,5 +60,5 @@ def page(page): return abort(404) if __name__ == '__main__': - configure_app(app) + #configure_app(app) app.run() diff --git a/web/settings_local.py.tmpl b/minimal/settings_local.py.tmpl similarity index 100% rename from web/settings_local.py.tmpl rename to minimal/settings_local.py.tmpl diff --git a/web/static/bootstrap/css/bootstrap-responsive.css b/minimal/static/bootstrap/css/bootstrap-responsive.css similarity index 100% rename from web/static/bootstrap/css/bootstrap-responsive.css rename to minimal/static/bootstrap/css/bootstrap-responsive.css diff --git a/web/static/bootstrap/css/bootstrap-responsive.min.css b/minimal/static/bootstrap/css/bootstrap-responsive.min.css similarity index 100% rename from web/static/bootstrap/css/bootstrap-responsive.min.css rename to minimal/static/bootstrap/css/bootstrap-responsive.min.css diff --git a/web/static/bootstrap/css/bootstrap.css b/minimal/static/bootstrap/css/bootstrap.css similarity index 100% rename from web/static/bootstrap/css/bootstrap.css rename to minimal/static/bootstrap/css/bootstrap.css diff --git a/web/static/bootstrap/css/bootstrap.min.css b/minimal/static/bootstrap/css/bootstrap.min.css similarity index 100% rename from web/static/bootstrap/css/bootstrap.min.css rename to minimal/static/bootstrap/css/bootstrap.min.css diff --git a/web/static/bootstrap/img/glyphicons-halflings-white.png b/minimal/static/bootstrap/img/glyphicons-halflings-white.png similarity index 100% rename from web/static/bootstrap/img/glyphicons-halflings-white.png rename to minimal/static/bootstrap/img/glyphicons-halflings-white.png diff --git a/web/static/bootstrap/img/glyphicons-halflings.png b/minimal/static/bootstrap/img/glyphicons-halflings.png similarity index 100% rename from web/static/bootstrap/img/glyphicons-halflings.png rename to minimal/static/bootstrap/img/glyphicons-halflings.png diff --git a/web/static/bootstrap/js/bootstrap.js b/minimal/static/bootstrap/js/bootstrap.js similarity index 100% rename from web/static/bootstrap/js/bootstrap.js rename to minimal/static/bootstrap/js/bootstrap.js diff --git a/web/static/bootstrap/js/bootstrap.min.js b/minimal/static/bootstrap/js/bootstrap.min.js similarity index 100% rename from web/static/bootstrap/js/bootstrap.min.js rename to minimal/static/bootstrap/js/bootstrap.min.js diff --git a/minimal/static/css/style.css b/minimal/static/css/style.css new file mode 100644 index 0000000..3537a8e --- /dev/null +++ b/minimal/static/css/style.css @@ -0,0 +1,3 @@ +footer { + text-align: center; +} diff --git a/web/static/js/jquery.min.js b/minimal/static/js/jquery.min.js similarity index 100% rename from web/static/js/jquery.min.js rename to minimal/static/js/jquery.min.js diff --git a/web/templates/helpers/_carousel.html b/minimal/templates/helpers/_carousel.html similarity index 100% rename from web/templates/helpers/_carousel.html rename to minimal/templates/helpers/_carousel.html diff --git a/web/templates/helpers/_carousel.js b/minimal/templates/helpers/_carousel.js similarity index 100% rename from web/templates/helpers/_carousel.js rename to minimal/templates/helpers/_carousel.js diff --git a/web/templates/helpers/_googleanalytics.html b/minimal/templates/helpers/_googleanalytics.html similarity index 100% rename from web/templates/helpers/_googleanalytics.html rename to minimal/templates/helpers/_googleanalytics.html diff --git a/web/templates/helpers/_herounit.html b/minimal/templates/helpers/_herounit.html similarity index 100% rename from web/templates/helpers/_herounit.html rename to minimal/templates/helpers/_herounit.html diff --git a/web/templates/index.html.template b/minimal/templates/index.html.template similarity index 100% rename from web/templates/index.html.template rename to minimal/templates/index.html.template diff --git a/web/templates/layout/_footer.html b/minimal/templates/layout/_footer.html similarity index 60% rename from web/templates/layout/_footer.html rename to minimal/templates/layout/_footer.html index 96576e5..ffb20e8 100644 --- a/web/templates/layout/_footer.html +++ b/minimal/templates/layout/_footer.html @@ -3,5 +3,6 @@

© {{ copyright }} {{ year }}

+

Powered by Minimal

{% endblock %} diff --git a/web/templates/layout/_topbar.html b/minimal/templates/layout/_topbar.html similarity index 100% rename from web/templates/layout/_topbar.html rename to minimal/templates/layout/_topbar.html diff --git a/web/templates/layout/base.html b/minimal/templates/layout/base.html similarity index 57% rename from web/templates/layout/base.html rename to minimal/templates/layout/base.html index 433c0f5..d9e8dc9 100644 --- a/web/templates/layout/base.html +++ b/minimal/templates/layout/base.html @@ -8,14 +8,15 @@ - + - + + - - - - - + + + + + {% include 'helpers/_googleanalytics.html' %} @@ -47,8 +48,8 @@ - - + + {% if carousel %} diff --git a/minimal/views/__init__.py b/minimal/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/minimal/views/assets.py b/minimal/views/assets.py new file mode 100644 index 0000000..c47aad1 --- /dev/null +++ b/minimal/views/assets.py @@ -0,0 +1,3 @@ +from flask import Blueprint + +assets = Blueprint('assets', __name__, static_folder='../static') diff --git a/minimal/views/static/prueba.css b/minimal/views/static/prueba.css new file mode 100644 index 0000000..25fa51c --- /dev/null +++ b/minimal/views/static/prueba.css @@ -0,0 +1,2 @@ +body { +} diff --git a/test/base.py b/test/base.py index b4df1f2..0bea05c 100644 --- a/test/base.py +++ b/test/base.py @@ -1,5 +1,5 @@ -from web import app -from web import settings_local as settings +from minimal import app +from minimal import settings_local as settings webapp = app.app webapp.config.from_object(settings) diff --git a/test/tests.py b/test/tests.py index 46f34d6..8c45da0 100644 --- a/test/tests.py +++ b/test/tests.py @@ -12,7 +12,7 @@ def setUpClass(self): self.file_name = str(random.randint(0,100)) + "_test.html" self.msg = str(random.randint(0,1000)) + "Random Test" # Create a random page to be served by the server - f = open("web/templates/" + self.file_name ,"w") + f = open("minimal/templates/" + self.file_name ,"w") f.write(self.msg) f.close() @@ -20,7 +20,7 @@ def setUpClass(self): def tearDownClass(self): """Delete created pages for the tests""" # Delete random page - os.remove("web/templates/{}".format(self.file_name)) + os.remove("minimal/templates/{}".format(self.file_name)) def test_01_index_template(self): """Test index template page works""" @@ -40,6 +40,8 @@ def test_03_styles(self): res = self.webapp.get('/') assert 'bootstrap.css' in res.data, res.data assert 'bootstrap-responsive.css' in res.data, res.data + # Check that the Blueprint is serving the static data + assert 'assets/static' in res.data, res.data def test_04_googleanalytics(self): """Test Google Analaytics is included"""