Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
PyCon Philippines 2012 Day 1
PyCon Philippines 2012 (PyCon PH) happened just this past weekend at the University of the Philippines Diliman (UP Diliman) campus in Quezon City, which is part of Metro Manila. I can assure you that PyCon PH was an wonderful, amazing, humbling experience. I'm hoping that this post and others will get across to you why. Arrival Frank Pohlmann, chairman of PyCon Philippines picked us up and drove us to the event. He had worked day and night getting the event ready, all the while running his company, working a job, and being a father to his lovely 21 month old daughter. As we arrived at the venue, Audrey and I were met by our good friend, Filipino-American Bryan Veloso of Github, who was to provide the closing keynote. As soon as Bryan heard that there was going to be a PyCon in the Philippines he gave up his trip to Europython to be a speaker at PyCon PH. Inside the Institute of Electrical and Electronics Engineering, we were greeted Ann Tan-Pohlman, logistics co-chair and volunteer organizer. She had over a dozen volunteers getting ready for the oncoming flood of registrants. More on the herculean efforts of the organizers and volunteers … -
django CMS 2.3 released
-
Multiple File Uploads in Django
Here is a quick example of how to add a multiple file form to your Django application. Most multiple-upload front-ends were created without Django in mind, so interfacing with tools is not always straightforward as it might be with a different language. Thankfully, there are a couple of Django libraries ... -
AJAX and Django Views
It seems that cleanly and easily doing AJAX views in Django is an area that gives a lot of people trouble. We like to do views as straight HTTP if at all possible, but there are always interactions that would be better served by not having a page load. We're also big fans of django-tastypie but it's a whole other ball of wax on its own, especially if you want to have views that write to the database. So, for the purposes of getting everyone up to speed doing AJAX with Django, we'll ignore Tastypie for now and just stick with ordinary views. Django automatic CSRF To start things off, put this bit of Javascript from the Django docs into a script that's loaded on all the pages where you'll be needing to perform AJAX views. This allows you to ignore the CSRF token for AJAX views, but it will be added as a request header. We previously said this could be seen as a security loophole and that same-origin came into effect. Both of these statements are wrong. AJAX & Form Field Errors Before we get to the Django side, there are a few small scripts that we recycle … -
Generic Layouts in Crispy Forms
Just a quick tip and sanity check, today, about something I ran into with django-crispy-forms, the awesome new form library from Miguel Araujo. This morning, I converted the project we've been building for a client (currently some 1,700 or so files, counting templates, CSS, and icons) from django-uni-form to django-crispy-forms. It's a pretty painless transition, actually. Just do some find-and-replace across your files, basically changing any instance of uni- to crispy- (well, and form to forms), and you're good to go. Then, however, I wanted to convert two large forms that we have, which share 90% of their fields, to using the sharable Layout objects that django-crispy-forms gives us. Basically, the forms looked like this: class FirstForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field", [field3 through field20] class SecondForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field2", [field3 thorugh field20] Obviously that was a lot of repetition that we could cut out now that these inheritable layouts exist. By the way, I'm pretty sure this would have been possible in django-uni-form but likely not as friendly. First I started off by creating the shared resources. … -
Our Custom Mixins
UPDATE: We've released a Github repo and a PyPI package with our mixins. Feel free to fork and submit new ones through a pull-request. Let's just start out and say it, Class Based Views. Ooohhhh. Unfortunately the topic of class based views is thought of as somewhat of a dark art in the Django community. It doesn't help that the documentation is still lacking but I find a lot of people, especially on Reddit, refuse to use them. For whatever reason, it's a hard pill for some to swallow. Before DjangoCon 2011, we started playing with class-based views. At first they seemed like a nightmare and without decent docs, we got frustrated really quickly. Skip forward to today and I can't imagine writing old function-based views again. Some argue that the generic views are only for generic applications and that, somehow, their work is far too custom and complex to be handled in a generic class-based view. Based on my experience, 99% of the time, they would be wrong. We plan on covering generic class-based views extensively with GSWD. Today, I'd like to share some mixins we have cooked up, on a rather large client project, that have helped us … -
User-friendlier model forms
Recently, in our large client project, we had need of fields, in a model form, that accepted multiple types of input, but sanitized the data for the model. For example, the rent field, on the form, needs to handle a rent range (e.g. 900-1200), a single amount, or be overridden or extended by other bits of information, like "call for details" or "on approved credit". Obviously we don't want to have to parse this out every time we read the data. So, enter our fields that tear data apart and put it together every time it passes through. Model Let's go over our Rent model first. It's an abstract model so we can use it in multiple places (we have more than one logical model in the system that needs to deal with rent, this way we can use it multiple places without having to hold on to a huge amount of joins). We have several other abstract models that perform the same actions as our Rent model, but I won't show them here. from django.core.exceptions import ValidationError from django.db import models class Rent(models.Model): rent_low = models.PositiveIntegerField() rent_high = models.PositiveIntegerField(blank=True, null=True) rent_percent_income = models.FloatField(blank=True, null=True) rent_oac = models.BooleanField(default=False) rent_call_for_details = … -
Extending time and details
For the fun of it I added an "Extended Room" contrib to Evennia the other night.("Contribs" are optional code snippets and systems that are not part of the actual codebase. They are intended for you to use or dissect as you like in your game development efforts).The ExtendedRoom is a room typeclass meant to showcase some more advanced features than the default one. Its functionality is by all means nothing revolutionary in MUD-world, but it was fun and very simple to do using only Evennia's basic building blocks - the whole thing took me some two hours to code, document and clean up for a contrib push. The "ExtendedRoom" contribution has the following features:Season-based descriptions. The new Room typeclass will change its overall description based on the time of year (the contrib supports the four seasons, you can hack this as you please). It's interesting from an implementation point of view since it doesn't require any Script or ticker at all - it just checks on-demand, whenever it is being looked at, only updating if the season has actually changed. There is also a general description used as a fallback in case of a missing seasonal one.Time-of-day-based descriptions. Within each … -
Testing As a Different Django User
All types of Django auth do basically the same thing: They associate a browser session ID with a Django user if the user logs-in successfully. I found a neat technique to bypass a Django login by modifying with a Django session, which can be useful for testing purposes.Why is ... -
Long Time No See
Hello again everyone! Soooo much has happened since I last posted on my blog. I figured it was about time to check in and actually be active on my own site again. What follows is just a summary of what has happened in our lives since the beginning of February this year. Leaving ScienceLogic First of all, my wife and I decided toward the end of 2011 that it was time for us to move away from Virginia. For reasons that we did not quite understand yet, we both wanted to move to Utah. I applied for my first Utah-based job opportunity just before Christmas 2011. Several of my friends in the Salt Lake City area were kind enough to get me a few interviews here and there, but none of the opportunities were very serious. Probably about the time I wrote my last blog post, I was contacted by a recruiter in Boise. I would have loved to move back to Idaho, but my wife would have nothing to do with me if I did that. When I shared this information with the recruiter, he said he had a recruiter friend in the SLC area and that he'd pass … -
Web API and Metaprogramming
In the last week I hacked a little with the preview of Diablo 3 web API . My aim was to produce a simple python client. I started the old way, parsing the JSON data the service returned and building Classes for each element. Then I realized I wasn't doing it not pythonic nor DRY. So I started to build generic objects that could hold the data and take the shape of each element. The basic idea is -
django CMS 2.3 release candidate 2 available
django CMS 2.3 release candidate 2 available -
django CMS 2.3 release candidate 2 available
-
Make runfcgi fail when database connection is open before fork
Make runfcgi fail when database connection is open before fork. Das ist eine Sache nach der ich schon ewige Zeiten jage, zuletzt in ein paar ziemlich wichtigen Projekten. Flup arbeitet so, dass es die WSGI-Anwendung erst initialisiert und mit dieser initialisierten WSGI Anwendung dann die Forks für die Worker macht. Dummerweise gibt es bei uns aber Datenbankzugriffe wärend der Anwendungsinitialisierung – dadurch hat der Basisprozess schon eine offene Datenbankverbindung, jeder Fork kopiert diese Daten. Aber der Socket der Verbindung geht natürlich nicht mit – der neue Prozess denkt nur er wäre verbunden, ist es aber nicht. Zugriffe von denen neuen Prozessen fallen dann mit einer Exception raus. Man kann im verlinkten Patch auch gut den raise auf die Exception einfach durch connection.connection = None ersetzen. Dann wird einfach die Verbindung die sowieso defekt ist weggeworfen und in neuen Prozessen immer eine neue Verbindung aufgebaut. Damit haben wir zumindestens in einem Produktionsumfeld (mit psycopg2) das ganze beheben können und sind guten Mutes, dass es auch bei der Umgebung mit pyodbc helfen wird. -
Django verbose_name in your template
There are many situations when you want to display model field verbose_name in template when displaying tables and other data. Ideally you would put this value in header section of your table for DRY purposes. The problem is that it's unable to use model _meta in templates. You can achive the same using an example verbose_name_tags.py templatetag. # verbose_name_tags.py from django import -
Never fix a bug twice
Noah Sussman wrote a post on Things you should test, “A checklist of things that are worth testing in pretty much any software system.” Many of the things on the list are helpful reminders. However, I think the mindset it encourages is essentially wrong. The mindset is basically this: Identify common mistakes that developers make, and ensure you are writing tests that check you haven't made them. The problem with this approach is that it is essentially whack-a-mole debugging. There is a never ending supply of bugs to kill. A much more helpful approach is found in this post on easy programming that advocates “Never fix a bug twice” (about one-third of the way down). If you come across a bug or class of bugs that often occur, you should not be thinking first of all “better add that to my list of classes of bugs that need testing against”. You should rather be thinking “how can I change the system so that this class of bugs disappears entirely?”. So, to take some of items listed for testing: Input handling bugs, such SQL injection and XSS attacks. In Django apps, I never write tests for SQL injection attacks or XSS … -
PostgreSQL and PostGIS installation from source on Mac OS X Lion
This is a cookbook for installing PostgreSQL and PostGIS on Mac OS X Lion from source, as alternative you can install the binaries from EnterpriseDB or KyngChaos. You don't have to install all packages but if you're using Django will be useful. Requirements Xcode with "Command Line Tools": Installation via Xcode > Preferences > Downloads. PostgreSQL Create the postgres user via System Preferences(for simplicity), use "postgres" as username. Compiling and installing PostgreSQL: $ curl -O http://ftp.postgresql.org/pub/source/v9.1.3/postgresql-9.1.3.tar.gz $ tar xzfp postgresql-9.1.3.tar.gz $ cd postgresql-9.1.3 $ ./configure CC=/usr/bin/clang CXX=/usr/bin/clang++ "CFLAGS=-arch x86_64" "LDFLAGS=-arch x86_64" "CXXFLAGS=-arch x86_64" $ make $ sudo make install $ cd .. Create PostgreSQL Database Cluster: $ sudo mkdir /usr/local/pgsql/data $ sudo chown postgres /usr/local/pgsql/data $ sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data Start PostgreSQL Server: $ sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start After installation add to .profile or .zshrc: export PATH=/usr/local/pgsql/bin:$PATH PROJ4 PROJ.4 is a library for converting geospatial data to different coordinate reference systems. $ curl -O http://download.osgeo.org/proj/proj-4.8.0.tar.gz $ curl -O http://download.osgeo.org/proj/proj-datumgrid-1.5.zip $ tar xzfp proj-4.8.0.tar.gz $ cd proj-4.8.0/nad $ unzip ../../proj-datumgrid-1.5.zip $ cd .. $ ./configure CC=/usr/bin/clang CXX=/usr/bin/clang++ "CFLAGS=-arch x86_64" "LDFLAGS=-arch x86_64" "CXXFLAGS=-arch x86_64" $ make $ sudo make install $ cd .. GEOS GEOS is a … -
#18251 multithreading deadlock in django.models.loading.get_apps – Django
#18251 multithreading deadlock in django.models.loading.get_apps – Django. Und noch eine Sache, die uns vielleicht betreffen könnte – Raceconditions zwischen Django-Threads bei der Initialisierung von Django-Applications. Gibt auch schon einen Patch dafür, der das in den Django Internals behebt. -
Using SELECT FOR UPDATE in Django
Using SELECT FOR UPDATE in Django. Drin was dran steht. Denn der Django ORM kann derzeit keinen SELECT FOR UPDATE erzeugen, aber manchmal braucht man ihn einfach. -
DjangoSites Move Complete
I've finished migrating DjangoSites to it's new home, and everything should be back online. I've got a few tips for migrating simple Django-powered sites if you click through to read the rest of this blog post. -
DjangoSites Move Complete
For the past few years I've hosted all of my projects on a single RimuHosting VPS. It's old, running Debian 5.0, and maintenance and upgrades have become headachy. It isn't easy to run Python 2.7 on old Debian versions, and since I only started using virtualenv relatively recently, things were a real mess. As such, it was time to upgrade the VPS. I made the decision to look around for other hosting options, and eventually settled on Prgmr as the performance-for-dollar ratio seemed much higher to me. I've taken the opportunity to break things down into multiple smaller VPS units to try and keep maintenance somewhat simpler. I can pull a single site's server down without breaking any other sites, and I can upgrade components individually for a single site. Prgmr's pricing makes this possible: Their 'base' is very low - you pay $4 for each VPS plus RAM. Djangosites.org now sits on it's own 512mb Prgmr Debian 6.0 instance. With 128mb taken up with memcached and a small portion to nginx and the operating system, there's plenty of RAM left for my gunicorn worker processes. So how did I move everything across? Although it took me 3 days to … -
DjangoSites Move Complete
For the past few years I've hosted all of my projects on a single RimuHosting VPS. It's old, running Debian 5.0, and maintenance and upgrades have become headachy. It isn't easy to run Python 2.7 on old Debian versions, and since I only started using virtualenv relatively recently … -
Making the django foreign key admin widget more useful
Thanks to a user at Django-snippets, I was able to quickly create an app containing a widget for displaying icons along side the normal related widget for foreignkey fields. The result looks like this: It’s pretty easy to use. Check it out on Github! -
Mining the Social Web: for fun , profit and satisfaction
I have recently read "Mining the social web" By Matthew A. Russell. It was part of my "big data & Natural Language" master plan, and, since the example were in python it looked as a good read. And it is! This is a review I completly agree with: Mining the Social Web is a good start for anyone is going to create scripts to analyze patterns in Social Networks. I've to say that this book -
Using Factory Boy in Django application tests
Factory Boy is a fixtures replacement for Django tests (and not only). In an easy and manageable way you can create and maintain data needed for tests. Fixtures can be hard to maintain. Direct ORM usage isn't the best thing too. Factory Boy is here to help... You can find Factory Boy on github. There is also full documentation of the project. Factory Boy allows you to create factories for models (not only for models). A factory is something like a wrapper that provides data required for object creation.