Archive

Archive for August 5th, 2008

Django: messaging

August 5th, 2008 3 comments

When completing something like deleting an item or adding a user, it’s usually nice to report a message to the user to let them know what just happened. I also find it useful to send the user somewhere they’d “want” to go. For example, if they just created a user, send them to the list of users page, so they see the change they just made.

I’m also a big advocate of keeping URLs clean.

Because of these concerns the best answer in Django is to do an HttpResponseRedirect. Now the problem with that is that you can’t pass data to a redirect. To get around this there are messages that you can send to the users session itself.

The mechanism isn’t that clean, but it does work, and it does do the job.

So if you have a buycbdproducts in user all you need to do to add messages is:
request.user.message_set.create(message='User successfully created.')

Now the flip side to the equation is that you “get” the message(s). So how this works is when you set a message you’re actually adding a message to a list. When you”get” the message, you’re actually getting the list (may be more than one message). And if you don’t “get” the message at the right time, the messages will just build up. But for the most part this system works just fine. To get the messages you just do:
messages = request.user.get_and_delete_messages()

Then just pass ‘messages’ to the view and show the list to the user.

Categories: Django Tags:

SVN import

August 5th, 2008 1 comment

Every once in a while I end up starting a project, and since it happens so infrequently I always forget the steps to set things up in subversion.

I won’t go through all the steps you need to start from scratch with subversion, but here’s the important part about adding a project to your repo.

svn import <path to project> file:///<path to svn root>/<project folder> -m "Initial import"


svn import /home/PROJ file:///home/svn/PROJ -m "Initial import"

import: This adds a directory tree to your

path to project: Actual path to directory tree where code sits

path to svn root: Path to repo

project folder: Name for project folder in svn

The one thing I’m not sure how to do right now is after I import the project. The folder with the code is not a subversion checkout. So what I usually end up doing is checking out the project and replacing the checked out version over my original code. Not sure if there’s a better way to do that…

Categories: Subversion Tags: