Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. -
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. -
Duże zmiany w django
Django idzie dużymi krokami do przodu. Coraz większe zmiany zachodzą w głównym repozytorium. Niedawno pojawił się tam patch o nazwie Large streaming uploads, czyli możliwość użycia Django do wysyłania bardzo dużych plików, które bezpośrednio, podczas wysyłania, mogą być zapisywane... -
GitHub Enables Markdown Documentation
I have been desiring to have the documentation that I write for my various projects on GitHub render to HTML when using a .markdown extension, just like they support doing for special files like README.markdown. At first, I thought they'd eventually get around to it and that is the best I could hope for as surely they are too busy to respond to a non-paying customer like me. Then I learned they the used the Lighthouse ticket system to manage their project and took public submissions for features. Before logging a feature request I did some searching and found a ticket already out there requesting exactly this same feature that I wanted. So I just added my own comments to the ticket to give it a +1. After a little back and forth I learned it was implemented tonight (just a week after my first comment). Good to see such responsive development. An example of this feature can be found in my django-aws project which is simple app to provide some template tags to provide Amazon Web Services information a la boto. -
GitHub Enables Markdown Documentation
I have been desiring to have the documentation that I write for my various projects on GitHub render to HTML when using a .markdown extension, just like they support doing for special files like README.markdown. At first, I thought they'd eventually get around to it and that is the best I could hope for as surely they are too busy to respond to a non-paying customer like me. Then I learned they the used the Lighthouse ticket system to manage their project and took public submissions for features. Before logging a feature request I did some searching and found a ticket already out there requesting exactly this same feature that I wanted. So I just added my own comments to the ticket to give it a +1. After a little back and forth I learned it was implemented tonight (just a week after my first comment). Good to see such responsive development. An example of this feature can be found in my django-aws project which is simple app to provide some template tags to provide Amazon Web Services information a la boto. -
Django auto-translation of field values
What’s really nice in Django is the gettext implementation and the _ convention. But when running django-admin.py makemessages we’re not generating any translations for dynamic values such as field values. So let’s say that we have a model and we’d … Continue reading → -
First wapi release
Wapi is somewhat 80% finished, so I think it's ready for the first release. The zipfile includes the wapi code as well as some examples taken from byNotes. You'll notice there are authentication methods for Basic, Digest and OAuth. However, only the former is usable for now, since the other two depend on Django applications which are't ready for release (but are likely to be ready before this week ends). If you try this, leave some feedback in a comment ;). I advise you to not use this code into production yet, since the API may change in the near future. -
Tip: Extending Django flatpages
I did a Google search and since nothing came up, I’m writing this little tip on creating your own CMS by extending Django’s flatpages. What’s good about flatpages is that they’re included in Django and has some basic code to … Continue reading → -
Wapi release coming next week
Wapi, the django application for publishing web apis, will be ready next week. These are the features implemented for now: Exposing ResT apis with transparent serialization (i.e. your code just returns a serialization preset, wapi formats it for you). API-as-class approach: Every function defined inside a class translates to an API method. Then, the class is plugged inside an exposer and it takes care of receiving the parameters and passing them to your function. Authentication middleware: The exposers take an optional parameter which let's your API authenticate users. Currently, there are authentication methods for HTTP Basic (against django.contrib.user database or custom auth function), HTTP Digest (custom auth with helpers for preparing a django.contrib.user database for digest auth) and OAuth (with extensions for token duration and token attributes, all customizable). The newserializers API is included inside wapi as wapi.serializers. Decorators for marking functions as login-required, read-only, write-only... And these are the features planned for the future: SOAP exposer Automatic WDSL generation What do you think about it? Do you miss something which could be useful for exposing Web APIs? -
Using IntelliJ for Django Development
About a year ago I’ve switched over to IntelliJ as my primary Java IDE. When I began to dabble a bit in Django a few days ago, I realized that IntelliJ had me spoiled when it comes to Editor Features – especially when working with Javascript and HTML files. Notepad++ – although a great text editor on its own right – simply didn’t cut it for me for web development. When I tried opening my Django files in IntelliJ I had to realize that IntelliJ needs a project context for opening a file. Even for a simple html file. Fortunately the solution was pretty straight forward. Navigate to your Django project root directory and create a new file .project. Some of you have guessed it: we are pretending to be Eclipse. Open the file in a text editor and paste the following snipped into it: <?xml version=”1.0″ encoding=”UTF-8″?> <projectDescription> <name>myproject</name> <comment></comment> <projects></projects> </projectDescription> Edit the <name> tag value and change it to your liking. Now it’s time to launch IntelliJ. Select File -> New Project. Select Import project from external model and click Next. Select Eclipse (should be the default) and click Next. Now enter the path to your Django … -
EuroPython 2008, day 3
For me, the main theme for the third and last day of the conference was Django. Day started with a session by Honza Král about Django newforms admin, which gave me a pretty good idea what I have to do in preparing for the migration to the new admin interface. Later on the day I had many interesting discussions about varions Django-related things, including ideas about having something like Django release party here in Europe, too. <a href="http://www.flickr.com/photos/uninen/2655794578/" title="We had time to visit the Vilnius TV tower"><img src="http://farm4.static.flickr.com/3183/2655794578_fcd0aba681_m.jpg" width="180" height="240" alt="At Vilnius TV Tower" align="right" /></a>Turns out there are quite a lot Djangonauts here in EuroPython, we just arent organized very well so most of us don't know about each other. Lively after-conference discussions about career choises, Web Design and working with Django in general were definitely the high point of the conference so far. A couple of hour later on the evening, decisions about quiet evening at the Sky Bar (at the 22nd floor of the conference hotel) were forgotten and, again, we headed for the old town. This time we ended up in some night club and, well, yeah, we had a great time :) -
Ordering Edit Inlines
In my continued experimentation with the newforms-admin branch of Django, I wanted to figure out how to order fields of an inline. Looking at the documentation for inlines I saw there was not an ordering field. I had thought that there was but it turns out I was just mistaken in the object hierarchy. InlineModelAdmin inherits from BaseModelAdmin the same as ModelAdmin -- I was thinking that InlineModelAdmin inherited from ModelAdmin. Therefore, I had to determine a way to accomplish this via some spelunking through the code. At first, I thought I'd just create my own template by inheriting or copying the tabular.html template. After looking at it, I determined that I didn't want to figure out how to do a regroup on inline_admin_formset or if even that was the proper way to try to order things in that template. After a few minutes in the code I realized that I could just subclass BaseInlineFormset and specify the fields that I wanted to order by (in this example I will use start_time and end_time: from django.contrib import admin from django.newforms.models import BaseInlineFormset class MyOrderedFormset(BaseInlineFormset): def get_queryset(self): qs = super(SessionInlineFormset, self).get_queryset() return qs.order_by('start_time', 'end_time') class MyOrderedInline(admin.TabularInline): model = MyModel extra = …