Skip to main content

Basic user interface for lizard websites

Project description

lizard-ui

Lizard-ui provides a basic Django user interface, so a base Django template and some css + javascript. We designed it at Nelen & Schuurmans for our geographical information websites (with water management information).

Choices, requirements, assumptions

Lizard-ui is opinionated: it makes choices and prescribes (good!) technologies.

  • Included: the blueprint css framework. It resets css styles so that we’ve got a common base. It fixes common IE layout bugs. It gives a basic typography that’s quite pleasing.

  • Required: django-staticfiles. For a more verbose description, see Reinout’s blog entry (written with lizard-ui in mind).

  • Required: django_compressor for combining css/javascript files in production.

  • Assumption: one screen, using the full width/height of the browser, without scrolling. Our main goal is showing a nice big map with a small header and a sidebar. You don’t want to scroll a map. It is of course possible to have a scrollbar inside that main content area itself.

  • Assumption: javascript is available. Hey, we’re showing a map so you need javascript. So we liberally use javascript to get the UI right, for instance by detecting and setting the main content area’s width and height.

  • Included: jquery. Yeah, it is pretty much the standard nowadays. So we use jquery where jquery can be used instead of doing it with generic javascript.

  • Included: both jqueryui and jquerytools. Visual goodies. Jquerytools for the overlay and tabs, jqueryui for the rest (drag/drop and so).

  • Included: openlayers as map javascript library. (Lizard-map, sooooon to be released, contains our basic map interaction javascript and python code).

License + licenses

Our own license is GPLv3.

Lizard-ui ships with a couple of external css/javascript libraries.

Blueprint

Modified MIT

Jquery and jqueryui

Dual licensed under the MIT or GPL Version 2 licenses. Includes Sizzle.js, released under the MIT, BSD, and GPL Licenses.

Jquerytools

No copyrights or licenses. Do what you like.

Openlayers

Clear BSD license.

Famfamfam icon set

CC attribution license.

Treeview jquery plugin

MIT/GPL

Django settings

Here’s an excerpt of a settings.py you can use. The media and static root directory setup assumes the use of buildout, but you can translate it to your own filesystem setup:

INSTALLED_APPS = [
    'lizard_ui',
    'compressor',
    'staticfiles',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    ]

# Note: the below settings are more elaborate than needed,
# but we want to test django_compressor's compressing which
# needs a media url and root and so.

# Set COMPRESS to True if you want to test compression when
# DEBUG == True.  (By default, COMPRESS is the opposite of
# DEBUG).
COMPRESS = False

# SETTINGS_DIR allows media paths and so to be relative to
# this settings file instead of hardcoded to
# c:\only\on\my\computer.
SETTINGS_DIR = os.path.dirname(os.path.realpath(__file__))

# BUILDOUT_DIR is for access to the "surrounding" buildout,
# for instance for BUILDOUT_DIR/var/static files to give
# django-staticfiles a proper place to place all collected
# static files.
BUILDOUT_DIR = os.path.abspath(os.path.join(SETTINGS_DIR, '..'))

# Absolute path to the directory that holds user-uploaded
# media.
MEDIA_ROOT = os.path.join(BUILDOUT_DIR, 'var', 'media')
# Absolute path to the directory where django-staticfiles'
# "bin/django build_static" places all collected static
# files from all applications' /media directory.
STATIC_ROOT = os.path.join(BUILDOUT_DIR, 'var', 'static')

# URL that handles the media served from MEDIA_ROOT. Make
# sure to use a trailing slash if there is a path component
# (optional in other cases).
MEDIA_URL = '/media/'
# URL for the per-application /media static files collected
# by django-staticfiles.  Use it in templates like "{{
# MEDIA_URL }}mypackage/my.css".
STATIC_URL = '/static_media/'
# URL prefix for admin media -- CSS, JavaScript and
# images. Make sure to use a trailing slash.  Uses
# STATIC_URL as django-staticfiles nicely collects admin's
# static media into STATIC_ROOT/admin.
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

# Storage engine to be used during compression
COMPRESS_STORAGE = "staticfiles.storage.StaticFileStorage"
# The URL that linked media will be read from and compressed
# media will be written to.
COMPRESS_URL = STATIC_URL
# The absolute file path that linked media will be read from
# and compressed media will be written to.
COMPRESS_ROOT = STATIC_ROOT


# Used for django-staticfiles
TEMPLATE_CONTEXT_PROCESSORS = (
    # Default items.
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    # Needs to be added for django-staticfiles to allow you
    # to use {{ STATIC_URL }}myapp/my.css in your templates.
    'staticfiles.context_processors.static_url',
    )

And a suitable apache config hint:

<Location /static_media/>
  # The css/javascript/image staticfiles are cached in the
  # browser for a day.
  ExpiresActive On
  ExpiresDefault "access plus 1 day"
</Location>

<Location /static_media/CACHE/>
  # django_compress's generated timestamp'ed files:
  # cache forever
  ExpiresActive On
  ExpiresDefault "access plus 10 years"
</Location>

# Static files are hosted by apache itself.
# User-uploaded media: MEDIA_URL = '/media/'
Alias /media/ ${buildout:directory}/var/media/
# django-staticfiles: STATIC_URL = '/static_media/'
Alias /static_media/ ${buildout:directory}/var/static/

Usage

You can mount lizard-ui’s urls, but it contains only live examples. So perhaps you should only mount it in debug mode under /ui. Handy, as it contains reasonably full documentation on how to use it, including available blocks and classes/IDs that you can use.

The base layout is defined in realbase.html. You should however extend lizard_ui/lizardbase.html and then override the blocks that you want.

CSS and javascript should be added to the relevant blocks, but don’t forget to call “block.super”. An example:

{% extends "lizard_ui/lizardbase.html" %}

{% block css %}
{{ block.super }}
<link type="text/css"
      href="{{ STATIC_URL }}lizard_map/lizard_map.css"
      media="screen, projection"
      rel="stylesheet" />
{% endblock css %}

{% block javascript %}
{{ block.super }}
<script type="text/javascript"
        src="{{ STATIC_URL }}openlayers/OpenLayers.js"></script>
<script type="text/javascript"
        src="{{ STATIC_URL }}lizard_map/jquery.workspace.js"></script>
<script type="text/javascript"
        src="{{ STATIC_URL }}lizard_map/lizard_map.js"></script>
{% endblock javascript %}

{% block content %}
<div id="map"></div>
{% endblock content %}

A example of a common task: change the logo. For that, make a media/lizard_ui directory in your django application (or site) and place a logo.png in it. Django-staticfiles’ mechanism will take your logo.png in preference to lizard-ui’s.

Development installation

The first time, you’ll have to run the “bootstrap” script to set up setuptools and buildout:

$> python bootstrap.py

And then run buildout to set everything up:

$> bin/buildout

(On windows it is called bin\buildout.exe).

You’ll have to re-run buildout when you or someone else made a change in setup.py or buildout.cfg.

The current package is installed as a “development package”, so changes in .py files are automatically available (just like with python setup.py develop).

If you want to use trunk checkouts of other packages (instead of released versions), add them as an “svn external” in the local_checkouts/ directory and add them to the develop = list in buildout.cfg.

Tests can always be run with bin/test or bin\test.exe.

TODO

  • Document all of the available classes/IDs that you can use to get automatic (javascript) behaviour.

  • Document the javascript code.

  • Strip out some/most of the applications in the testsettings.py as they’re not really needed.

  • Add basic test that the example.html renders without errors.

  • Add tests for the javascript code.

  • Add mechanism for rendering a passed-in (or registered/configured) list of object_tabs and object_actions, including some nice formatting.

  • Add mechanism for breadcrumbs.

Credits

  • TODO started this library

Changelog of lizard-ui

1.4.1 (2010-06-25)

  • Updated TODO list.

1.4 (2010-06-25)

1.3 (2010-06-23)

  • Added graph reloading on sidebar collapse/expand.

  • UI css fixes (overflow:hidden in a couple of places to prevent scrollbars in corner cases, for instance).

1.2 (2010-06-22)

  • Floating the main content area now and giving it the proper width with javascript. This makes the layout in IE more reliable.

  • The main body has “overflow: hidden” to get rid of scrollbars once and for all: scrollbars sometimes occur when there’s a small layout bug. A scrollbar takes up space, so the main content float is pushed down. We have an assumption of a single page without scrolling, so hiding scrollbars is perfectly fine. (The main area itself can have scrollbars for textual content).

1.1 (2010-06-18)

  • IE tweaks.

1.0 (2010-06-17)

  • Fixed javascript code with jslint.

  • Added django-compressor for javascript and css compression and combination. You’ll need to add the configuration in http://dpaste.de/xLDU/ to your settings and add “compressor” to your installed apps.

  • Switched to a separate “javascript” and “css” block instead of the site-head-extras, head-extras and so. Be sure to add {{super.block}} when you override the blocks.

0.12 (2010-06-11)

  • Upgraded to jqueryui 1.8.2 (from 1.8.1).

  • Removed jqueryui’s tab component as it conflicts with jquerytools’ implementation. Jquerytools’ implementation is way friendlier to our existing sidebar css.

0.11 (2010-06-08)

  • Added direct support for a jquery tree. We already contained the base treeview javascript, so lizard-ui was a logical place for setting it up.

0.10 (2010-06-07)

  • Added fillSidebar() alias for stretchOneSidebarBox().

  • Splitted title block in sitetitle/subtitle as that’s a common occurrence.

0.9 (2010-06-03)

  • Using jquery’s live() for “late binding” of events to elements added later through javascript. Saves some couple of lines.

0.8 (2010-06-01)

  • Added generic accordion handling for the sidebar. Including ajaxy loading.

0.7 (2010-05-18)

  • Added jquerytools for accordeon behaviour in sidebar.

  • Layout fixes, mostly for the sidebar. Also fix for the datepicker-placed div at the bottom.

  • Update to jquery-ui 1.8.1.

0.6 (2010-04-28)

  • Added collapsible sidebar.

  • Changed css framework from yui to blueprint: more understandable. The reason for yui was that it had a 100%-width layout. We’re now building up the layout (grid-wise) ourselves due to the collapsible sidebar, so switching back to blueprint is now possible.

  • Changed layout to match Dirk-Jan’s latest screenshots.

0.5 (2010-04-13)

  • Layout improvements.

  • Added documentation (just mount our urls!).

  • Removed separate icons, leaving only the sprite’d icons.

  • Added jqueryui. Including it automatically. It also means extjs isn’t included automatically anymore.

  • Sidebar width is 300px instead of 180px.

0.4 (2010-03-16)

  • Added extjs javascript library.

  • Added javascript and css for dividing the vertical space equally.

0.3.1 (2010-03-05)

  • Bugfix: removed sample breadcrumb content from the template.

0.3 (2010-03-05)

  • Added openlayers 2.8.

  • Added famfamfam silk icon set.

  • Added background to menubar, footer and body.

  • Removed blueprint and added the YUI css framework.

0.2 (2010-02-12)

  • Nested our templates in templates/lizard_ui instead of directly in templates. We’re well-behaved now!

0.1 (2010-02-12)

  • Added lizardbase.html template as base for a lizard user interface.

  • Added django-staticfiles as a dependency for managing css and javascript resources.

  • Added blueprint css framework.

  • Initial structure created by nensskel.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lizard-ui-1.4.1.tar.gz (835.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page