Week 7: Django - Part 2
Wherein we extend Django's built-in features
image: http://djangopony.com/
Questions from the Reading?
A reminder of our task for today:
Extend a basic micro-blog application with one of the following features:
- User Registration
- 'Archive' views based on date or author
- WYSIWYG visual editor for entry posts.
- Tagging
- Theme (make it beautiful)
Team 1:
Leader: Jon B
Members: Tyler, Matt K, John C, Wilson, Divesh
Your Task: User Registration with django-registration
Team 2:
Leader: Matt O
Members: David, Pho, Phil, Chris
Your Task: Archive Views using Generic date-based views
Team 3:
Leader: Austin
Members: Edet, Eric, Allan
Your Task: Content Tagging with django-taggit
Team 4:
Leader: Jason
Members: Daniel, Conor, Maria
Your Task: WYSIWYG Editing with django-ckeditor
Each team can work from a single core repository.
Break the job into discreet tasks.
Work in twos or threes, each small group take a task and complete it.
Create a local branch. Complete your task then merge.
Team leaders manage communications, keep an eye on the big picture.
Get a 'core' repository (perhaps leaders fork mine):
https://github.com/cewing/training.django_microblog
Add your teammates as collaborators:
- In your browser, view the repo you'll be working from in github.
- Click on the 'settings' tab (in the grey bar below the repo name)
- Click on the 'collaborators' menu item on the left
- Add your teammates by github id to the list of collaborators
Now you should all have read-write access to this core repo.
Each small group, pick a driver
Each driver, clone the core repo to your local machine
Pick a task. Before you start to work, make a local branch:
$ git checkout -b <task_name>
Complete your task, making commits as you go (you're on a branch)
When you're finished with a task, you'll merge your branch:
$ git branch master * <task_name> $ git checkout master Switched to branch 'master' $ git pull origin master From ... * branch master -> FETCH_HEAD Already up-to-date. $ git merge <task_name> $ git push origin master
Rinse and repeat
Leaders, make a copy of the core repository on your machine
When your team is done, set up your machine to show off your results
At 8:30 we'll come together. Each team will have 5 minutes to show a quick demo of their work, and say something about what they learned along the way.
Any Questions?
begin
A Few useful git commands:
$ git clone <repo_url> # make a clone $ git checkout -b <branch_name> # make a new local branch $ git checkout master # return to the master $ git branch # list branches (and show current) $ git commit -m "message" # make a commit locally $ git pull [origin [branch]] # pull recent changes from remote $ git push [origin [branch]] # push committed changes to remote $ git merge <branch_name> # merge changes from other to current
For this week, you have no code assignment.
Instead I want you to focus on installing software and reading for next week. Software we'll be installing uses C extensions, and so installing it on OS X or Linux requires a compiler and python's development headers.
There are a few steps here, so follow along carefully.
For Linux machines, we'll need to have gcc (a c compiler) and python's
development headers in order to complete our tasks. The VMs we have access to
already have gcc installed, so all we need there is:
::
$ sudo apt-get install python-dev
OS X does not come with a c compiler installed. You'll need to have XCode installed. It's free, but big expect it to take a while if you don't already have it.
Once it is installed, there's one more step, you have to install the 'optional' command line tools:
- Launch XCode
- From the XCode menu, click 'preferences' > 'Downloads' > 'Install Command Line Tools'
- Once it completes, you can quit XCode again.
There are pre-compiled binaries available for Windows, but we need one
.bat file in order to properly install them. We'll need to install Visual
Studio 2008 Express to get this file (if you already have another copy of VS,
you can probably skip this)
- Download the installer (894MB): http://download.microsoft.com/download/8/B/5/8B5804AD-4990-40D0-A6AA-CE894CBBB3DC/VS2008ExpressENUX1397868.iso
- Extract the files to a folder (call it VS2008ExpressENUX1397868—it will be 2.68GB) using something like 7zip
- Inside that folder double-click on Setup.hta
- On the screen that comes up, click on the installer for Visual C++ 2008 Express Edition and follow the instructions. Note: It does work if you include the following two options which are pre-selected for you: (1) MSDN Express Library for Visual Studio 2008, and (2) Microsoft SQL Server 2005 Express Edition (x86).
With that prep work out of the way, you're ready to start. First, set up a virtualenv:
$ python2.6 virtualenv.py --distribute pyramidenv ... $ source pyramidenv/bin/activate (pyramidenv)$
Remeber, Windows users: > pyramidenv\Scripts\activate
Once you've got a virtualenv set up and ready to go, install Pyramid:
(pyramidenv)$ easy_install pyramid
This will install a number of dependency packages, do not be alarmed.
Next, we'll install a different kind of Database, the ZODB.
If you're on OS X or Linux:
(pyramidenv)$ easy_install ZODB3==3.10.5
This will take some time. If you get errors, contact me directly or via the Google Group.
Windows users, you'll have it a bit easier here. You have to install a binary egg:
[pyramidenv]> pip install --egg ZODB3==3.10.5
At this point, you can check your work. Fire up a python interpreter in your virtualenv:
(pyramidenv)$ python >>> import ZODB >>> ^D (pyramidenv)$
If you get an ImportError when you try that, you're not done. Contact me.
Next, we'll need to finish installing the bits we need for our work next week:
(pyramidenv)$ easy_install docutils nose coverage ... (pyramidenv)$ easy_install pyramid_zodbconn pyramid_tm ... (pyramidenv)$ easy_install pyramid_debugtoolbar
These tools will allow us to manage ZODB connections, debug our app, and run cool tests.
And finally, we'll set up a project for ourselves. This is like running 'startproject' for django in a way:
(pyramidenv)$ pcreate -s zodb wikitutorial
Do not be alarmed by the 'sorry for the convenience' message.
You get a folder called wikitutorial. In it you should see files like
setup.py and development.ini among others.
This is an installable package. You can install this package with
easy_install.
In fact, let's do that now, so we can prove to ourselves this all worked:
(pyramidenv)$ cd wikitutorial (pyramidenv)$ python setup.py develop ...
You'll see a bunch of output. When it's over, run tests:
(pyramidenv)$ python setup.py test -q
When you've made it this far, and you see 1 test run successfully, you're done.
If you like, you can see your work by running the new project:
(pyramidenv)$ pserve development.ini Starting server in PID 3056. serving on http://0.0.0.0:6543
Visit http://localhost:6543 to see your work in action. then go grab a
beer and curl up with the reading for the week. There's a lot.
