Informatika Mihelac
January 27 2010 django | django-admin 0 comments

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

Posted on January 27th | 0 comments | Filed Under: | read on
November 12 2009 admin | django | i18n

Django set language for admin

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',
   ....
Posted on November 12th | 0 comments | Filed Under: | read on
November 10 2009 django | wsgi

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…

Posted on November 10th | 0 comments | Filed Under: | read on
October 23 2009 django auth

Django - avoiding typing password for superuser

When developing Django applications I call some kind of flush.py script innumerable times to recreate and sync database, import some data and create super user. It looks like:


#!/usr/bin/env bash
mysql -u root -e "DROP DATABASE secret_project_db;" 
mysql -u root -e "CREATE DATABASE secret_project_db CHARACTER SET='utf8';" 
./manage.py syncdb --noinput
./manage.py loaddata app/fixtures/*
./manage.py createsuperuser --username=admin --email=admin@example.com

It does the job quick but the thing that really annoy me is entering password and password confirmation each time over and over again. In looking for a quick way to reduce typing this is what I have now instead of last line in previous example:


echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', admin@example.com', 'pass')" | ./manage.py shell

Hope it will save you some typing too, if anyone has better idea then to call shell let me know in the comments.

Posted on October 23rd | 0 comments | Filed Under: | read on
September 15 2009 django | doctests | python | unicode

Use unicode in doctests

Use hex representation, double quote slashes in expectation. Do not use print in doctests .


""" 
>>> s = u"šđčćž" 
>>> s
u'\\xc5\\xa1\\xc4\\x91\\xc4\\x8d\\xc4\\x87\\xc5\\xbe'
""" 
Posted on September 15th | 0 comments | Filed Under: | read on

View archives for January 2010.

About

I am Bojan Mihelac and this blog is dedicated to share code, thoughts, tools and advices I came up with while working in Informatika Mihelac.

Contact: bmihelac AT mihelac.org
Twitter: /bmihelac

RSS feedSubscribe to RSS Feed