Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Nashvegas: A Simple Django Migration Tool
Introduction Back in July I discussed how I built a tool to help manage database changes across a team and through deployment for our Django based project. And yes, I am aware of other approaches/projects tackling this same problem. None of them seemed to work how I wanted them to as they all seemed to focus on trying to keep you from writing the raw sql yourself. I am comfortable with writing SQL and for something that will execute automatically against production databases, I prefer to have that control in knowing exactly what will get executed. Yes, many of these tools have options to allow me to preview the generated SQL, but it still gave me the feeling of being boxed in. For your reference, here are the ones I reviewed: South dmigrations django-evolution deseb yadsel schema-evolution So I abstracted out the script and it's assumptions about our environment to function as a management command in a stand alone reusable app. My Approach It's extremely simple and is based purely on executing SQL statements in order based on it's file naming scheme. Basically, you create a folder somewhere in your project -- I call mine "db". Within this folder you … -
Nashvegas: A Simple Django Migration Tool
Introduction Back in July I discussed how I built a tool to help manage database changes across a team and through deployment for our Django based project. And yes, I am aware of other approaches/projects tackling this same problem. None of them seemed to work how I wanted them to as they all seemed to focus on trying to keep you from writing the raw sql yourself. I am comfortable with writing SQL and for something that will execute automatically against production databases, I prefer to have that control in knowing exactly what will get executed. Yes, many of these tools have options to allow me to preview the generated SQL, but it still gave me the feeling of being boxed in. For your reference, here are the ones I reviewed: South dmigrations django-evolution deseb yadsel schema-evolution So I abstracted out the script and it's assumptions about our environment to function as a management command in a stand alone reusable app. My Approach It's extremely simple and is based purely on executing SQL statements in order based on it's file naming scheme. Basically, you create a folder somewhere in your project -- I call mine "db". Within this folder you … -
FAQ: Untrusted users and HTML
An input form that takes raw HTML. It’s a pretty common thing to see in web apps these days: many comment forms allow HTML, or some subset thereof; many social-network-style applications allow end-users to enter HTML in their profiles; etc. Unfortunately, allowing untrusted users to enter raw HTML is incredibly dangerous; read up on XSS if you don’t know why. So a common question that comes up in web developer circles deals with how best to “escape” user-entered HTML so that is safe for presentation. -
sPaste Update
After a bit of a break, there is now a bit of new functionality in sPaste. Now when creating a snippet users can select a date and a number of views, after which the snippet will self-destruct. This update adds a great extra layer of security by only allowing information to exist in sPaste just [...] -
django full text search with solango
2 months ago I wrote a post titled "django fulltext search part-1" this post was explaining how to take advantage of djangosearch to interface between django and solr.The big advantage of djangosearch is the fact that it comes with a plugable backend architecture. This can be a strength since in theory it enables you to abstract the details of the the full text engine you are using however in practice I ended up writing a patch to bypath the abstraction layer because it was preventing me of doing the query I wanted. So to make a long story short djangosearch was not working out of the box for my needs.However 2 week ago Sean Creeley released solango and this significantly changed landscape of full text search in the django eco-system. I will not go in the details about solango in this post. It comes with some management commands that are so convenient that I still wonder why I haven't thought at implementing them on top of djangosearch. I will copy below a short extract form the documentation which is excellent :./manage.py solr --help#solango schema options--fields Prints out the fields the schema.xml will create--flush Will remove the data directory from Solr.--reindex … -
QueryDict and update()
QueryDict and update() -
Parsing unescaped urls in django
Modern browsers escape urls automatically before sending them to the server, but what happens if your application serves http requests to clients that doesn't escape urls?The answer is that can get unexpected results if you server works in Django (and probably in any python framework/application). That's because python's BaseHTTPServer.BaseHTTPRequestHandler handles urls according to standards, not from a human point of view.Let's see with an example, consider the next request:http://vaig.be/identify_myself?name=Marc Garcia&country=Cataloniaif you request it with a browser, it will escape the space in the url, so the server will get:http://vaig.be/identify_myself?name=Marc%20Garcia&country=Cataloniabut what if the client uses, for example, python's urllib2.urlopen without escaping (using urllib.quote)? Of course it is a mistake, but you, as server side developer can't control your clients.In that case the whole request that server receives is:GET http://vaig.be/identify_myself?name=Marc Garcia&country=Catalonia HTTP/1.1and after being processed (splitted) by python's BaseHTTPServer.BaseHTTPRequestHandler, what we'll get from django is:request.method == 'GET'request.META['QUERY_STRING'] == 'name=Marc'request.META['SERVER_PROTOCOL'] == 'Garcia&country=Catalonia HTTP/1.1'so our request.GET dictionary will look like:request.GET == {'name': 'Marc'}what is not the expected value (from a human point of view).So, what we can do for avoiding this result is quite easy (and of course tricky), and is getting the GET values not from django request.GET dictionary but from the one … -
Washington Times releases open source projects
The Washington Times has always focused on content. After careful review, we determined that the best way to have the top tools to produce and publish that content is to release the source code of our in-house tools and encourage collaboration. The source code is released under the permissive Apache License, version 2.0. The initial tools released are: django-projectmgr, a source code repository manager and issue tracking application. It allows threaded discussion of bugs and features, separation of bugs, features and tasks and easy creation of source code repositories for either public or private consumption. django-supertagging, an interface to the Open Calais service for semantic markup. django-massmedia, a multi-media management application. It can create galleries with multiple media types within, allows mass uploads with an archive file, and has a plugin for fckeditor for embedding the objects from a rich text editor. django-clickpass, an interface to the clickpass.com OpenID service that allows users to create an account with a Google, Yahoo!, Facebook, Hotmail or AIM account. The opensource.washingtontimes.com web site will be hosting the code and issue tracking software, using django-projectmgr. Update: All our projects are now hosted at GitHub. -
Abstract Models and Dynamicly Assigned Foreign Keys
Model inheritance enables creating extensible apps. You can define a reusable core app which includes base.py with abstract models and models.py with models extending the abstract ones and inheriting all the features. In the specific project you can either use the core app directly, or create a specific app which models extend from the base abstract models of the core app and additionally introduce new features.This is a quick example skipping all the unrelated parts like settings, urls, and templates:core_projectappsplayerbase.pyfrom django.db impport modelsclass PlayerBase(models.Model): name = models.CharField(max_length=100) class Meta: abstract = Truemodels.pyfrom core_project.apps.player.base import PlayerBaseclass Player(PlayerBase): passspecific_projectappsplayermodels.pyfrom core_project.apps.player.base import PlayerBaseclass Player(PlayerBase): points = models.IntegerField()The concept works fine until you need to use foreign keys or many-to-many relations in the abstract models. As Josh Smeaton has already noticed, you can't set foreign keys to abstract models as they have no own database tables and they know nothing about the models which will extend them.Let's say, we have the following situation: GameBase and MissionBase are abstract models and the model extending MissionBase should receive a foreign key to the model extending GameBase.Thanks to Pro Django book by Marty Alchin, I understood how the models get created in the background. By default, all … -
Mejoras en django.es y feed de la comunidad
Sois varios los que nos habéis pedido un feed con las últimas entradas de los blogs la comunidad. Pues aquí lo tenéis. También hemos introducido algunas mejoras en django.es para que las páginas de nuestro sitio web carguen más rápido, y parece que lo hemos conseguido :) Por ejemplo los feeds de la página de inicio ya no se cargan en el lado del servidor al procesar la página sino mediante javascript una vez se ha cargado el documento. -
Open Government Hackathon: Chicago, March 29-31
Sunlight Labs is proud to be hosting the first ever Open Government Hackathon, March 29-31 in Chicago. This will be a 48 hour sprint where developers that are interested in contributing to an open source project that will free or otherwise enhance government data can gather to brainstorm and hack on things. Who Should Attend? Anyone that is interested in contributing to an open source project that will free or otherwise enhance government data can gather to brainstorm and hack on things. Although the sprint takes place at PyCon you don't have to be attending the conference to join us. Participation is free and open to anyone. What Happens at the Open Government Hackathon? The nature of the sprint will be fairly freeform, two Sunlight Labs members will be on hand guiding users that want to contribute to opening up the government. Users can come to the sprint without any background and we would help coordinate them and place them on a project where there skills would be useful (there is always a ton of scraping that needs to be done, building mini-web apps to showcase gov't data, etc.) Most likely we'll spend the first session on Sunday talking about … -
Blango, django-geonames, oauthsp and wapi hosted at GitHub
I've finished moving some of my git repos to GitHub. You can now check Blango, django-geonames, oauthsp and wapi from there. Those are, from now on, the official repos. The old ones at byNotes have already been closed. -
High Performance Media Merging with Django, Nginx and Memcached
I admit it – I’m a performance junkie. I can’t stand code that just works but performs poorly. Being said, I recently fell in love with Django (a fantastic Python powered web application framework). In one of my current projects – xarmory.com – the number of requests for static resources issued during page load began to bother me. The project makes intensive use of jQuery and it’s my personal belief that Django + jQuery is a match made in heaven. When working with jQuery you will find yourself often in the situation to rely in cool little jQuery plugins – each distributed as a seperate javascript file of course. When a project grows, those files begin to add up. In the case of xarmory.com we now had eleven javascript references in the header section of the page. Although the individual files are were only 3-11k in Size, the request overhead for all those tiny files became unacceptably in my eyes. To alleviate the problem I decided to resort to a simple solution and just merge the individual script files into a single file. A pretty common practice. Before reinventing the wheel I surfed the net for existing solutions and found … -
Leaving byNotes
Well, let me start by explaining all those mails about byNotes I haven't answered in the last few months. Around mid November I got contacted by the recruiting staff of a social network. At that time, I was still working in the project for my degree (computer science students in Spain are required to write a project for the university in order to get the degree) and I wanted to concentrate on it, but I decided to just take the interviews just in case. They finally told me they wanted me to join them and we agreed to continue the negotiations once I had finished my project. Fast forward to January, my project is done and christmas holidays are gone, time to reestablish negotiations. Salary is good, schedule is very good (telecommuting 99% of the time) but there's something bad: I must leave byNotes, since management considers it's competing with them. It wasn't an easy decision, but it was the best option. byNotes has been very fun, but also such a time drain to me, and I haven't got any single eurocent from it. Plus, I'm a coder, not a designer nor a business guy, and I don't have too … -
Django Tips – Unique Date Querysets
I swear this particular feature of querysets was made especially for the archive listing of a blog. You know, the month and year listing in the side bar for all your previous posts. This solves that problem exactly. -
Django LogEntry to the rescue
If you use Django's admin application, you're familiar with its "Recent Actions" sidebar. It gives a simple summary of your latest edits, including clickable links to the relevant objects (not any ones you deleted, naturally, but ones you added or changed). It's probably not something you look at very often, unless you do such intensive work in the admin that you lose track of things. Django stores that log data (via the admin's LogEntry model) for all admin users, a fact which has caused me to repeatedly daydream about writing a custom view or two to display it. In other words, I'd like to let superusers browse all object editing history. Because sometimes you need to answer questions like "When was that changed?" and/or "Who changed it?" Today at work, a question arose about some data that was deleted via the admin several months ago. It didn't need recovering, we just needed a record of its deletion. An audit trail. LogEntry to the rescue! Via manage.py shell and manage.py dbshell I was able to do some quick spelunking and get exactly the records we needed. It was a very positive experience. I love being able answer questions that begin, "Paul, … -
Announcing django-filter
Django-filter is a reusable Django application I have been working on for a few weeks, individuals who follow me on Github may have noticed me working on it. Django-filter is basically an application that creates a generic interface for creating pages like the Django admin changelist page. It has support for defining vairous filters(including custom ones), filtering a queryset based on the user selections, and displaying an HTML form for the filter options. It has a design based around Django's ModelForm.You can get the code, as well as tests and docs over at Github. For all bug reports, comments, and other feedback you can send me a message on Github(or message me on IRC) until I figure out a proper bug tracking system.Enjoy. -
FE-Plugin with multilingual TYPO3
I always forget how to force a frontend plugin to display the texts localized through $this->pi_getLL($key). This is how it works: class tx_extkey_piX extends tslib_pibase { function main() { $this->sys_language_uid = (int) t3lib_div::_GP('L'); ... } } -
FE-Plugin with multilingual TYPO3
I always forget how to force a frontend plugin to display the texts localized through $this->pi_getLL($key). This is how it works: class tx_extkey_piX extends tslib_pibase { function main() { $this->sys_language_uid = (int) t3lib_div::_GP('L'); ... } } -
FE-Plugin with multilingual TYPO3
I always forget how to force a frontend plugin to display the texts localized through $this->pi_getLL($key). This is how it works: class tx_extkey_piX extends tslib_pibase { function main() { $this->sys_language_uid = (int) t3lib_div::_GP('L'); ... } } -
Training Video of the week
Thoughts David did a great job explaining many of the crucial pieces of web site scaling. Our discussion afterward focused on how we can structure our site to handle more requests without more hardware. We also talked about David’s point on the importance of profiling code to find the slow spots. I know I have spent too much time trying to optimize code that was only a small part of the running time. -
EuroDjangoCon
Just a quick note to say I just registered to go to EuroDjangoCon! Head over to http://euro.djangocon.org/ to sign up for the earlybird prices! I can't wait, it's going to be Awesome. :) Hope to see you all there! -
Missing django-admin's startproject Command?
Did you just notice your "django-admin.py startproject new_project" command does nothing but to remind you to read the help docs? Well, clear your existing environment variable "DJANGO_SETTINGS_MODULE" and you'll have it again.Django takes away "startproject" command if it realizes you are already working with an existing project. Not sure what the purpose is, but its there. -
A Second Look at Inheritance and Polymorphism with Django
Previously I wrote about ways to handle polymorphism with inheritance in Django's ORM in a way that didn't require any changes to your model at all(besides adding in a mixin), today we're going to look at a way to do this that is a little more invasive and involved, but also can provide much better performance. As we saw previously with no other information we could get the correct subclass for a given object in O(k) queries, where k is the number of subclasses. This means for a queryset with n items, we would need to do O(nk) queries, not great performance, for a queryset with 10 items, and 3 subclasses we'd need to do 30 queries, which isn't really acceptable for most websites. The major problem here is that for each object we simply guess as to which subclass a given object is. However, that's a piece of information we could know concretely if we cached it for later usage, so let's start off there, we're going to be building a mixin class just like we did last time:from django.db import modelsclass InheritanceMixIn(models.Model): _class = models.CharField(max_length=100) class Meta: abstract = TrueSo now we have a simple abstract model that … -
Migrating Django models with south and converting data
I use South whenever a model needs to be changed. One thing that is not really documented in the South documentation is how to convert data. After some trial and error I found a way to use Django QuerySets to access both the old and new models to convert data. For example, I used to have two models defined like this: class Assignment(models.Model): course = models.ForeignKey(Course) name = models.CharField(max_length=100) class AssignmentEdition(models.Model): assignment = models.ForeignKey(Assignment) # ... other fields The way the assignments were defined, each edition of an assignment has the same name. I needed to change this into: class Assignment(models.Model): course = models.ForeignKey(Course) class AssignmentEdition(models.Model): assignment = models.ForeignKey(Assignment) name = models.CharField(max_length=100) # ... other fields Each edition has it’s own name. It’s still possible for editions to have the same name, but it is also possible to have a different name and still be an edition of the same assignment. During the migration I want each assignment edition to get the name of it’s assignment. One way to do this is to use SQL queries to get the names of the assignments and update the assignment edition names, but that’s not very Django-like. I want to use QuerySets. I …