Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
django-nbskel
Well it was time already to give some more code into the public domain and the community, so I decided to release my personal way of starting new django projects. I call it django-nbskel ("nb" for nomadblue and "skel" for skeleton). Development code can be found, along with my other apps, in Bitbucket: http://bitbucket.org/nabucosound/django-nbskel/ The project page is here. The purpose if this application is to contain a basic django project and help you out configure it to speed up the process of starting up a new development, be it a quick hack or a long project. I often need to produce new django projects and I don't enjoy doing repetitive things. They start basically with the same structure so with this app I can wrap all the first steps into a couple of actions. It also makes me feel secure because I always tend to forget to initialize settings, include files, import modules, and so on, so with django-nbskel I am sure I am beginning to develop upon a tested and stable code. Please be warned this is code that automates stuff for me, so you will be probably modifying it to fit your django configuration, tools, and deployment … -
Django translations for lazy programmers
I came to a dirty but practical solution for one minor project I had to develop for a client who wanted a website with i18n capabilities and also needed to have the different translations for each candidate values each in a different field, in the same model. That is, one field for each language. Here in this post I explain how to achieve it. Let's say we have some models with some fields we want to be duplicated, one for each language. In this example, we will store english (en), spanish (es) and french (fr): class MyObject(models.Model): name = models.CharField(max_length=50) title_en = models.CharField(max_length=50) title_es = models.CharField(max_length=100) title_fr = models.CharField(max_length=100) description_en = models.CharField(max_length=100) description_es = models.CharField(max_length=100) description_fr = models.CharField(max_length=100) class MyOtherObject(models.Model): name = models.CharField(max_length=50) content_en = models.CharField(max_length=200) content_es = models.CharField(max_length=200) content_fr = models.CharField(max_length=200) Notice we append a suffix to each field consisting of an underscore plus the language code. It is important to set the field names this way, as we are going to use a template tag that uses this suffix to find the proper translated field. Next thing to do is add a new TRANSLATION_FIELDS setting that will contain all the field names for ALL your model fields that … -
My thoughts on DjangoCon Berlin 2010
During this past week I attended DjangoCon, which took place in Berlin thanks to the German Django Association, a non-profit organization founded by german djangonauts. Interesting talks about Django, WSGI, NoSQL, testing, CouchDB, MongoDB, South or front-end design, to name a few. And in the evening or night, geeks gathered in Berlin pubs for beers and fun. I found a relief in meeting so many other people using Django, we djangonauts are a sort of lonely rangers here in Spain. The community is expanding, at the same pace that Django project is growing. In fact, it has already become a grown up in the open source ecosystem, and I think this fact is one of the main reasons that brought Jacob Kaplan-Moss give the first talk in the opening day about how we, Django users/developers/commiters, have to behave with the project itself and to the eyes of the others. The pony, a silly mascot that can be embarrassing to somebody (picture a girl asking her parents to buy her a pony, or a gay decorating his bedroom with stuffed animals, and you won't find the scene much related to guys with beards, pirates, ninjas or geeks hacking python) is precisely … -
New release of django-nomadblog
My Django blogging app, django-nomadblog, is sporting a new look after I added many features I needed for some of my present and future project developments. Mainly, I wanted to turn this app into a multiple blogging system, which means I am able to create and manage multiple blogs from the same installation, via admin interface. The implementation of this followed some improvements in the code and the modularity of the app itself. To upgrade this django blog to the new version of django-nomadblog, I should have created a migration using South, for example. But considering the small size of the database and the project inn general, I went the lazy way and created a fixture from the old database, edited by hand to meet the new models and relationships, and imported it to a fresh database. My punishment for being lazy was missing to update django.contrib.sites to replace the default example.com with nomadblue.com, and to include the data related to the projects site section in the fixture. I'll never learn. -
Using disqus comments and django-localeurl
Lately I have added comments to my company blog. We have it localized, so things turned out to be not so straight forward as one can think. django-localeurl This neat piece of code allows us to localize our URLs. You can find it in its bitbucket repository. So, in my blog I have four languages (english, catalan, spanish and french), each one with a different prefixed URL: http://example.com/blog/post_slug/ http://example.com/ca/blog/post_slug/ http://example.com/es/blog/post_slug/ http://example.com/fr/blog/post_slug/ Note that the english version doesn't have any prefix actually; this is a default from django-localeurl but you can change it if you want. disqus url So we want to include, of course, comments to our blog, and we are going to use disqus, a well-known service that makes our life more enjoyable without having to carry the burden of spam comments, implementing all the ubiquitous facebook, twitter, and many more logging services, to name a few. When using the universal JavaScript embed code, by default this script uses window.location to send the URL of the current page. As long as we are using localized URLs, if we don't modify this behavior then each localized URL would have its own comments. Hopefully, we can specify our URL with the … -
Translated text images for lazy programmers
In a previous post about django translations in this blog, I shared how to achieve a quick system that allowed me to manage translations stored in models and served using a template tag. In this post I will explain how to serve images that contain translated text and, hence, a localized image exists for each language. In my case, images are referenced from <img> HTML tags in templates and from CSS files. First of all we must create a basic structure in our img/ and css/ media folders, creating inside a directory for each language code we will use. For example, if we have two languages -- english and spanish -- we would create img/en/, img/es/, css/en/ and css/es/. In the CSS folders, the same files must be initially copied. If we have, for instance, just one style.css file, it must be both in css/en/style.css and css/es/style.css: css/ en/ style.css es/ style.css For the images, we should create the images that will be translated into each language code folder. All CSS files will reference the non-translated images in the same way, but their own file path to the translated image. I'll give an example. Let's say we have one background … -
django-propaganda: simple newsletter app
Hey you, political leader, founder of a new religion or spiritual guru! With this application, your acolytes will receive the official organizational propaganda pamphlets right into their inboxes. Keep them updated with the Truth! In a recent fever that drove me to program a system for the marketing department at my Barcelona SEO company, I developed a project that integrates Django admin to create basic versions of newsletters, manage the subscribers, and queue emails for later delivery using Celery workers and Amazon SES as platform. So now I published on GitHub the part that manages the basic models and functions: https://github.com/nabucosound/django-propaganda/ This simple Django application is made to be used for trivial newsletter (pamphlets) deliveries with your information (propaganda), where you supply the raw content (both plain text and HTML versions) to be delivered. Subscribers will then receive the emails you send. In the coming days I will maybe open source code for a sample project using the app, as well as all that components to finish the subscriber mailing cycle, or perhaps write a post with the instructions that I found useful to achieve that. In the meantime, I uploaded django-propaganda to the Python index, so that can easily … -
Asynchronous email delivery with Django, Amazon SES, Celery and Supervisord
A few weeks ago, I released a simple Django app to manage models for simple newsletters. The package itself is blatantly useless if we do not use it on a project that integrates with other parts, so I created a fully-equipped system that can create propaganda, assign it to subscribers and queue it ready to be sent whenever I need to. The architecture First, I have been using Amazon SES for a while to send newsletters to customers, both in-house and for clients and third-parties. It removes the hassle of maintaining SMTPs, email server management, network configuration, and meeting rigorous Internet Service Provider (ISP) standards for email content. So we will take profit of all those advantages, and make our life more simple and enjoyable. Second, we want a smooth and efficient delivery through concurrent background tasks, seamless for the user and detached from the front-end business logic. Whenever we press the "send" button we expect the system to return a confirmation response immediately — regardless of what's happening in the background — instead of getting the request frozen, waiting too much time for the email queue to be emptied and ending up with a web server timeout response. Celery … -
Useful Packages for Django projects (part 1)
This is the first of a series of posts about which libraries and tools we use for our Django development. Almost every Nomadblue project will have the following packages in their requirements.txt pip file. Probably most of the readers won't find much news here; however, eventually someone can realize he was missing something that could be leveraging their productivity or making life easier. Pillow As stated by the library documentation, Pillow is the "friendly" PIL fork by Alex Clark and Contributors. With Pillow you can stay cool as it installs smoothly using pip, and also you can sleep at night because somebody is maintaining the library in a healthy state through continuous integration, regular releases, bug fixing and development on github, and active participation on the Imaging-SIG. South When we started with Django (more than 5 years so far) there were a bunch of migration libraries out there, with different approaches. Andrew Godwin became a frequent flyer on the Django community, eventually winning the pulse and gathering the Djangonauts until South became a "must" or "de-facto" library to manage your database schema and data transitions. Worth mentioning that Andrew recently applied at kickstarter for a call to develop "a new, … -
Google Analytics tracking code into Django projects, the easy way
Creating a pluggable Django app to just embed the GA code seemed overkill to me, so I created this post as a quick reference for next Django web projects. The idea is creating a system that will add the tracking code under the following conditions: We have provided the ID and domain of our GA configuration. We are not running in settings.DEBUG mode. Settings variables The following settings must be defined on your settings.py. GOOGLE_ANALYTICS_PROPERTY_ID A string containing your ID on GA (e.g. UA-14845987-3). Get it from your configuration page: GOOGLE_ANALYTICS_PROPERTY_ID = 'UA-14845987-3' GOOGLE_ANALYTICS_DOMAIN This means the root domain you registered in Google Analytics. Even if you are configuring a subdomain (e.g. www.mydoamin.com or foo.mydomain.com) you must use the root domain. For instance, mydomain.com: GOOGLE_ANALYTICS_DOMAIN = 'mydomain.com' Context Processor Add this function to your context processors file: from django.conf import settings def google_analytics(request): """ Use the variables returned in this function to render your Google Analytics tracking code template. """ ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_PROPERTY_ID', False) ga_domain = getattr(settings, 'GOOGLE_ANALYTICS_DOMAIN', False) if not settings.DEBUG and ga_prop_id and ga_domain: return { 'GOOGLE_ANALYTICS_PROPERTY_ID': ga_prop_id, 'GOOGLE_ANALYTICS_DOMAIN': ga_domain, } return {} Add the context processor to your settings: TEMPLATE_CONTEXT_PROCESSORS = ( ... 'website.context_processors.google_analytics', ) Template … -
Not a Fan of Django
Hynek Schlawack presents us with some Django criticism while talking with us about static media, test speed, mezzanine theming, a pypi wrapper, logging, markdown docs, interceptors, admin styling, pycon keynotes, and test servers. -
Django on windows: how to make Django run in CherryPy as a Windows service
Recently a client asked me to investigate the possibility to have a Django application hosted in a Windows environment. I looked around a bit and there are many ways to achieve this goal. I found the “pure Python” approach described here simpler to deploy and configure, yet very powerful and production ready for my needs. I will explain how to install Python, CherryPy and Django on Windows, and how to configure them to serve a Django application from the CherryPy WSGI server, running as a Windows service. Table of Contents Install Python 2.7 Install CherryPy CherryPy server started as a Windows Service Install Django Give a powerful DB engine to your Django app: install MySQL! Make your Django project an installable python package Django running in CherryPy as a Windows service Conclusions Install Python 2.7 First of all you have to install the Python programming language support for Windows. I used Python 2.7.5 Windows Installer. Then to be able to invoke the python command from the command line – no matter what the current work directory is – add Python to system path. Go to Control panel > System > Advanced > Environment variables look for path variable, click on … -
Number Theoretic Algorithms – Factorization
In the following series of posts, I will write about some of the number theoretic algorithms that one encounters in most of competitive programming. These are fundamental algorithms which most computer scientist should know. In this post I will post an algorithm and a corresponding JAVA code to perform prime factorization of a give number. The algorithm to perform prime factorization is a very trivial algorithm and mostly encountered by everyone atleast once in their high school. - Iterate for i from 1 to sqrt(n) - While i|n, divide n by i. Report i as a prime factor of n - After the iteration of i from 1 to sqrt(n), if n is a number greater than 1, report that also as a prime factor The key observation is that, this algorithm runs in O(square root (n) ). We are able to iterate only upto sqrt(n) since, we can claim one of the following: 1) n is a prime number or 2) If n has a prime factor p greater than sqrt(n), then there exists a corresponding prime factor p’ lesser than or equal to sqrt(n), such that p*p’ = n If (1) doesn’t hold, it implies that n is … -
Tagging with django-taggit
In this video you will learn an easy way to add tags to your models, and on your site. Tags can be hard if you try to implement them yourself, so don't try and just use this library from the start.Watch Now... -
Ecoscope
Brett Cannon joins us to talk about PyTenessee, performance, cookiecutter, flask foundation, scaling, raw sql migrations, code review, waffling, sockets, pixel tracking, and even cooking. -
Skipping Test DB Creation
We are always looking for ways to make our tests run faster. That means writing tests which don't preform I/O (DB reads/writes, disk reads/writes) when possible. Django has a collection of TestCase subclasses for different use cases. The common TestCase handles the fixture loading and the creation the of TestClient. It uses the database transactions to ensure that the database state is reset for every test. That is it wraps each test in a transaction and rolls it back once the test is over. Any transaction management inside the test becomes a no-op. Since TestCase` overrides the transaction facilities, if you need to test the transactional behavior of a piece of code you can instead use TransactionTestCase. TransactionTestCase resets the database after the test runs by truncating all tables which is much slower than rolling back the transaction particularly if you have a large number of tables. There is also SimpleTestCase which is the base class for the previous to classes. It has some additional assertions for testing HTML and overriding Django settings but doesn't manage the database state. If you are testing something that doesn't need to interact with the database such as form field/widget output, utility code or … -
Guilt Trip
Eric Holscher jumps in to talk about blogging, deployment, the latest community news and project releases, teaching kids to code, and his experiment to support his community contributions through gittip. -
Django Projects
Over the past 6 years, I've built a lot of things with Django. It has treated me very well, and I have very much enjoyed seeing it progress. I got into Django when I helped the company I was working for transition away from a homegrown PHP framework toward something more reliable and flexible. It was very exciting to learn more about Django at a time when the ecosystem was very young. When I started with Django, there weren't a lot of pluggable apps to fill the void for things like blogs, event calendars, and other useful utilities for the kinds of sites I was building. That has changed quite a bit since then. The ecosystem has evolved and progressed like mad, and it's wonderful. We have so many choices for simple things to very complex things. It's amazing! Unfortunately, during this whole time period, my development efforts have shifted from creating my own open source projects to share with the world toward more proprietary solutions for my employers. If it's not obvious to you from my blog activity in recent years, I've become very busy with family life and work. I have very little time to give my open … -
django-waffle
Learn how to use this popular feature flipper for helping you to develop and test new features live instead of only in development.Watch Now... -
Brilliant or Insane?
This week, Kenneth and Brandon are joined by Bryan Veloso. We talk about the several official Django announcements last week, when maintainability should be sacrificed for performance, algorithmic wedding seating, promises (or futures) in concurrent programming, the Django Pony, and more! -
Personal lessons from XOXO
Three things I want to remember from XOXO, written in haste as the conference wraps up: Optimism XOXO is so un-snarky, so radically honest and sincere, that it almost feels like another world. XOXO is an amazing departure from that. The sincerity and friendliness is so total, so comfortable. A number of speakers shared intensely personal moments: Marco called his talk a “group therapy session” and discussed his fear and insecurity; Cabel shared a story of depression that was heartfelt and resonant. -
How to Create a File Upload Widget
Ajaxified file uploads are becoming de facto standard on the web. People want to see what they chose right after selecting a file instead of during submit of the form. Also if a form has validation errors, nobody wants to select the files again; the selection made should be still available in the form. Therefore, we need a solution that works by Ajax. Luckily there is a Django app that can help. It's called django-ajax-uploader. Ajax uploader allows to create asynchronous single and multiple file uploads. All uploads are done into the uploads directory. In addition to the default functionality we need a possibility to show the preview of the temporary uploaded file, translate all messages and buttons, delete a file, move a file to a specific directory. I created a demo project which implements all that. If you have a ModelForm with a FileField or ImageField, you need to not show this field in the form, but instead to add a hidden field for uploaded file path. When you choose a file, it will be uploaded to a temporary uploads directory and its path will be set in the hidden field. Also you need a hidden BooleanField for the … -
First thoughts about Django-CMS
I just set up a site using Django-CMS over at Pomme d'Api Preschool. Overall, I am pretty impressed. I really like the Django admin interface enhancements as well as the site overlay editing feature. One of the best things it he use of django-filer, a file management tool to manage all the uploads to the site. It's awesome and it makes me want to throw out this home page completely and switch over to Django-CMS. Image handling in Drupal has always sucked and still does. The fact that there was no official media/image handling in Drupal 6 sucks, and it's made worse by the fact that there is no real upgrade path to Drupal 7 for media/images, especially if you're like me and you used the "Image" and "image-assist" modules, two of the most popular modules dealing with images. Django-CMS is pretty powerful and so far it has allowed me to do pretty much anything I have wanted to do. -
Central logging in Django with Graylog2 and graypy
.. |--| unicode:: U+2013 .. en dash .. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace :trim: Django's `logging configuration `_ facilities, which arrived in version 1.3, have greatly eased (and standardized) the process of configuring logging for Django projects. When building complex and interactive web applications at Caktus, we've found that detailed (and properly configured!) logs are key to successful and efficient debugging. Another step in that process |---| which can be particularly useful in environments where you have multiple web servers |---| is setting up a centralized logging server to receive all your logs and make them available through an easily accessible web interface. There are a number useful tools to do this, but one we've found that works quite well is `Graylog2 `_. Installing and configuring Graylog2 is outside the scope of this post, but there are plenty of tutorials on how to do so accessible through your search engine of choice. Once you have it setup, getting logs flowing to Graylog2 from Django is relatively straightforward. First, grab a copy of the ``graypy`` package from PyPI and add it to your requirements file:: pip install -U graypy Next, add the following configuration inside the ``LOGGING['handlers']`` … -
Django Round-Up #10
This week we're joined by Portia Burton! We discuss Portland, Mozilla Persona, making a game board, migrations and South's frozen ORM, Bee Ware and GUI tools vs. the command line, clever comprehensions, and a whole lot more.