diff --git a/README.md b/README.md index 953e121..d9c1f34 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -[![Stories in Ready](https://badge.waffle.io/timlinux/user_map.png?label=ready)](https://waffle.io/timlinux/user_map) -[![Build Status](http://jenkins.linfiniti.com/buildStatus/icon?job=UserMap)](http://jenkins.linfiniti.com/job/UserMap/) - User Map ======== A simple flask application for creating user community maps. +Hacking +------- + By default, this app reads configuration from `users/default_config.py`. To override values set in default config, simply copy the contents of `users/default_config.py` and save it elsewhere. @@ -14,20 +14,18 @@ of `users/default_config.py` and save it elsewhere. Then edit the custom config file, setting appropriate values as needed. -To run in debug mode (which will also serve up static content), -use the `-d` flag: +To run the development server: - USERS_CONFIG=/path/to/custom/config.py python runserver.py -d + USERS_CONFIG=/path/to/custom/config.py python manage.py runserver Each config item is overridable through environment variable. -For instance, if you want to suppress email delivery, -simply set appropriate value: +For instance, if you want to suppress email delivery, simply set appropriate value: - USERS_MAIL_SUPPRESS_SEND=True python runserver + USERS_MAIL_SUPPRESS_SEND=True python manage.py runserver To run testcases: - USERS_CONFIG=/path/to/custom/config.py MAIL_SUPPRESS_SEND=True ./runtests.sh + USERS_CONFIG=/path/to/custom/config.py USERS_MAIL_SUPPRESS_SEND=True ./runtests.sh Collaboration ------------- @@ -38,28 +36,6 @@ Collaboration 4. Once it done, submit your pull request (PR) against upstream `develop` branch. 5. Our maintainers will review your PR. If it's good — all tests passed and proposed feature is in our roadmap — your PR will be merged. -Deployment using Docker ------------------------ - -If you are using docker, you can create a Docker image for this app easily as -follows: - -``` -wget -O Dockerfile https://raw.github.com/timlinux/user_map/master/docker/Dockerfile -wget -O sources.list https://raw.github.com/timlinux/user_map/master/docker/sources.list -wget -O post-setup.sh https://raw.github.com/timlinux/user_map/master/docker/post-setup.sh -chmod +x post-setup.sh - -docker build -t linfiniti/user_map:base . -docker run -d -p 8099:80 -t linfiniti/user_map:base -n user_map -D -``` - -If you are on a Hetzner server, consider replacing the second line above with: - -``` -wget -O sources.list https://raw.github.com/timlinux/user_map/master/docker/hetzner-sources.list -``` - Authors ------- diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..32ee53c --- /dev/null +++ b/manage.py @@ -0,0 +1,7 @@ +from flask.ext.script import Manager + +from users import APP + +if __name__ == "__main__": + manager = Manager(APP) + manager.run() diff --git a/requirements.txt b/requirements.txt index 480195f..d22d0c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Flask==0.10.1 Flask-Mail==0.9.0 +Flask-Script==2.0.5 Jinja2==2.7.3 MarkupSafe==0.23 Werkzeug==0.9.6 diff --git a/runserver.py b/runserver.py deleted file mode 100644 index 0a1eea4..0000000 --- a/runserver.py +++ /dev/null @@ -1,29 +0,0 @@ -# coding=utf-8 -"""Simple runner for our flask app. - -see http://flask.pocoo.org/docs/patterns/packages/#larger-applications -""" -import optparse - -from users import APP, LOGGER -from users.static import static_file - -if __name__ == '__main__': - parser = optparse.OptionParser() - parser.add_option('-d', '--debug', dest='debug', default=False, - help='turn on Flask debugging', action='store_true') - - options, args = parser.parse_args() - - if options.debug: - print 'Running in debug mode' - LOGGER.info('Running in debug mode') - APP.debug = True - # set up flask to serve static content - APP.add_url_rule('/', 'static_file', static_file) - else: - print 'Running in production mode' - LOGGER.info('Running in production mode') - - print 'Starting.....' - APP.run(host='0.0.0.0') diff --git a/users/__init__.py b/users/__init__.py index c8ea437..b56cbdd 100644 --- a/users/__init__.py +++ b/users/__init__.py @@ -68,25 +68,10 @@ def setup_logger(): APP = Flask(__name__) -#: Load configuration from any possible means. -#: To override default configuration defined in ``users.default_config``, -#: simply copy the contents of ``config.py`` file, -#: and save it into a file. -#: -#: .. sourcecode:: sh -#: -#: USERS_CONFIG=/path/to/config.py python runserver.py -#: -#: Another way of doing it is by setting environment variable for each -#: config item. -#: -#: .. sourcecode:: sh -#: -#: USERS_CONFIG=/path/to/config.py USERS_MAIL_SUPPRESS_SEND=True \ -#: python runserver.py -#: +# Load configuration from any possible means. AppConfig(APP, default_settings="users.default_config") +# Mailer mail = Mail(APP) # backward-compat diff --git a/users/static.py b/users/static.py deleted file mode 100644 index 6ca23e7..0000000 --- a/users/static.py +++ /dev/null @@ -1,46 +0,0 @@ -# coding=utf-8 -"""Helper module for serving static files when running in dev mode. -:copyright: (c) 2013 by Tim Sutton -:license: GPLv3, see LICENSE for more details. -""" -import os -from flask import abort, Response - -# -# These are only used to serve static files when testing -# -FILE_SUFFIX_MIMETYPES = { - '.css': 'text/css', - '.jpg': 'image/jpeg', - '.html': 'text/html', - '.ico': 'image/x-icon', - '.png': 'image/png', - '.js': 'application/javascript', - '.eot': 'application/vnd.ms-fontobject', - '.svg': 'image/svg+xml', - '.ttf': 'font/ttf', - '.woff': 'application/font-woff' -} - - -def static_file(path): - """Flask static file hander used for local testing. - - :param path: Path for the static resource to be served. - :type path: str - - :returns: An http Response of the correct mime type for the resource - requested. - :rtype: HttpResponse - """ - try: - path = os.path.join(os.path.dirname(__file__), os.path.pardir, path) - static_resource = open(path) - except IOError: - abort(404) - return - _, ext = os.path.splitext(path) - if ext in FILE_SUFFIX_MIMETYPES: - return Response( - static_resource.read(), mimetype=FILE_SUFFIX_MIMETYPES[ext]) - return static_resource.read() diff --git a/users/templates/html/base.html b/users/templates/html/base.html index 50f7730..4996087 100644 --- a/users/templates/html/base.html +++ b/users/templates/html/base.html @@ -6,31 +6,24 @@ {% block title %}{{ project_name | safe }} User Map{% endblock %} {% block head_resources %} - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + {% endblock head_resources %} diff --git a/users/templates/html/index.html b/users/templates/html/index.html index 18450c0..a6d7d0d 100644 --- a/users/templates/html/index.html +++ b/users/templates/html/index.html @@ -1,11 +1,13 @@ {% extends "html/base.html" %} {% block head_resources %} - {{ super() }} - - - - + {{ super() }} + + + + {% endblock head_resources %} {% block body %} diff --git a/users/views.py b/users/views.py index 9b9068f..559cd21 100644 --- a/users/views.py +++ b/users/views.py @@ -153,7 +153,7 @@ def add_user_view(): body = render_template( 'text/registration_confirmation_email.txt', project_name=APP.config['PROJECT_NAME'], - url=APP.config['PUBLIC_URL'], + url=APP.config["PUBLIC_URL"], user=added_user) recipient = added_user['email'] send_async_mail( @@ -307,7 +307,7 @@ def delete_user_view(guid): """ # Delete User delete_user(guid) - return APP.config['PUBLIC_URL'] + return APP.config["PUBLIC_URL"] @APP.route('/download') @@ -362,7 +362,7 @@ def reminder_view(): body = render_template( 'text/registration_confirmation_email.txt', project_name=APP.config['PROJECT_NAME'], - url=APP.config['PUBLIC_URL'], + url=APP.config["PUBLIC_URL"], user=user) send_async_mail( sender=MAIL_ADMIN,