'Web' Category

  • jQuery: Novice to Ninja — what I’ve found useful

    Июнь 26, 2010

    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 […]

  • Auto trimming field value / Django forms

    Июнь 7, 2010

    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}))

  • django registration form custom field

    Июнь 1, 2010

    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 […]

  • Draw an arrow on Google map

    Апрель 25, 2010

    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 = […]

  • check login decorator for json responses

    Март 21, 2010

    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 […]

  • add custom styles to yui datatable

    Март 16, 2010

    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 […]

  • Have ascii coding error in django admin?

    Март 10, 2010

    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!

  • django: Comments from authenticated users

    Январь 25, 2010

    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 […]

  • get_comment_list reversed

    Январь 23, 2010

    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 = […]

  • Make all markers visible

    Январь 3, 2010

    Следующий код позволяет настроить границы карты таким образом, чтобы необходимые маркеры были в зоне видимости: function makeRouteVisible(markers) { var bounds = new GLatLngBounds; for (var i = 0; i < markers.length; i++) { bounds.extend(markers[i].getLatLng()); } map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); }

Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org