Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Catching up Before the End
It's funny, I've had mountains of "free" time lately and somehow, none at all available to do the simplest of cumulative tasks. I've not replied to the nineteen emails sitting in my inbox, and keeping this site up to date has clearly not been a priority. However, in an effort to "clean house" so to speak before the New Year, I'll try to cover everything here. If you like to read everything, I suggest taking a moment to procure a beverage. Carolling: A Reunion Way back in October, I received a text message from my old friend Michelle containing a request to re-capture some of our better memories by going carolling this year, an annual tradition we once supported by hadn't attempted for nearly a decade. Excited at the thought of it, I agreed to play my role and she recruited Gary (another old friend) and a Soprano friend of theirs for the task. I did some digging of my own and managed to coax Merry out as well and with a group of five very out-of-practise choir folk, we set out on December 19th to bring some Christmas cheer to the suburbs. The whole thing didn't go off nearly … -
Outsourcing Revisited And No One Is Safe
The recent article Outsourcing Killed By Django And Ruby On Rails has caused as much proper debate as it has blind controversy. The feedback provided by readers here as well as other sites like Y Combinator and Reddit have brought up some good points. If I had to write the article again here [...] -
How I set up my development Mac
Starting a new job means setting up a new computer. With a clean slate, a blank canvas, a fresh start, if you will, I decided to document what I really need and use. MacBook Pro I haven’t used a desktop Mac since the late 90’s. My laptop goes everywhere with me. Of course, I have never, ever, used a Windows computer as my primary machine. Developer Tools The Apple developer tools come on a separate DVD and need to be installed. Don’t much care for XCode, but all the low level compilers are there. If you want to compile something from source, you’ll need them. Firefox Safari is nice, but for any type of real web development, you need Firefox, and a few extensions. Required extensions: Firebug: I can’t say enough about what this extension can do. Developing web sites would be so frustrating without it. My favorite features are the JavsScript console and CSS editing. Web Developer: My favorite usage of this addon is the ability to view the JavaScript-generated source code of a page. Typically Firefox will only show you the source of a page as it came from the server. Quartz PDF: One thing I miss about Safari is the ability to view … -
Web Statistics Shortcoming
I recently read about django-webalizer http://github.com/arneb/django-webalizer/tree/master I decided to set it up. I'd never really cared to analyze my log files before. I set up webalizer, and it was great. The django-webalizer app provides a good interface for my statistics. I'll definitely include it for any freelance work I might do in the future. When I ran webalizer on my site for the first time, I realized there were a couple broken links, and I noticed there were some things I could do to better my site. I don't use a favicon, so I had several hundred 404s in my log. I also analyzed logs for a public facing site at work, and fixed quite a few things. This was good, but all those errors that happened at the beginning of the month have been taken care of. webalizer doesn't have an option where I can generate a report from the last 24 hours. A report like that is useful because I can see what is happening with my websites now. I decided to look into other open source log analyzers. I haven't looked super hard, but it seems like awstats and webalizer are the two super active log analyzer … -
Users and the admin
So, for as long as I can remember the single most-frequently-asked question about the Django admin has been some variation of “how do I set a foreign key to User to automatically be filled in with request.user?” And for a while the answer was that you couldn’t do that, really; it was and still is easy to do with a custom form in your own view, but up until a few months back ... Read full entry -
Users and the admin
So, for as long as I can remember the single most-frequently-asked question about the Django admin has been some variation of “how do I set a foreign key to User to automatically be filled in with request.user?” And for a while the answer was that you couldn’t do that, really; it was and still is easy to do with a custom form in your own view, but up until a few months back ... Read full entry and comments -
Markdown w/ Pygments: Round 2
Dig back into my vast blog archive and you will find this post: I said it, I did it. Therein you will find my bumbling, ham-fisted solution for integrating pygment code highlighting into markdown. I just wandered back past this code today and then stumbled across the actual right way to do this. Quoth me: Pygments as [sic] a markdown pre-processor. Ideally one would be able to just pass this through as an extension to markdown using the functionality in the existing template tag. Unfortunately, pre-processors seem to be a different sort of animal. In the end I couldn't keep things very DRY. Well, I was half right. Introducing this extra functionality via an extension is the ideal solution. But pre-processors are only different from extensions in that they're just one of kinds of things you can enable via extensions. I've righted past wrongs. Here is the proof, in diff form: --- /dev/null+++ b/build/site/lib/mdx_pygments.py@@ -0,0 +1,9 @@+import markdown+from pg_md_processor import CodeBlockPreprocessor++class PygmentsExtension(markdown.Extension):+ def extendMarkdown(self, md, md_globals):+ md.textPreprocessors.insert(0, CodeBlockPreprocessor())++def makeExtension(configs=None):+ return PygmentsExtension(configs=configs)--- a/build/site/pocketuniverse/pygmented_markdown/templatetags/pygmented_markdown.py+++ /dev/null@@ -1,64 +0,0 @@-from django import template-from django.conf import settings-from django.utils.encoding import smart_str, force_unicode-from django.utils.safestring import mark_safe--from markdown import Markdown--from pg_md_processor import CodeBlockPreprocessor--register = template.Library()--@register.filter-def markdown(value, arg=''):- """- … -
Wszystkiego najlepszego wszystkim miłośnikom Django
Wesołych Świat Bożego Narodzenia, oraz szczęśliwego Nowego Roku 2009 życzy, zespół Taulab. Podzielcie się z nami opłatkiem wchodząc na stronę: http://podzieloplatek.pl/TAULAB/. Zostawcie po sobie życzenia ;). -
Django Site of the Week - Ooh-Ga-Boo-Ga
For the second Django SOTW, I had a chat to Bruce Kroeze about one of his Satchmo projects, Ooh-Ga-Boo-Gah. It's a great match of cool design and technical wizardry. For the un-initiated, Satchmo is one of Django's 'killer apps', providing an e-commerce platform that enables Django-powered shopping sites to be built with ease. Bruce is on the core development team and was able to provide us with a great insight into the project. You can read the interview now. Note: Due to Christmas and New Years, there will be no Django SOTW next week. We'll return on January 3rd, 2009. Have a great holiday season! -
Django Site of the Week - Ooh-Ga-Boo-Ga
For the second Django SOTW, I had a chat to Bruce Kroeze about one of his Satchmo projects, Ooh-Ga-Boo-Gah. It's a great match of cool design and technical wizardry. For the un-initiated, Satchmo is one of Django's 'killer apps', providing an e-commerce platform that enables Django-powered shopping sites to be … -
Announcing django-swingtime
Announcing django-swingtime -
Outsourcing Killed By Django And Ruby On Rails
The absolute pinnacle of outsourcing madness peaked with the publication of “The 4 Hour Workweek” by Timothy Ferriss. The book was a Bible for starting your own sweat shop. Everyone from one man startups long forgotten to mega corporations like Ebay were looking to India, China, and eastern Europe to cut development costs. [...] -
Moving Data from One Database to Another with Django
So I have a django database I'm working on and I decided I wanted to do the development in sqlite3 instead of mysql. I decided to do this because it makes it easier, for example, to have someone else work on HTML/CSS if I can just give them a directory, tell them to run a bash script and go to http://localhost:8000, rather than them having to do all that AND setup a mysql server. Sure, that can also be done with a script, but with sqlite things are just a hell of a lot easier in some ways. I decided I wanted to take the data out of my mysql database and load it into a sqlite db. Not so simple, you can't just take an SQL dump from mysql and import it into sqlite3. I started Googling around for "mysql to sqlite" and didn't really get anywhere. I then realized that Django can already talk to sqlite and mysql transparently without me having to know any SQL. So I thought about writing my own python modules to do this, but it turns out someone has already done it. The django-extensions project has a manage.py command called "dumpscript" that "Generates … -
Dynamic ModelForms in Django
For an ongoing project I am implementing basic advertising functionality, where I define a number of positions in the page and advertisers can self-serve to create an advertisement to fit those positions. Each 'Position' can have different attributes turned on or off. For example, a 'sidebar' ad may permit an image and link text, however a 'footer' ad may only contain link text. When the user creates their own ad, I wanted a single form that morphed itself based on the Position being used so that fields were enabled or disabled, and made mandatory as required. To get started, here are excerpts from the two models I'll use to demonstrate how I achieved this: # models.py from django.db import models class Position(models.Model): title = models.CharField(max_length=100) description = models.TextField() has_title = models.BooleanField(blank=True, null=True) has_summary = models.BooleanField(blank=True, null=True) has_link = models.BooleanField(blank=True, null=True) has_image = models.BooleanField(blank=True, null=True) class Advertisement(models.Model): position = models.ForeignKey(Position) internal_name = models.CharField(max_length=150) image = models.ImageField(upload_to=ad_image_path, blank=True, null=True) link_url = models.URLField(blank=True, null=True) link_text = models.CharField(max_length=100, blank=True, null=True) ad_text = models.CharField(max_length=100, blank=True, null=True) The trick here is to ensure that when creating an Advertisement, the image, link_url, link_text and ad_text fields are turned on and off based on the related Position. First … -
Dynamic ModelForms in Django
For an ongoing project I am implementing basic advertising functionality, where I define a number of positions in the page and advertisers can self-serve to create an advertisement to fit those positions. Each 'Position' can have different attributes turned on or off. For example, a 'sidebar' ad may permit an … -
Clarification for Confusion: Creating New Django Fields. Part 1
Let's say you've just published your first Django-based project. You've learned a lot, you know how to create a new app, views, forms, middleware, and template tags. That's cool, but there is still much space for making your code cleaner and better-organized. One of such improvements could be joining multiple fields into a single field.To be clear, there are several types of fields in Django web development and all of them are related to each other. First of all, there are the fields of database tables in the lowest level. Then there are model fields representing the database fields in python. Form fields go on top in the abstraction level. Then there are bound fields which bound the form fields with data from the database (or somewhere else). And finally there are HTML fields which represent the rendered bound fields and which can be spiced up with Javascript for creating new widgets.Now imagine, that you have a Contact model which includes two phone numbers where each of them has three parts. They are the country code, area code, and the serial number. In the simplest case you would have something like this:COUNTRY_CODE_CHOICES = getattr(settings, "COUNTRY_CODE_CHOICES", ( ("+44", "United Kingdom (+44)"), … -
Django Site of the Week
Since I started DjangoSites over a year ago, the response has been fantastic. I used to approve a handful of websites a week, recently it's more like a half-dozen a day. I've decided that a bunch of those websites are just awesome, and I wanted to have a chat with the owners of those sites and share their stories with the Django Community. Most larger or more unique stories have a story behind them, and the experiences of the team building them are vary from project to project. Upon approaching the owners of a number of cool websites powered by Django, I received great feedback and enthusiastic responses. So far there are a few weeks of interviews ready to be published, with more on the way. The first website we've featured is Disqus, a hosted comment engine that can be used on any blog or website for free. It's an interesting website, and Daniel Ha (one of the founders) was very helpful in answering my questions and helping to share his experiences with Django. Each weekend, another interview will be published. You can subscribe to the RSS feed to be automatically alerted to new websites, however I suggest you visit … -
Django Site of the Week
Since I started DjangoSites over a year ago, the response has been fantastic. I used to approve a handful of websites a week, recently it's more like a half-dozen a day. I've decided that a bunch of those websites are just awesome, and I wanted to have a chat with … -
Diário 0.2 out! The Alexandros Grigoropoulos's Diary Release
Today was released the Diário version 0.2, blog application for Django projects, packaged from revision 181 in Subversion. New in version 0.2: Django 1.0.X compatible; Support to ping weblog directories (issue #11); Changed license to LGPLv3 (issue #36); Some code refactoring; Removed deprecated features; Many bug fixes; Other enhancements. Diário 0.2 too will be packaged to Debian by Lincoln Sousa and be available in main Debian repository. Help us to improve Diário! See the Roadmap for version 0.3. Thanks to everyone who made this release possible! This version is a tribute to Alexandros Grigoropoulos, 15-year-old boy, libertarian, murdered by greek police in last week (2008-12-06). -
Enhancing Django comments admin with django-batchadmin
So, I'm making headway against comment spam, but still accumulating a bunch of comments that are suspicious enough to mark for review, but not bad enough to reject out of hand. The find, delete, confirm delete cycle in the admin interface is tiresome. Enter django-batchadmin. -
Django fulltext search -- part 1
I have been recently working on adding full text search to a django based web application since this is not yet particularly well documented. Here it is my little stone to the amazing pyramid already in place waiting for you to use it. In order to add this "must have" feature to your great web application you will need 3 components :djangosearchpysolrsolrStarting by the latest the first challenge is to get it installed, I haven't had luck with the usual "apt-get install solr". It must be me but after an installation I was only getting a blank page instead of solr admin interface. On #solr channel someone advise me to just grab the latest release tar ball and to run with it. Then I have performed the tutorial this help me a lot to get started with solr. Believe it or not when you are there you have done the hardest part of it.Now you need to go inside the django project you want to work on and follow the following recipe :download and put into your PYHTONPATH djangosearch and pysolrAdd djangosearch inside the INSTALLED_APPS tuppleadd the following settings :SEARCH_ENGINE = "solr" # solr, lucene, xapian, estraierSEARCH_RESULTS_PER_PAGE = 10SOLR_URL= "http://localhost:8983/solr"At … -
Testy
Anyone attempting to dip into my modest archive this morning would have seen an error message instead. (And yes, the error page itself isn't getting styled properly. One thing at a time, people!) I discovered a bug in how my archive_month view was working and I fixed it. And in the process I opened a much worse bug. This is one of the classic narratives, along with "boy meets girl", "stranger comes to town" and the rest. Here's the way the view looked this morning: def archive_month(request, year, month, category_slug=None): queryset = BlogPost.objects.public_posts() if category_slug: category = get_object_or_404(Category, slug=category_slug) queryset = queryset.filter(category=category) return date_based.archive_month( request, year=year, month=month, month_format="%B", date_field='pub_date', queryset=queryset, template_object_name='blogpost', extra_context={'category': category, 'preview': True} ) So close... Now, here it is, with the fix: def archive_month(request, year, month, category_slug=None): queryset = BlogPost.objects.public_posts() if category_slug: category = get_object_or_404(Category, slug=category_slug) queryset = queryset.filter(category=category) else: category = None return date_based.archive_month( request, year=year, month=month, month_format="%B", date_field='pub_date', queryset=queryset, template_object_name='blogpost', extra_context={'category': category, 'preview': True} ) Now category is always set, whether it's to a Category object or to None. No more "UnboundLocalError: local variable 'category' referenced before assignment". But when I realized I was going to post my fix, I also realized I would have … -
SmartyPants in Django Templates
John Gruber’s SmartyPants script is a great tool for converting a body of text into a more typographically correct and visually appealing version. Chad Miller’s Python port makes it really easy to implement this functionality as a template tag, but I wanted to take it a step further and use SmartyPants as a Markdown pre-processor, just as I did with Pygments. The solution is actually very simple, but the actual RegEx required to do the job took me a bit of time to put together. The problem was to properly ignore code blocks and apply the SmartyPants filter on all areas outside the code examples. Here is the final Markdown pre-processor that I came up with: class SmartyPantsPreprocessor(TextPreprocessor): """ A Markdown preprocessor that implements SmartyPants for converting plain ASCII punctuation characters into typographically correct versions """ pattern = re.compile(r'(.+?)(@@.+?@@end|$)', re.S) def run(self, lines): def repl(m): return smartyPants(m.group(1)) + m.group(2) return self.pattern.sub(repl, lines) The pattern looks for every piece of text that comes before a text block or before the end of the content, then filters the first part through SmartyPants, and passes the code blocks as they are. Finally, I make sure to register this processor before my Pygments pre-processor: … -
django-registration
This will be about (bad?) documentation.Im in process of making small database inferface in django with few additional functions. I need to register people. This is the place where django-registration kicks in, I choose it to cut development time and to not reinvent the wheel.Basic setup of django-registration is a breeze, but when it gets to template creation it gets worse. Information about context variables passed to the templates is hid among the rest of documentation. I found easier to dig it out from the code rather than from documentation. It could be so beautiful if it was included in overview.txt (in "Templates used by django-registration" section specifically). I know that it is not much but it could be easy 5 minutes of setting up django-registration instead of 15 minutes poking with code and other documentation.Fortunately I wont moan more but do something productive instead and produce better documentation ;) I know that in a week I will not remember which template takes which parameter and first place I'll be looking in is documentation. So here we go:The views included in django-registration make use of five templates:* ``registration/registration_form.html`` displays the registration form for users to sign up. Gets ``form`` in … -
Clearing Django Form Fields One By One
I just spent an hour looking all over the web for something everyone assumes everyone else already knows. If you’re new to Django and you’re trying to clear a form field on validation then the solution is not intuitive. Take a common scenario, you have a CAPTACHA image and the user enters it incorrectly, next [...]