Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Lista de discussão Django Apps
O Michael Elsdörfer criou a lista de discussão Django Apps. A idéia é utilizar a lista para suas próprias aplicações Django e isso possui, no mínimo, duas grandes vantagens: Se faz desnecessário a criação de uma lista de discussão para cada nova aplicação; Existe uma potencial possibilidade de outras pessoas, não necessariamente usuárias de suas aplicações, participarem das discussões com ótimas opiniões. Eu não iria criar listas de discussões para minhas aplicações, uma vez que o número de discussões tenderia à zero e seria uma tarefa chata, mas, com isso, as aplicações Diário, Fleshin e Tube ganharam um local para discussão! Então, quando precisar, já sabe onde pode discutir algo a respeito das aplicações citadas acima. Já adicionei o grupo de discussão nas páginas dos meus projetos no Google Code. Utilize o prefixo [diario], [fleshin] e [tube] no assunto das mensagens, como descrito na página inicial do grupo: All messages should be prefixed with the application name in brackets. If the application name itself has the popular django prefix, it should be left off. E.g. use [tables] for django-tables. -
EuroPython 2008
I started writing this post at the airport just before flying back from Vilnius to Berlin. EuroPython 2008 - the three-days conference and sprints afterwards - gave me loads of information, new relations, and better understanding of the big image of Python developers' community.Some highlights from the conference follow.During video conference the author of Python programming language Guido van Rossum encouraged using Python 2.6 just after the release, but said that Python 3.0 still shouldn't be used for production. The good future-proof practices are inheriting from object for classes, using xrange(), sorted(), and zip() functions, "//" for floor divisions, and dict.iterkeys(). The full porting to 3.0 guide will be probably written and published in the python.org site.Clone Digger is a project from Google Summer of Code 2008 for finding similar pieces of code which could be optimized by moving that to parameterized functions.Restrictive Python is a project which blocks the user from executing dangerous functions or methods or accessing files which might harm the system. You can try Restrictive Python out in the simulated terminal.Python is an interpreted language and if you want to deploy a project writen in Python, you have to be sure that the end user will … -
Annoucning sPaste.com
Tonight I am officially launching my new side project, sPaste.com! sPaste is a simple tool to help you quickly and securely send small snippets of data around the web. As usual, the site is written entirely in Django on the server side and jQuery on the client side. At the moment it is little more [...] -
A simple site-wide, per-user, date format validation system
It is important to be aware that dates are spelled differently in different countries (e.g. dd/mm/yyyy in Australia or mm/dd/yyyy in the US). This is why it is a good idea to let the user select their preferred date format and store it into their user profile. For example, you may store the values "%d/%m/%Y" or "%m/%d/%Y" in that user’s profile. That way, you may display dates in the format chosen by the user throughout the site. Now, if the site contains many forms with date fields (say, for example, you’re building a calendar application), it can be a bit repetitive and annoying to check and assign the date format for every form in every view. To go around that, I came up with a simple trick. It all happens in the following class: class FormWithFormattedDates(forms.ModelForm): def __init__(self, *args, **kwargs): date_format = None if 'date_format' in kwargs: date_format = kwargs['date_format'] del kwargs['date_format'] # The ModelForm's __init__ method doesn't expect to receive that argument, so take it out. super(FormWithFormattedDates, self).__init__(*args, **kwargs) if date_format is not None: for (field_name, field) in self.fields.items(): if isinstance(field, forms.fields.DateField): field.input_format = [date_format] field.widget = forms.widgets.DateTimeInput(format=date_format) What this class does is explore what’s in the form, and … -
Testing App Views
How to easily test views in applications which don't have a urls.py file. -
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Testing App Views
First of all, thanks to those people who've been reading and pointing out improvements in the comments - it's much appreciated, and I've learned a lot from you! Django applications tend to have views, in a views.py file. These are generally looked up by URL. URLConfs (various urls.py files) are used to map request URLs to views. This can lead to a problem from a testing perspective. Not all applications have urls.py files; and for those that do, there's nothing stopping a project wiring up different URLs to those views through a custom urls.py. It therefore becomes difficult to use Django's test client to invoke a view using a GET or a POST because you don't know how that URL has been configured. After all, you run python manage.py test from your project, and the project's configuration is used. Let's say I have a views.py that looks like this: from django.shortcuts import render_to_responsefrom django.template import RequestContextdef say_hi(request): return render_to_response('app/hi.html', context=RequestContext(request)) I want to use Django's test client to ensure that when this view is called, it returns an HTTP 200 OK response. However, my app doesn't have a urls.py - the person using it is meant to wire this view … -
Django moving toward 1.0: tickets overview
As the Django web framework (see our previous study comparing 3 major web frameworks) is moving toward the 1.0 release (due in early september this year), one of the creators of Django, Adrian Holovaty, asked about the strength and weekness of Django replied: I love the way URLconfs work — like a table of contents [...] -
Time to release: django-digest and django-oauthsp
Let me be clear on this: altough I'm already using this code in byNotes, I still consider it in alpha stage, so think twice before incorporating it into your project. django-digest is an app for helping with digest authentication. It implements the basic models needed for storing the data, while authentication is handle by wapi middleware. On the other hand, django-oauthsp implements the service provider side of OAuth with all the bells and whistles. Currently, it supports the full OAuth spec, custom token attributes, token renewal as specified by ScalableOAuth and problem reporting as specified by ProblemReporting. It also includes some views for requesting, authorizing, reviewing and revoking user tokens as well as registering, editing and listing consumers. If you try this apps, you know, leave some feedback in the comments ;). -
Django
Django -
Odds and Ends
I’ve been busy. -
Ajax with dojango (dojo+django)
Ok, now you got dojango and you want to write an AJAX app. There are some basics that just need to be provided in order to make that a piece of cake. Dojango offers them. And this article will show you how to best plug those pieces together and get up and running with ajax and dojango. This article will show you how to simply pass data properly from the backend to the client. JSON communication with the server There are enough use cases (and they are becoming more) when you want to get data from the server and the most common data format nowadays for that is JSON, for various good reasons. Let’s construct a simple form who’s data we want to submit to the server and know if it all went ok or not. For now we just print the submitted data on the django console (from where you started the local dev server) and we let the user know about the submission with the small text “Submitted” beside the submit button. So let’s get started with the JavaScript side. Dojango luckily provides us with the basic infrastructure, so let’s create a template that extends dojango/base.html (it is … -
Flexible test-database engine selection in Django
StopFinder has a suite of unit and integration tests that probably has just about as much code as the application itself. The first thing I do after the deployment is run the tests. This is in the nature of a smoke test, to make sure that I haven’t messed up syncing with third-party libraries and [...] -
MySQL Connection Pooling with Django and SQLAlchemy
Here's a quick and dirty recipe to get connection caching from SQLAlchemy. This is really not connection pooling as that would require a separate process to only handle connections. All this does is prevent the connection from closing after you finish a query. We're also not replacing the Django ORM. To give a little more background, normally when you use Django to get to your database, Django will automatically disconnect from the database when the thread is done with that query. So, if you do something like: q = Model.objects.all() As soon as you destroy "q" it will close the database connection. This is not ideal as it takes time to connect to the database and then to release the database connection. To prevent this, you can use SQLAlchemy to cache the connections for you. With SQLAlchemy, when "q" is destroyed the database connection is not closed. The database connection is only closed when the process running Python is closed. If you have your web server killing threads that are idle then you still have a problem, but you should be avoiding this anyway. See my previous blog post for details about thread thrashing. Step 1 - Install SQL Alchemy: … -
How to evaluate the coverage of a django test suite
I am using this recipe to estimate the coverage of the test suites arounds my django's projects.Software PrerequisitesIn order to follow this recipe you will need to have the following software installed :Djangopython (obviously)coverage.pyI will not explain how to get the first 2 items of this list installed since if you are reading this I am assuming that you are familiar with them. "Coverage" is a bit different, python package index make installing this component a piece of cake.# easy_install coverageUsage of coverage with django test suiteThis presentation give a recipe to evaluate the coverage of your test suite. I found this page useful to understand how to use it. If you are looking for a project to test this recipe on you can checkout "django-survey". The 3 lines below is all you need to get a report on the coverage of your test suite.# coverage.py -e (1)# coverage.py -x manage.py test survey (2)# coverage.py -r -m >report.txt (3)The first line erases collected coverage data, the second executes the module and collect the coverage data, the third line reports on the statement coverage for the given files and show line numbers of the statements that weren't executed.Then you need to … -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Javascript and special characters
I just found a website providing tools and information about javascript and special characters. My current problem was that I lost the special characters in an ajax call. Some trying later and it finally worked - check it out: http://www.the-art-of-web.com/javascript/escape/ -
Dojango version 0.3 released
Now it is official! We released Dojango on google code today and you can get details about it and download it from there. Dojango provides a dojo integration as a reusable app. Download it, copy it into your django project and you have dojo included into django. A quick summary of the main features of dojango: a reusable django app that provides dojo easy dojo setup inside django build an optimized dojo some helper functions, i.e. JSON conversion switch easily between different dojo versions. The main purpose of dojango is to help you using dojo within your django projects. Currently it delivers the main infrastructure to easily switch between several dojo versions and includes several functions that helps developing rich internet applications. Now we are able to chain dojo and django on a solid basis and we work at porting the actual django form widgets to use dojo widgets. We would be happy, if a lot of people would test the current version and tell us about bugs, strange behaviors, misunderstandings, … Also we are open for everyone who would like to help out extending dojango. In coincidence Roberto Saccon (big thanks!) already testet dojango with google app engine and … -
How I Moved My Commercial Projects to Newforms-Admin
My projects were all running on an SVN checkout from late April 2007, after the Queryset-refactor branch was merged into trunk. This meant that I had to make a number of changes, on a public server, to incorporate modifications to file uploads, generic create/update views, and more. In this post I'm only going to cover how I did the change to Newforms Admin, as the other changes were relatively simple for my projects. I made these changes on a live server, whilst my projects were running. For the volume of changes I had to make, this was very straightforward. I use FastCGI, and because the FastCGI processes were already running I was able to modify the Python code without it taking effect until I restarted FastCGI. As always, make sure you've got a backup that's easy to roll back to. The first thing I did was create my admin.py files in each application. For example, for DjangoSites I removed this admin definition from my 'Website' model: class Admin: list_filter = ('verified', 'screenshot',) list_display = ('url', 'title', 'owner', 'created', 'verified', ) search_fields = ('title',) and moved it into websites/admin.py: from django.contrib import admin from djangosites.websites.models import Website class WebsiteAdmin(admin.ModelAdmin): list_filter = … -
How I Moved My Commercial Projects to Newforms-Admin
My projects were all running on an SVN checkout from late April 2007, after the Queryset-refactor branch was merged into trunk. This meant that I had to make a number of changes, on a public server, to incorporate modifications to file uploads, generic create/update views, and more. In this … -
Django-treemenus new release 0.5
I have just packaged a new release 0.5 for django-treemenus That release should only concern people working on Django’s development version after the merge of the newforms-admin branch. I also hear that Django 1.0 alpha has just been released, so that’s good timing ;) If you’re using Django’s trunk prior the NFA merge, then you can stick to 0.4. I’ve also included the German translation kindly provided by Thomas Kerpe (thanks Thomas!). Available languages are now: English, French, Dutch, Russian and German. Please keep sending me your translations and they will be included in future releases. Also, I’d be very interested to hear testimonials of people using this app. How do you use it? Do you use the menu extension mechanism? How would you like to see this app improved? Any feedback/criticism is very welcome ;) -
Django tip: Translating your application names (app_label)
This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a … Continue reading → -
Changeset 7967: NFA Branch Merged into Trunk
I and a host of other folks have been waiting anxiously for this merge for a while now. Excited to see it happen tonight. Good job, Brian Rosner et al.