Skip to content

Commit

Permalink
Add a demo page for next_color
Browse files Browse the repository at this point in the history
  • Loading branch information
Natim committed Jun 11, 2013
1 parent 0224da8 commit 8eb4ea4
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.pyc
*~
*.egg-info/
var/
.coverage
/bin/
/lib/
/include/
/build/
/local/
/.tox/
41 changes: 41 additions & 0 deletions chartjs/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
COLORS = [
(202, 201, 197), # Light gray
(171, 9, 0), # Red
(166, 78, 46), # Light orange
(255, 190, 67), # Yellow
(163, 191, 63), # Light green
(122, 159, 191), # Light blue
(140, 5, 84), # Pink
(166, 133, 93), # Light brown
(75, 64, 191), # Red blue
(237, 124, 60), # orange
]


def next_color(color_list=COLORS):
"""Create a different color from a base color list.
>>> color_list = (
... (122, 159, 191), # Light blue
... (202, 201, 197), # Light gray,
... )
>>> g = next_color(color_list)
>>> next(g)
[122, 159, 191]
>>> next(g)
[202, 201, 197]
>>> next(g)
[63, 100, 132]
>>> next(g)
[143, 142, 138]
>>> next(g)
[4, 41, 73]
>>> next(g)
[84, 83, 79]
"""
step = 1
while True:
for color in color_list:
yield map(lambda base: (base + step) % 256, color)
step += 197
60 changes: 60 additions & 0 deletions demo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
############
Demo project
############

The :file:`demo/` folder holds a demo project to illustrate django-chartjs
usage.


***********************
Browse demo code online
***********************

See `demo folder in project's repository`_.


***************
Deploy the demo
***************

System requirements:

* `Python`_ version 2.7 or 3.3, available as ``python`` command.

.. note::

You may use `virtualenv`_ to make sure the active ``python`` is the right
one.

* ``make`` and ``wget`` to use the provided :file:`Makefile`.

Execute:

.. code-block:: sh

git clone [email protected]:novagile/django-chartjs.git
cd django-chartjs/
make demo

It installs and runs the demo server on localhost, port 8000. So have a look
at http://localhost:8000/

.. note::

If you cannot execute the Makefile, read it and adapt the few commands it
contains to your needs.

Browse and use :file:`demo/demoproject/` as a sandbox.


**********
References
**********

.. target-notes::

.. _`demo folder in project's repository`:
https://github.com/novagile/django-chartjs/tree/master/demo/demoproject/

.. _`Python`: http://python.org
.. _`virtualenv`: http://virtualenv.org
Empty file added demo/demoproject/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions demo/demoproject/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python
import os
import sys

from django.core.management import execute_from_command_line

def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.settings" % __package__)
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
Empty file added demo/demoproject/models.py
Empty file.
98 changes: 98 additions & 0 deletions demo/demoproject/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""Django settings for Django-DownloadView demo project."""
from os.path import abspath, dirname, join


# Configure some relative directories.
demoproject_dir = dirname(abspath(__file__))
demo_dir = dirname(demoproject_dir)
root_dir = dirname(demo_dir)
data_dir = join(root_dir, 'var')


# Mandatory settings.
ROOT_URLCONF = 'demoproject.urls'
WSGI_APPLICATION = 'demoproject.wsgi.application'


# Database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': join(data_dir, 'db.sqlite'),
}
}


# Required.
SECRET_KEY = "This is a secret made public on project's repository."

# Media and static files.
MEDIA_ROOT = join(data_dir, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = join(data_dir, 'static')
STATIC_URL = '/static/'


# Applications.
INSTALLED_APPS = (
# Standard Django applications.
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'chartjs',
'demoproject',
# For test purposes. The demo project is part of django-downloadview
# test suite.
'django_nose',
)

TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
]

# Default middlewares. You may alter the list later.
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

LANGUAGE_CODE = 'fr'
ugettext = lambda s: s
LANGUAGES = (
('fr', ugettext('French')),
('en', ugettext('English')),
('de', ugettext('German')),
)

# Development configuration.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--verbose',
'--nocapture',
'--rednose',
'--with-id', # allows --failed which only reruns failed tests
'--id-file=%s' % join(data_dir, 'test', 'noseids'),
'--with-doctest',
'--with-xunit',
'--xunit-file=%s' % join(data_dir, 'test', 'nosetests.xml'),
'--with-coverage',
'--cover-erase',
'--cover-package=demoproject,i18nurl',
'--no-path-adjustment',
'--all-modules',
]
Empty file.
14 changes: 14 additions & 0 deletions demo/demoproject/templates/colors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>django-chartjs colors demo</title>
</head>
<body>
<h1>Here is a list of colors generated for each dataset!</h1>

{% for color in colors %}
<div style="display: inline-block; width: 100px; height: 100px; background: rgb({{ color.0 }}, {{ color.1 }}, {{ color.2 }});"></div>
{% cycle '' '' '' '' '' '' '' '' '' '<hr style="clear: both;"/>' %}
{% endfor %}

</body>
</html>
24 changes: 24 additions & 0 deletions demo/demoproject/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load i18n i18nurl %}
<html>
<head>
<title>django-i18nurl demo</title>
</head>
<body>
<h1>{% trans "Welcome to django-i18nurl demo!" %}</h1>
<p>{% trans "Here are some demo links. Browse the code to see how they are implemented" %}</p>

<h2>{% trans "Using current_i18nurl" %}</h2>
<ul>
<li><a href="{% current_i18nurl 'fr' %}">Français</a></li>
<li><a href="{% current_i18nurl 'en' %}">English</a></li>
<li><a href="{% current_i18nurl 'de' %}">Deutsch</a></li>
</ul>

<h2>{% trans "Using i18nurl" %}</h2>
<ul>
<li><a href="{% i18nurl 'home' 'fr' %}">Français</a></li>
<li><a href="{% i18nurl 'home' 'en' %}">English</a></li>
<li><a href="{% i18nurl 'home' 'de' %}">Deutsch</a></li>
</ul>
</body>
</html>
Loading

0 comments on commit 8eb4ea4

Please sign in to comment.