Recently I’ve read a book jQuery: Novice to Ninja. I was using jQuery for a long time, however I felt that I was using only a small part of this library, so I decided to read some books about it. The books is rather good and easy (and interesting) to read. Here I want to [...]
I don’t know why this is not done by default, but.. from django import forms class TrimmedCharField(forms.CharField): def clean(self, value): return forms.CharField.clean(self, value.strip()) class Form1(forms.Form): f1 = TrimmedCharField(widget=forms.Textarea(attrs={‘rows’: 6})) f2= TrimmedCharField(widget=forms.Textarea(attrs={‘rows’: 6}))
In most cases when a user registers in your django application you need to know more than just user name, password and e-mail. To add custom fields to the registration form you should pass form_class parameter to the register view function — it’s easy, but saving additional data could be rather complex. There are solutions [...]
I wrote a simple javascript function that draws an arrow on a Google Map (based on http://wtp2.appspot.com/BdccArrowedPolyline.js): function drawArrow(pt1, pt2, color) { var lineWidth = 10; var lineOpacity = 0.7; var arrowSize = 50; function addHead(point, theta, zoom, color) { var p = prj.fromLatLngToPixel(point, zoom) var x = p.x, y = p.y; var t = [...]
Django has a login_required decorator that redirects to the login page if user is not authenticated, here I’ll show how to write a custom decorator for json responses. If the uses is authenticated then decorated function returns the desired data otherwise some error in json format. NB — this decorator is for view functions with [...]
If you want to change styles of yui components — it’s easy. All you need is to make some overriding in your css files. My example looks like this: As you can see, I don’t want most borders and gradient backgrounds. This is done via the following style overriding: .yui-skin-sam .yui-dt th { border-right: 0px [...]
If you have some unicode data in tables e.g. some Russian names and want them to be displayed by default you need to do some trick: class SomeTable(models.Model): name = models.CharField(max_length=def_max_length) def __unicode__(self): return «%s» % self.name See that — instead of returning self.name directly I returned «%s» % self.name and admin panel is shining!
Selenium is great unless it deals with sites that require windows authorization — annoying dialog appears waiting for credentials. The pattern http://user:password@site.com does not work. Here I’ll show the possible workaround for making FireFox skip this dialog. This post is based on http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/ and http://codebetter.com/blogs/eric.wise/archive/2006/11/16/Note-to-self_3A00_-Firefox-Windows-Authentication.aspx articles.
Djano has a beautiful application — django.contrib.comments. And what is even more beautiful that it is customizable! So I’ll describe how to customize it so that only authenticated users are able to leave comments and comments must contain some rating — I will call such comments reviews. First, create an overridden comments application in a [...]
Django has comments application and it works fine for me, except that I need comments in the reversed order. I could have used reversed order in the {% for %} tag, but this doesn’t work with pagination as pagination wants already prepared list. So I wrote a separate filter: from django.template import Library register = [...]