

I’m very happy with the progress I’ve made on the downloads application. Again, this is similar to the Web links application, so it was somewhat familiar ground. Web links was one of the earliest applications I wrote, so this time I tried to do some slightly different things just to compare and contrast. For Web links, I used a base template for all of the Web links related sub-pages. This was primarily so I could include custom CSS in one spot, and build the main Web links navigation and search form in one place. For downloads, I instead used a template tag for this navigation area. I think I like this a little better, as now my views don’t have to construct and send in a search form to the template. This is tucked away in one spot in my template tag now. I still have to include the CSS on every page, but I don’t consider that a big deal.
Even though I have upload functionality in a few other places, I still got bit by a few gotchas when dealing with uploaded files. First of all, you have to construct your <form> tag with an additional encoding type attribute:
<form action="." method="post" enctype="multipart/form-data">
And on the server side, when validating the received POST arguments and files, you must bind the uploaded files to the form:
f = MyForm(request.POST, request.FILES)
Even though I’ve done this before multiple times, and it is clearly documented in the Django docs, I forgot these steps which caused a few minutes of confusion. I guess I am getting cocky now.
The really fun thing I got working is an AJAX style rating system to let people rate downloads. So now I have something similar to the YouTube.com “star” rating system. My progress was aided by this excellent tutorial at progressive-coding.com. The tutorial shows the steps to write the system in vanilla Javascript, then shows how to integrate it with several Javascript frameworks at the end. Since I’m using jQuery, I took the ideas there and wrote the whole thing with jQuery in mind, resulting in smaller code. I’m glad I took the time to study the tutorial and fashion it into my own making, as I learned a great deal by doing it. I was really impressed, again, by how easy jQuery makes these things. I will likely go over what I came up with in greater detail in a future post.
Now that I have this rating system in place, I think I will add a feature to limit the number of votes you can make on an item. I’m thinking of allowing a user to vote on a download once a week. It is so easy to vote now, just by a single click, that I’m sure people would be tempted to vote multiple times. I may go add something like this to the polls application too.













