Yawd website

Articles From August 2011

  1. Using class-based views to process a django form through ajax

    Field-specific errors with the JSONFormView class-based view Since Django 1.3 class-based views have been introduced to allow for code reusability. Class-based views have been criticized for their poor documentation (count me in) and their amazing ability to grow our code size instead of reducing it! The latter appears to be true only if we are not careful with sub-classing. On the other hand class-based views finally deliver django what has been missing: a consistent way of coding all your models, forms and views.
    Unfortunately, django's generic class-based views do not provide a mechanism for implementing JSON views. Ajax requests are the standard way of doing things these days and I feel that django needs some work towards this direction. However, the official documentation offers the implementation of a simple JSONResponseMixin that we will use as a base for our own view. What we try to achieve here is create a view that will process a form, return the errors when the form is not valid or save the form and return a success message otherwise. This is a fairly common scenario and extremely useful when a full page reload is not acceptable (e.g. a newsletter subscription form).
    Posted on August 30th, 2011 by Pantelis Petridis
  2. Allow for lazy dynamic choices in django's model fields

    Here's a quick how-to for those that need to dynamically generate model field choices with django. Normally we would define a CharField as follows, where choices should be a tuple containing static choices.

    Posted on August 16th, 2011 by Pantelis Petridis
  3. Migrate to Keystone 5

    If you want to upgrade your old Keystone TKL digital library and exploit the fast performance that Keystone 5 offers, here's what you most likely need to change. Please note that since PHP5 differs significantly over PHP4, you should also modify your custom PHP code, especially if it involves XML/DOM manipulation to work with PHP5.

    Posted on August 5th, 2011 by Pantelis Petridis