Archive for the ‘frameworks’ Category.

Another simple but useful Django trick

Say you need the full URL of the current page you're displaying that you need to use on the template of that page, for example, to add links to Facebook, Delicious, etc., and you don't want to have additional JavaScript that you didn't write on your pages. (Why yes, I'm a control freak, shush. :P) Also say that you don't want to use the sites framework to hack it together. The permalink decorator won't work, either, because that just gives you the relative link.

Thankfully, there's a new request object that's been added to 1.0 that will do it.

To use it, include the bolded bit in your views.py file, as part of each view where you want to have the variable available:

return render_to_response('dir/template.html', {'object': obj, 'link': request.build_absolute_uri()}, RequestContext(request))

Then you can use the link variable on the template where you need the URL:

<a href="http://www.facebook.com/sharer.php?u={{ link|urlencode }}&t={{ title|urlencode }}">

I have yet to figure out how to get it to work with generic views, so feel free to holler if you know how. *vbg*

Django snippet — Template tag: split list to n sublists

This is the code for a Django template tag I adapted (also posted here). It was based on this snippet, adapted to split a list into n number of sublists, e.g. split a list of results into three evenly-divided sublists to enable display of the results in three columns on one page with CSS.
Continue reading 'Django snippet — Template tag: split list to n sublists' »

Arrrrrrrrrrrgh.

I like CodeIgniter so far (I've been fiddling with it on and off for a bit), but I've run into an issue that is driving me insane, so if anyone sees a typo that's causing the issue, I'd appreciate it if you'd let me know. *g*

I posted about the issue on the CI forums this afternoon, so all the relevant code's over there.

The gist of the problem is this: I'm using the same form for both adding a record and editing it. The model, view and controller work fine for the form when adding a new record cheap viagra. They also work fine when I submit the edited information. However, where it doesn't work is when I initially load the record to be edited by grabbing the data from the database and then filling the fields on form. Text and textarea inputs get filled in just fine, but radio and checkboxes do not get checked to match their stored values. *sigh*

Any ideas out there?

Installing symfony on Dreamhost using PEAR

I tried to get all of the commands put down in this how-to, so that people of all skill levels could follow the instructions. Be sure to let me know if I missed any or something needs clarified. :) But as usual, use at your own risk, yadda, yadda. Continue reading 'Installing symfony on Dreamhost using PEAR' »