Mar 07

Announcing FeinCMS Extensions

FeinCMS is great content management system for Django. FeinCMS Extensions is repository of tools and modules that I wrote and find can be of use to other developers.

Visit: http://github.com/bmihelac/feincms-feincmsext

Feb 19

Django time widget with custom time shortcuts

How to customize Django admin time widget to set desired time shortcuts.

This small javascript snippet replaces standard django clock shortcuts Midnight, Noon, Now & 6am with various time increments .

$(window).load(function() {
  $('.timelist').each(function(num, el) {
    time_format = get_format('TIME_INPUT_FORMATS')[0];
    $(el).html('');
    for (i=8; i<20; i++) {
      var time = new Date(1970,1,1,i,0,0);
      lnk = "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + 
                  ", '" + time.strftime(time_format) + "');"
      $(el).append('<li><a href="'lnk'">' + time.strftime('%H:%M') + '</a></li>');
    }
  });
});

This snippet use JQuery which is available with Django 1.2. (dev at time of writing)
Also, javascript should be loaded after DateTimeShortcuts.js but unfortunately I didn’t find a better way to achive this but to add in modified base admin site templates/admin/base_site.html. If you have any suggestion for improvement, let me know in comments.

Jan 27

Django-simpleadmindoc

Simpleadmindoc is django application that allows you to quickly create help for modules in Django admin. Goal is to be flexible enough, fast to create and easy to integrate.

I started this project as I needed to deliver help and documentation for django-admin on client website and admindocs seems more oriented to developers than to users.

http://github.com/bmihelac/django-simpleadmindoc

Nov 12

Django set language for admin

Middleware that intialize specific locale for admin pages.

If you want to explicitly set language for django admin section use this middleware:

from django.conf import settings

class AdminLocaleURLMiddleware:

    def process_request(self, request):
        if request.path.startswith('/admin'):
            request.LANG = getattr(settings, 'ADMIN_LANGUAGE_CODE', settings.LANGUAGE_CODE)
            translation.activate(request.LANG)
            request.LANGUAGE_CODE = request.LANG

Then put somewhere in settings.py:

ADMIN_LANGUAGE_CODE=’it’

and add middleware:

MIDDLEWARE_CLASSES = (
   ...
    'utils.multilang.middleware.AdminLocaleURLMiddleware',
   ....
Nov 10

Can't connect to MySQL when touching django.wsgi

Error when touching django.wsgi: Can’t connect to MySQL server…

did not help unless restarted apache.

Solution that did work is to set DATABASE_PORT to ‘3306’ instead of empty string. Not sure why…