Table of Contents
Django Site Development
- RemoteDjangoSiteDevelopment - SVN repository info etc.
The new Django site code creates two types of site administrators where before there was only one:
- People updating Meetings, Announcements, Page content
2. People adding new features to the site
The former group can now do everything they need to do through the admin interface built in to the site at: http://oclug.on.ca/admin/
The latter group needs a way to work on the code collaboratively, test changes and update the database schema when the changes are deployed.
Django documentation
Django has very good online documentation. The tutorial is a good place to start. Some other useful references:
File layout
Shortcuts to some of the files available from the “browse source” button above.
file | description |
__init__.py | allows directory to be imported as a module (python idiom) |
local_settings.py | database and secret key settings NOT IN SUBVERSION |
settings.py | global settings for the project |
urls.py | static mappings for URLs to views and templates |
sandbox_settings.py | overrides for sandbox site |
staging_settings.py | overrides for staging site |
manage.py | django utility script for managing the project |
dump.sh | script to dump all the non-sensitive data from the db as xml |
docroot | apache document root |
docroot:favicon.ico | special case fall-through for “favorites icon” |
docroot:media: | all requests to oclug.on.ca/media/ are served from this directory (apache config) |
docroot:media:admin | symlink to django's admin site media directory (for icons, etc.) |
docroot:media:uploaded | symlink to site_data/uploaded directory (for files and images uploaded to admin site) |
docroot:media:oclug.css | CSS for site |
docroot:media:oclug.png | site logo |
meetings | custom OCLUG meetings application |
meetings:models.py | meetings models, database field types and admin site customization |
meetings:views.py | custom view functions for meetings application |
meetings:feeds.py | RSS feed classes for meetings |
meetings:templatetags | extension code for templates |
meetings:templatetags:meetings_image.py | templatetag for uploaded images (to include size, title, alt, etc.) |
templates | templates that generate site HTML |
templates:base_generic.html | common site look, with logo, navigation bar and boxes |
templates:404.html | 404 (not found) page |
templates:500.html | 500 (server error) page |
templates:meetings | templates for meetings application |
templates:meetings:upcoming.html | page for upcoming meetings and announcements |
templates:meetings:past.html | page past meetings |
templates:meetings:meeting_detail.html | page for an individual meeting |
templates:meetings:location_detail.html | page for a meeting location |
templates:meetings:speaker_detail.html | page for a speaker |
templates:meetings:image_detail.html | page for single-image view |
templates:meetings:meeting_brief.html | a one-line view of a meeting (page fragment) |
templates:meetings:meeting_info.html | a detailed view of a meeting (page fragment) |
templates:admin | overrides for admin site templates |
templates:admin:base_site.html | modified version that includes a link to markdown reference |
templates:feeds | RSS feed templates |
templates:feeds:upcoming_description.html | meeting description (currently blank) |
templates:feeds:upcoming_title.html | meeting title |
templates:flatpages | flatpages application templates |
templates:flatpages:default.html | flatpage layout |
Template dependencies
#!rst +-----------------------------+-----------------------------+------------------------------+ |"extends" |page template |"includes" | +=============================+=============================+==============================+ |base_generic.html |meetings/upcoming.html |meetings/meeting_info.html | + +-----------------------------+ + | |meetings/meeting_detail.html | | + +-----------------------------+------------------------------+ | |meetings/past.html |meetings/meeting_brief.html | + +-----------------------------+ + | |meetings/speaker_detail.html | | + +-----------------------------+ + | |meetings/location_detail.html| | + +-----------------------------+------------------------------+ | |meetings/image_detail.html | | + +-----------------------------+ + | |flatpages/default.html | | + +-----------------------------+ + | |400.html | | + +-----------------------------+ + | |500.html | | +-----------------------------+-----------------------------+------------------------------+
Applications installed
#!rst ============================= ================================================================= application description ----------------------------- ----------------------------------------------------------------- django.contrib.auth users, groups and permissions django.contrib.contenttypes django.contrib.sessions session tracking (required by auth) django.contrib.sites multiple site support (required by flatpages) django.contrib.admin administration interface http://oclug.on.ca/admin/ django.contrib.markup markup template tags, used for markdown formatted text django.contrib.flatpages database-backed pages, used for http://oclug.on.ca/about/, etc. django.contrib.redirects database-backed redirection, used to fix .php urls mostly meetings custom OCLUG meetings application ============================= =================================================================
Sites and directories
http://oclug.on.ca
Main OCLUG site
#!rst ==================== ================================== ============================================================= code location /home/webdude/oclug_django_site/ "push_staging_to_production" script used to copy from staging settings file settings.py data location /home/webdude/site_data/ checked in to SVN: /site_data/trunk/ upload location /var/local/main_site_uploaded/ owned by www-data, file and image uploads go here database Postgres: "oclug_django_site" serialized database /home/webdude/site_data/db.xml "serialize_db_and_checkin" script called nightly ==================== ================================== =============================================================
http://staging.oclug.on.ca
Site for testing new code and db columns/tables
#!rst ==================== ======================================== ============================================================= code location /home/webdude/staging/oclug_django_site/ "update_staging" script used to update from SVN settings file staging_settings.py data location /home/webdude/site_data/ shared with main site upload location /var/local/main_site_uploaded/ shared with main site database Postgres: "oclug_django_site" shared with main site serialized database none data not serialized ==================== ======================================== =============================================================
http://sandbox.oclug.on.ca
Site for testing changes made by admin interface
#!rst ==================== ======================================== ============================================================= code location /home/webdude/sandbox/oclug_django_site/ copied from main site by "reset_sandbox" script settings file sandbox_settings.py data location /home/webdude/sandbox/site_data/ copied from main site by "reset_sandbox" script upload location /var/local/sandbox_site_uploaded/ copied from main site by "reset_sandbox" script database Postgres: "oclug_django_sandbox_site" reloaded from main site by "reset_sandbox" script serialized database none data not serialized ==================== ======================================== =============================================================
main and staging sites share database and upload directory so that common changes (adding columns to a table and creating new models) can be tested with the live data. When there are new columns or tables the main site will ignore them.
Scripts
This is a list of the maintenance script locations and what they do.
nightly
/home/webdude/bin/nightly (run from crontab daily at 4am)
- call serialize_db_and_commit
2. call reset_sandbox
serialize_db_and_commit
/home/webdude/bin/serialize_db_and_commit (called by nightly script)
- dump the database, except sessions and user auth info, into the serialized database location
2. rsync uploads into site data dir
3. check in everything in site data dir to SVN. This will cause changes to be emailed out like other SVN commits, and everyone on the oclug-www list will be able to see what has changed on the site.
reset_sandbox
/usr/local/bin/reset_sandbox → /home/webdude/bin/reset_sandbox (called by nightly script)
- rsync oclug_django_site and site_data from main site to sandbox (see /root/bin/rsync_oclug_sandbox)
2. dump site database into sandbox database
3. restart apache
update_staging
/usr/local/bin/update_staging → /home/webdude/bin/update_staging
- “svn update” staging oclug_django_site dir
2. “manage.py validate && manage.py syncdb” if any errors, stop and notify user
3. restart apache
push_staging_to_production
/usr/local/bin/push_staging_to_production → /home/webdude/bin/push_staging_to_production
- rsync oclug_django_site from staging
2. restart apache
Open issues
How do we accommodate changes to the database layout (other than new tables that are handled by “manage.py syncdb”?
- new columns can be dealt with by manually entering “ALTER TABLE” commands (not as hard as it sounds, can use “manage.py sql …” to show the sql that would be used to create the table and just copy&paste the column into “psql”)
- need to investigate serialize/flush/syncdb/reload as a possible option (maybe not, some things shouldn't be made too simple)
Resolved issues
- need to figure out why subversion notifications aren't being sent - logfile20070626
- install Trac for issue tracking and development - logfile20070712 logfile20070717