[[:[PageOutline]]]
====== 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 ======
[[http://www.djangoproject.com/|Django]] has very good
[[http://www.djangoproject.com/documentation/|online documentation]].
The [[http://www.djangoproject.com/documentation/tutorial01/|tutorial]]
is a good place to start. Some other useful references:
* [[http://www.djangoproject.com/documentation/model-api/|Models]]
* [[http://www.djangoproject.com/documentation/url_dispatch/|URLs]]
* [[http://www.djangoproject.com/documentation/templates/|Templates]]
====== File layout ======
Shortcuts to some of the files available from the "browse source" button above.
| **file** | **description** |
| [[:source:oclug_django_site:trunk:__init__.py|__init__.py]] | allows directory to be imported as a module (python idiom) |
| local_settings.py | database and secret key settings NOT IN SUBVERSION |
| [[:source:oclug_django_site:trunk:settings.py|settings.py]] | global settings for the project |
| [[:source:oclug_django_site:trunk:urls.py|urls.py]] | static mappings for URLs to views and templates |
| [[:source:oclug_django_site:trunk:sandbox_settings.py|sandbox_settings.py]] | overrides for sandbox site |
| [[:source:oclug_django_site:trunk:staging_settings.py|staging_settings.py]] | overrides for staging site |
| [[:source:oclug_django_site:trunk:manage.py|manage.py]] | django utility script for managing the project |
| [[:source:oclug_django_site:trunk:dump.sh|dump.sh]] | script to dump all the non-sensitive data from the db as xml |
| [[:source:oclug_django_site:trunk:docroot|docroot]] | **apache document root** |
| [[:source:oclug_django_site:trunk:docroot:favicon.ico|docroot:favicon.ico]] | special case fall-through for "favorites icon" |
| [[:source:oclug_django_site:trunk:docroot:media:|docroot:media:]] | all requests to oclug.on.ca/media/ are served from this directory (apache config) |
| [[:source:oclug_django_site:trunk:docroot:media:admin|docroot:media:admin]] | symlink to django's admin site media directory (for icons, etc.) |
| [[:source:oclug_django_site:trunk:docroot:media:uploaded|docroot:media:uploaded]] | symlink to site_data/uploaded directory (for files and images uploaded to admin site) |
| [[:source:oclug_django_site:trunk:docroot:media:oclug.css|docroot:media:oclug.css]] | CSS for site |
| [[:source:oclug_django_site:trunk:docroot:media:oclug.png|docroot:media:oclug.png]] | site logo |
| [[:source:oclug_django_site:trunk:meetings|meetings]] | **custom OCLUG meetings application** |
| [[:source:oclug_django_site:trunk:meetings:models.py|meetings:models.py]] | meetings models, database field types and admin site customization |
| [[:source:oclug_django_site:trunk:meetings:views.py|meetings:views.py]] | custom view functions for meetings application |
| [[:source:oclug_django_site:trunk:meetings:feeds.py|meetings:feeds.py]] | RSS feed classes for meetings |
| [[:source:oclug_django_site:trunk:meetings:templatetags|meetings:templatetags]] | extension code for templates |
| [[:source:oclug_django_site:trunk:meetings:templatetags:meetings_image.py|meetings:templatetags:meetings_image.py]] | templatetag for uploaded images (to include size, title, alt, etc.) |
| [[:source:oclug_django_site:trunk:templates|templates]] | **templates that generate site HTML** |
| [[:source:oclug_django_site:trunk:templates:base_generic.html|templates:base_generic.html]] | common site look, with logo, navigation bar and boxes |
| [[:source:oclug_django_site:trunk:templates:404.html|templates:404.html]] | 404 (not found) page |
| [[:source:oclug_django_site:trunk:templates:500.html|templates:500.html]] | 500 (server error) page |
| [[:source:oclug_django_site:trunk:templates:meetings|templates:meetings]] | **templates for meetings application** |
| [[:source:oclug_django_site:trunk:templates:meetings:upcoming.html|templates:meetings:upcoming.html]] | page for upcoming meetings and announcements |
| [[:source:oclug_django_site:trunk:templates:meetings:past.html|templates:meetings:past.html]] | page past meetings |
| [[:source:oclug_django_site:trunk:templates:meetings:meeting_detail.html|templates:meetings:meeting_detail.html]] | page for an individual meeting |
| [[:source:oclug_django_site:trunk:templates:meetings:location_detail.html|templates:meetings:location_detail.html]]| page for a meeting location |
| [[:source:oclug_django_site:trunk:templates:meetings:speaker_detail.html|templates:meetings:speaker_detail.html]] | page for a speaker |
| [[:source:oclug_django_site:trunk:templates:meetings:image_detail.html|templates:meetings:image_detail.html]] | page for single-image view |
| [[:source:oclug_django_site:trunk:templates:meetings:meeting_brief.html|templates:meetings:meeting_brief.html]] | a one-line view of a meeting (page fragment) |
| [[:source:oclug_django_site:trunk:templates:meetings:meeting_info.html|templates:meetings:meeting_info.html]] | a detailed view of a meeting (page fragment) |
| [[:source:oclug_django_site:trunk:templates:admin|templates:admin]] | **overrides for admin site templates** |
| [[:source:oclug_django_site:trunk:templates:admin:base_site.html|templates:admin:base_site.html]] | modified version that includes a link to markdown reference |
| [[:source:oclug_django_site:trunk:templates:feeds|templates:feeds]] | **RSS feed templates** |
| [[:source:oclug_django_site:trunk:templates:feeds:upcoming_description.html|templates:feeds:upcoming_description.html]] | meeting description (currently blank) |
| [[:source:oclug_django_site:trunk:templates:feeds:upcoming_title.html|templates:feeds:upcoming_title.html]] | meeting title |
| [[:source:oclug_django_site:trunk:templates:flatpages|templates:flatpages]] | **flatpages application templates** |
| [[:source:oclug_django_site:trunk:templates:flatpages:default.html|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]]