Apr 26 2009

Arquivos do Mini curso de Django disponibilizados

Category: Djangovbmendes @ 23:04

No dia 24 de abril de 2009, no SENAC em Natal/RN, ocorreu o FLISOL. Neste evento, eu ministrei um mini curso de django. Então estou disponibilizando tanto os arquivos_mini_curso desenvolvido durante o curso, como os slides.

Tags: , ,


Apr 24 2009

Festival Latino-americano de Instalação de Software Livre

Category: Djangovbmendes @ 18:58

flisol

Venho através deste convidá-los ao FLISOL/RN 2009. O Festival Latino-americano de Instalação de Software Livre do RN irá acontecer no dia 25 de abril de 2009 no SENAC em Natal.

No evento eu irei ministrar um mini-curso introdutório ao framework Django das 14:00 as 17:00 horas, cujo objetivo é formar pessoas com conhecimentos básicos acerca do framework. O mini-curso irá abordar diversos conceitos do django através do desenvolvimento de um blog.

Maiores informações sobre o evento podem ser encontradas no site.

Tags: , ,


Mar 20 2009

Reffering to Django docs from your docs using Sphinx

Category: Djangovbmendes @ 12:25

Sphinx is a great documentation tool, and one of it’s built-in extensions is sphinx.ext.intersphinx. It simply takes your objects references for other projects and converts to links in the other project’s documentation.

In sphinx-quickstart command, it asks if you want to add this extension. If so, It adds this code to your conf.py file:

extensions = ['sphinx.ext.intersphinx']
intersphinx_mapping = {'http://docs.python.org/dev': None}

As you can see, it comes integrated with python documentation by default. But what I want is to integrate with Django documentation. So I changed the code a little bit:

extensions = ['sphinx.ext.intersphinx']
intersphinx_mapping = {
    'http://docs.python.org/dev': None,
    'http://docs.djangoproject.com/en/dev': 'http://docs.djangoproject.com/en/dev/_objects',
}

Sphinx looks for default for the file name objects.inv inside the documentation root, but django doesn’t provide such a file. Since ticket #10315 they provided a file like objects.inv but with a different URL: http://docs.djangoproject.com/en/dev/_objects/.

Now, all you have to do is reffer to classe or any kind of objects inside django: :class:django.contrib.auth.models.User. It will refference the User documentation inside django’s docs.

Tags: , , , ,


Mar 18 2009

Documenting Django pluggable apps with Sphinx

Category: Djangovbmendes @ 15:06

I decided to document my Django projects with the same tool used by Django team: Sphinx. It is a very good documenting tool, and was used for many other projects, including the Python Project itself.

But it has a simple problem with Django, that I found the solution rlazo’s blog. But it still has some problems, when you are trying to document a pluggable app, that doesn’t have a project, you have to configure the django settings without the project settings, since pluggable apps doesn’t have a settings module.

Thanks to apollo13, who shown me this better approach, you can simply add this code to sphinx’s conf.py file:

from django.conf import settings
settings.configure()

With this approach, you don’t need to add any kind of fake files in your project.

Tags: , , , ,


Feb 01 2009

MEDIA_URL and context from processors available in HTTP 500 template

Category: Djangovbmendes @ 22:43

It’s easy to create a custom template for HTTP 500 errors. All you have to do is create a file named 500.html in any of the application’s TEMPLATE_DIRS. But in almost all cases you want to use media in this page. It’s good to have an error page with the same look and feel of the system itself.

The default HTTP 500 handler in django uses Context instead of RequestContext. It means that none of your template context processors will be loaded, and the MEDIA_URL variable available in the template system comes exactly from one of these processors. So, without template context processors, we get no MEDIA_URL variable in templates.

Searching in google for a solution to this problem I found a snippet[1] that solves the MEDIA_URL problem. But it still doesn’t load the processors, all it does is pass the MEDIA_URL variable to the context for template. So I decided to make simple changes in it to load the processors. And here is the complete code:

def server_error(request, template_name='500.html'):
    from django.template import RequestContext
    from django.http import HttpResponseServerError
    t = loader.get_template(template_name)
    return HttpResponseServerError(t.render(RequestContext(request)))

Put this code in any views file you want and then define it as the handler500 in your urls.py:

handler500 = 'views.server_error'

[1] http://www.djangosnippets.org/snippets/1199/

Tags: , , ,


Jan 29 2009

Django ORM now supports fields references in filters

Category: Djangovbmendes @ 08:28

Today was added a new feature to django ORM. Now it supports references to fields in filters expressions. Just checkout the SVN version and enjoy it.

Before this update, queryset could be filtered only by absolute values.

queryset.filter(field='absolute value')

Will generate somthing like this:

SELECT * FROM table_name WHERE field = 'absolute value';

Now you can filter by another’s table field value.

queryset.filter(field=F('another_field'))

Will generate something like this:

SELECT * FROM table_name WHERE field = another_field;

The feature also supports arithmetical operations in the lookups so you can do filters where the views_number is twice as big as the comments_number.

queryset.filter(views_number__gt=F('comments_number')*2)

Will generate a SQL like this:

SELECT * FROM table_name WHERE views_number = comments_number*2;

It’s a very good feature. So, checkout the SVN version and take a look at docs/topics/db/queries.txt to know more about this.

Tags: , ,


Next Page »