commit 0cce7f9e2a19c83fa76645d7773d39d54f357c43 Author: Yohan Boniface Date: Tue Nov 20 10:47:19 2012 +0100 First POC diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..692432b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.pyc +*.egg-info +youmap/settings/local.py +youmap/settings/local/* +docs/_build diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..80153bf8 --- /dev/null +++ b/README.rst @@ -0,0 +1,23 @@ +YouMap project +============== + +Quickstart +---------- + +To bootstrap the project:: + + virtualenv youmap + source youmap/bin/activate + cd path/to/youmap/repository + pip install -r requirements.pip + pip install -e . + cp youmap/settings/local.py.example youmap/settings/local.py + manage.py syncdb --migrate + +Documentation +------------- + +Developer documentation is available in Sphinx format in the docs directory. + +Initial installation instructions (including how to build the documentation as +HTML) can be found in docs/install.rst. diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..0b5e0caa --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,88 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf _build/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html + @echo + @echo "Build finished. The HTML pages are in _build/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml + @echo + @echo "Build finished. The HTML pages are in _build/dirhtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in _build/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in _build/qthelp, like this:" + @echo "# qcollectiongenerator _build/qthelp/project.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile _build/qthelp/project.qhc" + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex + @echo + @echo "Build finished; the LaTeX files are in _build/latex." + @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ + "run these through (pdf)latex." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes + @echo + @echo "The overview file is in _build/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in _build/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in _build/doctest/output.txt." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..c2286a71 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,195 @@ +# -*- coding: utf-8 -*- +# +# youmap documentation build configuration file, created by +# sphinx-quickstart on Wed Aug 19 10:27:46 2009. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os +import datetime + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.append(os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.autodoc'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'youmap' +copyright = u'%d, myauthor' % datetime.date.today().year + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '1.0' +# The full version, including alpha/beta/rc tags. +release = '1.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directory, that shouldn't be searched +# for source files. +exclude_trees = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_use_modindex = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'youmapdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'youmap.tex', u'youmap Documentation', + u'myauthor', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True diff --git a/docs/deployment.rst b/docs/deployment.rst new file mode 100644 index 00000000..34e39eb9 --- /dev/null +++ b/docs/deployment.rst @@ -0,0 +1,28 @@ +Deployment +========== + +Staging/Development +------------------- + +`Fabric `_ is used to allow developers to +easily push changes to a previously setup development/staging environment. +To get started, install Fabric by running the following command from within +your virtual environment:: + + pip install fabric==1.4 + +So see a list of available commands, run the following command from within your +project directory:: + + fab -l + +Some common commands:: + + fab restart # Restart the web server. + fab update # Just update the repository. + fab push deploy # Push, then fully deploy. + +From the within the project directory, you can just run ``fab [command]``. +If you want to run fabric outside of the directory, use:: + + fab --fabfile /path/to/project/fabfile.py [command] diff --git a/docs/environments.rst b/docs/environments.rst new file mode 100644 index 00000000..b702cd37 --- /dev/null +++ b/docs/environments.rst @@ -0,0 +1,17 @@ +================== +Environments +================== + +When deploying to multiple environments (development, staging, production, etc.), you'll likely want to deploy different configurations. Each environment/configuration should have its own file in ``youmap/settings`` and inherit from ``youmap.settings.base``. A ``dev`` environment is provided as an example. + +By default, ``manage.py`` and ``wsgi.py`` will use ``youmap.settings.local`` if no settings module has been defined. To override this, use the standard Django constructs (setting the ``DJANGO_SETTINGS_MODULE`` environment variable or passing in ``--settings=youmap.settings.``). Alternatively, you can symlink your environment's settings to ``youmap/settings/local.py``. + +You may want to have different ``wsgi.py`` and ``urls.py`` files for different environments as well. If so, simply follow the directory structure laid out by ``youmap/settings``, for example:: + + wsgi/ + __init__.py + base.py + dev.py + ... + +The settings files have examples of how to point Django to these specific environments. \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..4304d61a --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,19 @@ +Welcome to youmap's documentation! +===================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + install + environments + deployment + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/install.rst b/docs/install.rst new file mode 100644 index 00000000..45c4d857 --- /dev/null +++ b/docs/install.rst @@ -0,0 +1,57 @@ +================== +Installation +================== + +Pre-Requisites +=============== + +* `setuptools `_ +* `virtualenv `_ + +To install all of these system dependencies on a Debian-based system, run:: + + sudo apt-get install python-setuptools + sudo easy_install virtualenv + + +Creating the Virtual Environment +================================ + +First, create a clean base environment using virtualenv:: + + virtualenv youmap + cd youmap + source bin/activate + + +Installing the Project +====================== + +Install the requirements and the project source:: + + cd path/to/your/youmap/repository + pip install -r requirements.pip + pip install -e . + + +Configuring a Local Environment +=============================== + +If you're just checking the project out locally, you can copy some example +configuration files to get started quickly:: + + cp youmap/settings/local.py.example youmap/settings/local.py + manage.py syncdb --migrate + + +Building Documentation +====================== + +Documentation is available in ``docs`` and can be built into a number of +formats using `Sphinx `_. To get started:: + + pip install Sphinx + cd docs + make html + +This creates the documentation in HTML format at ``docs/_build/html``. diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 00000000..407d29f8 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,239 @@ +from fabric.api import task, env, run, local, roles, cd, execute, hide, puts,\ + sudo +import posixpath +import re + +env.project_name = 'youmap' +env.repository = 'git@github.com:lincolnloop/youmap.git' +env.local_branch = 'master' +env.remote_ref = 'origin/master' +env.requirements_file = 'requirements.pip' +env.restart_command = 'supervisorctl restart {project_name}'.format(**env) +env.restart_sudo = True + + +#============================================================================== +# Tasks which set up deployment environments +#============================================================================== + +@task +def live(): + """ + Use the live deployment environment. + """ + server = 'youmap.com' + env.roledefs = { + 'web': [server], + 'db': [server], + } + env.system_users = {server: 'www-data'} + env.virtualenv_dir = '/srv/www/{project_name}'.format(**env) + env.project_dir = '{virtualenv_dir}/src/{project_name}'.format(**env) + env.project_conf = '{project_name}.settings.local'.format(**env) + + +@task +def dev(): + """ + Use the development deployment environment. + """ + server = 'youmap.dev.lincolnloop.com' + env.roledefs = { + 'web': [server], + 'db': [server], + } + env.system_users = {server: 'www-data'} + env.virtualenv_dir = '/srv/www/{project_name}'.format(**env) + env.project_dir = '{virtualenv_dir}/src/{project_name}'.format(**env) + env.project_conf = '{project_name}.conf.local'.format(**env) + + +# Set the default environment. +dev() + + +#============================================================================== +# Actual tasks +#============================================================================== + +@task +@roles('web', 'db') +def bootstrap(action=''): + """ + Bootstrap the environment. + """ + with hide('running', 'stdout'): + exists = run('if [ -d "{virtualenv_dir}" ]; then echo 1; fi'\ + .format(**env)) + if exists and not action == 'force': + puts('Assuming {host} has already been bootstrapped since ' + '{virtualenv_dir} exists.'.format(**env)) + return + sudo('virtualenv {virtualenv_dir}'.format(**env)) + if not exists: + sudo('mkdir -p {0}'.format(posixpath.dirname(env.virtualenv_dir))) + sudo('git clone {repository} {project_dir}'.format(**env)) + sudo('{virtualenv_dir}/bin/pip install -e {project_dir}'.format(**env)) + with cd(env.virtualenv_dir): + sudo('chown -R {user} .'.format(**env)) + fix_permissions() + requirements() + puts('Bootstrapped {host} - database creation needs to be done manually.'\ + .format(**env)) + + +@task +@roles('web', 'db') +def push(): + """ + Push branch to the repository. + """ + remote, dest_branch = env.remote_ref.split('/', 1) + local('git push {remote} {local_branch}:{dest_branch}'.format( + remote=remote, dest_branch=dest_branch, **env)) + + +@task +def deploy(verbosity='normal'): + """ + Full server deploy. + + Updates the repository (server-side), synchronizes the database, collects + static files and then restarts the web service. + """ + if verbosity == 'noisy': + hide_args = [] + else: + hide_args = ['running', 'stdout'] + with hide(*hide_args): + puts('Updating repository...') + execute(update) + puts('Collecting static files...') + execute(collectstatic) + puts('Synchronizing database...') + execute(syncdb) + puts('Restarting web server...') + execute(restart) + + +@task +@roles('web', 'db') +def update(action='check'): + """ + Update the repository (server-side). + + By default, if the requirements file changed in the repository then the + requirements will be updated. Use ``action='force'`` to force + updating requirements. Anything else other than ``'check'`` will avoid + updating requirements at all. + """ + with cd(env.project_dir): + remote, dest_branch = env.remote_ref.split('/', 1) + run('git fetch {remote}'.format(remote=remote, + dest_branch=dest_branch, **env)) + with hide('running', 'stdout'): + changed_files = run('git diff-index --cached --name-only ' + '{remote_ref}'.format(**env)).splitlines() + if not changed_files and action != 'force': + # No changes, we can exit now. + return + if action == 'check': + reqs_changed = env.requirements_file in changed_files + else: + reqs_changed = False + run('git merge {remote_ref}'.format(**env)) + run('find -name "*.pyc" -delete') + run('git clean -df') + fix_permissions() + if action == 'force' or reqs_changed: + # Not using execute() because we don't want to run multiple times for + # each role (since this task gets run per role). + requirements() + + +@task +@roles('web') +def collectstatic(): + """ + Collect static files from apps and other locations in a single location. + """ + dj('collectstatic --link --noinput') + with cd('{virtualenv_dir}/var/static'.format(**env)): + fix_permissions() + + +@task +@roles('db') +def syncdb(sync=True, migrate=True): + """ + Synchronize the database. + """ + dj('syncdb --migrate --noinput') + + +@task +@roles('web') +def restart(): + """ + Restart the web service. + """ + if env.restart_sudo: + cmd = sudo + else: + cmd = run + cmd(env.restart_command) + + +@task +@roles('web', 'db') +def requirements(): + """ + Update the requirements. + """ + run('{virtualenv_dir}/bin/pip install -r {project_dir}/requirements.txt'\ + .format(**env)) + with cd('{virtualenv_dir}/src'.format(**env)): + with hide('running', 'stdout', 'stderr'): + dirs = [] + for path in run('ls -db1 -- */').splitlines(): + full_path = posixpath.normpath(posixpath.join(env.cwd, path)) + if full_path != env.project_dir: + dirs.append(path) + if dirs: + fix_permissions(' '.join(dirs)) + with cd(env.virtualenv_dir): + with hide('running', 'stdout'): + match = re.search(r'\d+\.\d+', run('bin/python --version')) + if match: + with cd('lib/python{0}/site-packages'.format(match.group())): + fix_permissions() + + +#============================================================================== +# Helper functions +#============================================================================== + +def dj(command): + """ + Run a Django manage.py command on the server. + """ + run('{virtualenv_dir}/bin/manage.py {dj_command} ' + '--settings {project_conf}'.format(dj_command=command, **env)) + + +def fix_permissions(path='.'): + """ + Fix the file permissions. + """ + if ' ' in path: + full_path = '{path} (in {cwd})'.format(path=path, cwd=env.cwd) + else: + full_path = posixpath.normpath(posixpath.join(env.cwd, path)) + puts('Fixing {0} permissions'.format(full_path)) + with hide('running'): + system_user = env.system_users.get(env.host) + if system_user: + run('chmod -R g=rX,o= -- {0}'.format(path)) + run('chgrp -R {0} -- {1}'.format(system_user, path)) + else: + run('chmod -R go= -- {0}'.format(path)) diff --git a/manage.py b/manage.py new file mode 100644 index 00000000..c30bedc8 --- /dev/null +++ b/manage.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "youmap.settings.local") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/requirements.pip b/requirements.pip new file mode 100644 index 00000000..e62c4ce8 --- /dev/null +++ b/requirements.pip @@ -0,0 +1,10 @@ +# This file collects all required third-party applications that are needed +# to run this project. Later you can install all these apps in a row +# using pip. Example:: +# +# pip install -r requirements.pip + +django==1.4.2 +#south==0.7.6 +git+git://github.com/petry/django-foundation.git +git+git://github.com/yohanboniface/django-chickpea.git \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..45b2afd7 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +from setuptools import setup, find_packages + +setup( + name='youmap', + version='1.0', + description="", + author="Lincoln Loop", + author_email='info@lincolnloop.com', + url='', + packages=find_packages(), + package_data={'youmap': ['static/*.*', 'templates/*.*']}, + scripts=['manage.py'], +) diff --git a/youmap/__init__.py b/youmap/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/youmap/apps/__init__.py b/youmap/apps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/youmap/settings/__init__.py b/youmap/settings/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/youmap/settings/base.py b/youmap/settings/base.py new file mode 100644 index 00000000..c3ff60ff --- /dev/null +++ b/youmap/settings/base.py @@ -0,0 +1,125 @@ +"""Base settings shared by all environments""" +# Import global settings to make it easier to extend settings. +from django.conf.global_settings import * # pylint: disable=W0614,W0401 + +#============================================================================== +# Generic Django project settings +#============================================================================== + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +SITE_ID = 1 +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +TIME_ZONE = 'UTC' +USE_TZ = True +USE_I18N = True +USE_L10N = True +LANGUAGE_CODE = 'en' +LANGUAGES = ( + ('en', 'English'), +) + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'j6fly6aomgo6!3_$v#9kvhw-%wgs1@1l6x+4nr73tmn40=&_@&' + +INSTALLED_APPS = ( + # 'youmap.apps.', + 'chickpea', + 'foundation', + + #'south', + + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.admin', + 'django.contrib.admindocs', + 'django.contrib.gis', +) + +#============================================================================== +# Calculation of directories relative to the project module location +#============================================================================== + +import os +import sys +import youmap as project_module + +PROJECT_DIR = os.path.dirname(os.path.realpath(project_module.__file__)) + +PYTHON_BIN = os.path.dirname(sys.executable) +ve_path = os.path.dirname(os.path.dirname(os.path.dirname(PROJECT_DIR))) +# Assume that the presence of 'activate_this.py' in the python bin/ +# directory means that we're running in a virtual environment. +if os.path.exists(os.path.join(PYTHON_BIN, 'activate_this.py')): + # We're running with a virtualenv python executable. + VAR_ROOT = os.path.join(os.path.dirname(PYTHON_BIN), 'var') +elif ve_path and os.path.exists(os.path.join(ve_path, 'bin', + 'activate_this.py')): + # We're running in [virtualenv_root]/src/[project_name]. + VAR_ROOT = os.path.join(ve_path, 'var') +else: + # Set the variable root to a path in the project which is + # ignored by the repository. + VAR_ROOT = os.path.join(PROJECT_DIR, 'var') + +if not os.path.exists(VAR_ROOT): + os.mkdir(VAR_ROOT) + +#============================================================================== +# Project URLS and media settings +#============================================================================== + +ROOT_URLCONF = 'youmap.urls' + +LOGIN_URL = '/login/' +LOGOUT_URL = '/logout/' +LOGIN_REDIRECT_URL = '/' + +STATIC_URL = '/static/' +MEDIA_URL = '/uploads/' + +STATIC_ROOT = os.path.join(VAR_ROOT, 'static') +MEDIA_ROOT = os.path.join(VAR_ROOT, 'uploads') + +STATICFILES_DIRS = ( + os.path.join(PROJECT_DIR, 'static'), +) + +#============================================================================== +# Templates +#============================================================================== + +TEMPLATE_DIRS = ( + os.path.join(PROJECT_DIR, 'templates'), +) + +TEMPLATE_CONTEXT_PROCESSORS += ( +) + +#============================================================================== +# Middleware +#============================================================================== + +MIDDLEWARE_CLASSES += ( +) + +#============================================================================== +# Auth / security +#============================================================================== + +AUTHENTICATION_BACKENDS += ( +) + +#============================================================================== +# Miscellaneous project settings +#============================================================================== + +#============================================================================== +# Third party app settings +#============================================================================== diff --git a/youmap/settings/dev.py b/youmap/settings/dev.py new file mode 100644 index 00000000..a8556485 --- /dev/null +++ b/youmap/settings/dev.py @@ -0,0 +1,20 @@ +"""Settings for Development Server""" +from youmap.settings.base import * # pylint: disable=W0614,W0401 + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +VAR_ROOT = '/var/www/youmap' +MEDIA_ROOT = os.path.join(VAR_ROOT, 'uploads') +STATIC_ROOT = os.path.join(VAR_ROOT, 'static') + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'youmap', +# 'USER': 'dbuser', +# 'PASSWORD': 'dbpassword', + } +} + +# WSGI_APPLICATION = 'youmap.wsgi.dev.application' diff --git a/youmap/static/.gitignore b/youmap/static/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/youmap/static/youmap/youmap.css b/youmap/static/youmap/youmap.css new file mode 100644 index 00000000..be9981bb --- /dev/null +++ b/youmap/static/youmap/youmap.css @@ -0,0 +1,32 @@ +/* + Foundation use a position:relative; on body, which break the 100% rule + on #map +*/ +body.map_detail { + width: 100%; + height: 100%; + position: inherit; +} + +/* HOME */ +.map_fragment { + width: 100%; +} +.map_list .map_fragment { + height: 200px; +} + +/* Modals */ +.reveal-modal.update-tilelayers { + width: 75%; + max-height: 500px; /* TODO Make it dynamic */ + overflow: auto; + margin-left: -35%; +} + +/* Global alert */ +.alert-box.global { + z-index: 1001; + margin-right: auto; + margin-left: auto; +} \ No newline at end of file diff --git a/youmap/templates/404.html b/youmap/templates/404.html new file mode 100644 index 00000000..f5209ebe --- /dev/null +++ b/youmap/templates/404.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block content %} + Not Found +{% endblock %} \ No newline at end of file diff --git a/youmap/templates/500.html b/youmap/templates/500.html new file mode 100644 index 00000000..83d90601 --- /dev/null +++ b/youmap/templates/500.html @@ -0,0 +1,14 @@ + + + + {% block head_title %}{% endblock %} + + + + +
+ Server Error +
+ + + diff --git a/youmap/templates/base.html b/youmap/templates/base.html new file mode 100644 index 00000000..cffc9e80 --- /dev/null +++ b/youmap/templates/base.html @@ -0,0 +1,70 @@ + + + + {% block head_title %}YouMap{% endblock %} + + + + + + + + + + {% block extra_head %} + {% endblock extra_head %} + + + + +
+ {% block content %} + {% endblock %} +
+ + + + + + + + + + + + + + + {% block bottom_js %} + + {% endblock %} +
+ + diff --git a/youmap/templates/chickpea/map_form.html b/youmap/templates/chickpea/map_form.html new file mode 100644 index 00000000..e6cb0c66 --- /dev/null +++ b/youmap/templates/chickpea/map_form.html @@ -0,0 +1,31 @@ +

Create your map now!

+
+ {{ form.non_field_errors }} + {% csrf_token %} + {{ form.name }} + {% for error in form.name.errors %} + {{ error|escape }} + {% endfor %} + {{ form.description }} + {{ form.description.errors }} + {{ form.zoom }} + {{ form.center }} + +
+ + \ No newline at end of file diff --git a/youmap/templates/chickpea/map_update_tilelayers.html b/youmap/templates/chickpea/map_update_tilelayers.html new file mode 100644 index 00000000..e214ec6f --- /dev/null +++ b/youmap/templates/chickpea/map_update_tilelayers.html @@ -0,0 +1,41 @@ +{% load chickpea_tags %} +

Choose your tilelayers

+
+ {% csrf_token %} +
    + {% for tilelayer in tilelayers %} +
  • + +
  • + {% endfor %} +
    + +
    + + + \ No newline at end of file diff --git a/youmap/templates/youmap/home.html b/youmap/templates/youmap/home.html new file mode 100644 index 00000000..a8a32659 --- /dev/null +++ b/youmap/templates/youmap/home.html @@ -0,0 +1,160 @@ +{% extends "base.html" %} + +{% load chickpea_tags %} + +{% block extra_head %} + {% chickpea_css %} + {% chickpea_js %} +{% endblock %} + +{% block content %} +
    +
    + + + + + + + +
    +
    + + +
    +
    +
    + + + +
    +
    + +
    +
    +

    YouMap alpha


    +
    YouMap let you create map with OpenStreetMap layers in a minute and embed them in your site.
    This is a demo instance, you can host your own, it's open source! +
    +
    +
    +
    What you can do?
    +
      +
    1. Choose the layers of your map
    2. +
    3. Add POIs: markers, lines, polygons...
    4. +
    5. Manage POIs colours and icons
    6. +
    7. Batch import geostructured data (GEOJson...)
    8. +
    9. Choose your licence
    10. +
    11. Embed and share your map
    12. +
    +
    + +
    +
    +
    + +
    + +

    Action!


    + + +
    + Test me +
    +
    + + +
    + Fork me +
    +
    + +
    + + + +
    +
    +
    +
    +
    +
    +

    Browse maps

    +
    +
    +
    +
    +
    + {% for map_inst in maps %} +
    + {% map_fragment map_inst %} +
    {{ map_inst.name }} — {{ map_inst.description }} See this map!
    +
    + {% endfor %} +
    +
    +
    + + + + + + + + +{% endblock content %} + + +{% block bottom_js %} + {{ block.super }} + +{% endblock bottom_js %} \ No newline at end of file diff --git a/youmap/urls.py b/youmap/urls.py new file mode 100644 index 00000000..353a8006 --- /dev/null +++ b/youmap/urls.py @@ -0,0 +1,23 @@ +from django.conf import settings +from django.conf.urls.static import static +from django.conf.urls.defaults import patterns, url, include +from django.contrib.staticfiles.urls import staticfiles_urlpatterns + +from django.contrib import admin + +from . import views + +admin.autodiscover() + +urlpatterns = patterns('', + # (r'', include('youmap.apps.')), + (r'^admin/doc/', include('django.contrib.admindocs.urls')), + (r'^admin/', include(admin.site.urls)), + url(r'^$', views.home, name="home"), + (r'', include('chickpea.urls')), +) + +if settings.DEBUG and settings.MEDIA_ROOT: + urlpatterns += static(settings.MEDIA_URL, + document_root=settings.MEDIA_ROOT) +urlpatterns += staticfiles_urlpatterns() diff --git a/youmap/views.py b/youmap/views.py new file mode 100644 index 00000000..3c487735 --- /dev/null +++ b/youmap/views.py @@ -0,0 +1,15 @@ +from django.views.generic import TemplateView + +from chickpea.models import Map + + +class Home(TemplateView): + template_name = "youmap/home.html" + + def get_context_data(self, **kwargs): + maps = Map.objects.all()[:20] + return { + "maps": maps + } + +home = Home.as_view() diff --git a/youmap/wsgi.py b/youmap/wsgi.py new file mode 100644 index 00000000..861c4dbb --- /dev/null +++ b/youmap/wsgi.py @@ -0,0 +1,29 @@ +""" +WSGI config for youmap project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "youmap.settings.local") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application)