Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Using Munin to monitor trends on a Django site
A common requirement is to track changing trends: are visitors signing up? Has there been a sudden spike in forum posts? After spending some time rolling out my own solutions, I suddenly woke up and realised that I could use Munin to produce graphs like this: -
Keep synced production media files with your development environment- the "dirty" way
As I wrote in previous post, it's really problem personally for me to keep synced media between dev and production environment. I don't examine cases when on production available really a lot of data.So,Copy user-related media files – usually solved via ignore files, symlinks etc. but there is NO STANDARD or SOLUTION - UnsolvedQuick and dirty solution:# 1) go to parent folder of your # static_media (usually project's root folder)# 2) executersync -avzu -e ssh mylogin@remotehost:~/path/to/static_media ./ And execute it every time you need have synced media files with your remote host. Update: I've hacked previous version of script to exclude files which already in git repo.rsync -avzu echo `git ls-files | \ grep static/ | \ xargs -I file echo --exclude="file"` \ -e ssh mylogin@remotehost:~/path/to/static_media ./ -
Extending Django CMS Page model – part II
… or how to use the extended model in your templates and especially in the built-in navigation The problem: As you can see in the previous post there is a very simple way to extend the page model with some custom fields without changing the core code. But how to use your custom fields inside [...] -
Tweaking Django exceptions with custom middleware
When settings.DEBUG is set to False, exception tracebacks will be sent to settings.ADMINS. To make it simpler to track down how and why the exception was raised, it's beneficial to know which user caused the exception. It's quite simple to do this using some custom middleware. In the Hub, we include the associated users email address in the exception with the following: settings.py MIDDLEWARE_CLASSES = ( ... 'hubutils.middleware.ExceptionMiddleware', ) hubutils/middleware.py class ExceptionMiddleware(object): def process_exception(self, request, exception): """include authenticated user email in request.META""" if request.user.is_authenticated(): request.META['USER_EMAIL'] = request.user.email -
Tweaking Django exceptions with custom middleware
When settings.DEBUG is set to False, exception tracebacks will be sent to settings.ADMINS. To make it simpler to track down how and why the exception was raised, it's beneficial to know which user caused the exception. It's quite simple to do this using some custom middleware. In the Hub, we include the associated users email address in the exception with the following: settings.py MIDDLEWARE_CLASSES = ( ... 'hubutils.middleware.ExceptionMiddleware', ) hubutils/middleware.py class ExceptionMiddleware(object): def process_exception(self, request, exception): """include authenticated user email in request.META""" if request.user.is_authenticated(): request.META['USER_EMAIL'] = request.user.email -
Tweaking Django exceptions with custom middleware
When settings.DEBUG is set to False, exception tracebacks will be sent to settings.ADMINS. To make it simpler to track down how and why the exception was raised, it's beneficial to know which user caused the exception. It's quite simple to do this using some custom middleware. In the Hub, we include the associated users email address in the exception with the following: settings.py MIDDLEWARE_CLASSES = ( ... 'hubutils.middleware.ExceptionMiddleware', ) hubutils/middleware.py class ExceptionMiddleware(object): def process_exception(self, request, exception): """include authenticated user email in request.META""" if request.user.is_authenticated(): request.META['USER_EMAIL'] = request.user.email -
Django Hides (some) Widget Exceptions
If you write any custom Django widgets or admin list_display callable functions you have probably run into this: Everything looks ok, except the place where your widget should be is just blank. Nothing. No traceback or any clue as to what went wrong. It seems that Django suppresses all the exceptions sent by widgets rendering except for AssertionError and TypeError. Debugging under those conditions is tricky, so I wrote a function decorator to help. Just import this and put @assert_on_exception before your render method or admin list_display callable function: def assert_on_exception(fn): import sys def wrap(*args, **kwargs): try: return fn(*args, **kwargs) except (AssertionError, TypeError): raise except: raise AssertionError(sys.exc_info()[0].__name__ + ": " + str(sys.exc_info()[1])) wrap.__name__ = fn.__name__ wrap.__dict__.update(fn.__dict__) wrap.__doc__ = fn.__doc__ wrap.__module__ = fn.__module__ return wrap -
Extending Django CMS Page Model
… or how to add some fields to the Page model in the admin without changing Django CMS core The problem: Some times the Page model just lack of something you need. In my case this was “page avatars”. Long story short – I needed an image/avatar for each page in my CMS. So what [...] -
nicEditor in Django
Integrating BBCode editing, image upload and other nicEdit features with Django -
On overriding toJSON
Last week, we quietly1 rolled out an update that swapped our intramural library for cross-domain communications with easyXDM. We decided in favor of easyXDM simply because it is very well tested and supports more browsers (Firefox 1 anyone?) than the one we built. The integration process was not ... -
jQuery template syntax coloring for Vim 7.1+
We’re using the jQuery template plugin at Disqus for several of our pages, and it waas getting annoying that Vim wouldn’t properly highlight parts of the template language. As such, I’ve created a fairly small and rudimentary syntax file for Vim 7.1+ that will color some basic elements of ... -
Announcing the DISQUS Code Blog
Yesterday we semi-silently launched our engineering blog and project site over at DISQUS. We're going to be aggregating posts from all of the engineering team's personal blogs, as well as putting all of our open source projects and conference coverage over there. Look for all of the juicy details... -
Announcing the DISQUS Code Blog
-
Django PositiveNormalizedDecimalField
Some weeks ago I was working on a Django project that was using some FloatFields where they should not be used, the database backend was Postgres 8.4. If you are not aware of it, FloatFields are turned into double precission types, that means 64-bit floating-point numbers. Those fields were storing values that didn’t need such precission. For example I don’t think you need them to store items’ weights, do you? I migrated those fields to DecimalFields using an average (max_digits=7, decimal_places = 2), which means a total of 7 digits, with 2 decimals. Of course I had to migrate the database, doing some manual alters, as Django-south was not being used. By default DecimalFields render the number with all its decimal digits, which was not what I was looking for. I needed a decimal field that: By default render decimal values normalized using non-scientific notation. See Decimal("10.400").normalize() Only allowed positive values I could have used floatformat built-in filter, but that would have supposed to change hundreds of different templates. Even though grep and sed are a big allies, the process would be quite error prone. I simply needed a centralized solution. Obviously It was time to create a custom model … -
Django PositiveNormalizedDecimalField
Some weeks ago I was working on a Django project that was using some FloatFields where they should not be used, the database backend was Postgres 8.4. If you are not aware of it, FloatFields are turned into double precission types, that means 64-bit floating-point numbers. Those fields were storing values that didn’t need such precission. For example I don’t think you need them to store items’ weights, do you? I migrated those fields to DecimalFields using an average (max_digits=7, decimal_places = 2), which means a total of 7 digits, with 2 decimals. Of course I had to migrate the database, doing some manual alters, as Django-south was not being used. By default DecimalFields render the number with all its decimal digits, which was not what I was looking for. I needed a decimal field that: By default render decimal values normalized using non-scientific notation. See Decimal("10.400").normalize() Only allowed positive values I could have used floatformat built-in filter, but that would have supposed to change hundreds of different templates. Even though grep and sed are a big allies, the process would be quite error prone. I simply needed a centralized solution. Obviously It was time to create a custom model … -
Leaving NASA
This has been a hard post to write. I was delighted that on January 3rd, 2005 I started my first day working for the National Aeronautics and Space Administration (NASA). While I wasn't working on science efforts, I was at least contributing to the cause. In 2005 I was introduced by co-worker Chris Shenton to Python, which became my favorite programming language ever. I also learned tools like Zope, Plone, and Django. Over the past five years, I've met a lot of fascinating people in and around the agency, a list that seems endless in size and scope. That includes astronauts, scientists, engineers, developers, managers, and so much more.This meant so much to me, and maybe because my first memories of television as a child were the moon landings of the early 1970s. I dreamed as a child of being an astronomer or astronaut, and sometimes I plot how I would redo my life to fit these dreams if I got a second childhood.In the past year I've had some incredible opportunities present themselves to me. I've been presenting frequently on Django and Pinax. I've had the singular honor of writing course material for Holdenweb, LLC on behalf of the … -
Speeding up Django unit test runs with MySQL
Here are a couple of tips to speed up unit test runs on Mac OS X and Linux when running MySQL. -
Speeding up Django unit test runs with MySQL
When I'm developing Django sites, my database of choice is usually PostgreSQL. However, lots of clients use MySQL. And there lies a problem: table creation on MySQL seems to be an order of magnitude slower on Mac OS X than on Linux. This makes repeated unit test runs extremely painful. I researched this a little bit a while ago, and noticed that it had been reported as a bug in the MySQL tracker. At the time, there were no fixes or workarounds. A recent update, however, has revealed the use of the skip-sync-frm option. Put it in your MySQL config file in the [mysqld] section for a quick speedup: [mysqld]default-table-type=innodbtransaction-isolation=READ-COMMITTEDdefault-character-set=utf8skip-sync-frm=OFF Of course, nothing in this life is free, as Daniel Fischer explains in a comment: The reason why it's slower on Mac OS X than on Linux is that on Mac OS X, fcntl(F_FULLFSYNC) is available, and mysqld prefers this call to fsync(). The difference is that fsync() only flushes data to the disk - both on Linux and Mac OS X -, while fcntl(F_FULLFSYNC) also asks the disk to flush its own buffers and blocks until the data is physically written to the disk.In a nutshell, it's slower because … -
Speeding up Django unit test runs with MySQL
When I'm developing Django sites, my database of choice is usually PostgreSQL. However, lots of clients use MySQL. And there lies a problem: table creation on MySQL seems to be an order of magnitude slower on Mac OS X than on Linux. This makes repeated unit test runs extremely painful. I researched this a little bit a while ago, and noticed that it had been reported as a bug in the MySQL tracker. At the time, there were no fixes or workarounds. A recent update, however, has revealed the use of the skip-sync-frm option. Put it in your MySQL config file in the [mysqld] section for a quick speedup: [mysqld]default-table-type=innodbtransaction-isolation=READ-COMMITTEDdefault-character-set=utf8skip-sync-frm=OFF Of course, nothing in this life is free, as Daniel Fischer explains in a comment: The reason why it's slower on Mac OS X than on Linux is that on Mac OS X, fcntl(F_FULLFSYNC) is available, and mysqld prefers this call to fsync(). The difference is that fsync() only flushes data to the disk - both on Linux and Mac OS X -, while fcntl(F_FULLFSYNC) also asks the disk to flush its own buffers and blocks until the data is physically written to the disk.In a nutshell, it's slower because … -
Speeding up Django unit test runs with MySQL
When I'm developing Django sites, my database of choice is usually PostgreSQL. However, lots of clients use MySQL. And there lies a problem: table creation on MySQL seems to be an order of magnitude slower on Mac OS X than on Linux. This makes repeated unit test runs extremely painful. I researched this a little bit a while ago, and noticed that it had been reported as a bug in the MySQL tracker. At the time, there were no fixes or workarounds. A recent update, however, has revealed the use of the skip-sync-frm option. Put it in your MySQL config file in the [mysqld] section for a quick speedup: [mysqld]default-table-type=innodbtransaction-isolation=READ-COMMITTEDdefault-character-set=utf8skip-sync-frm=OFF Of course, nothing in this life is free, as Daniel Fischer explains in a comment: The reason why it's slower on Mac OS X than on Linux is that on Mac OS X, fcntl(F_FULLFSYNC) is available, and mysqld prefers this call to fsync(). The difference is that fsync() only flushes data to the disk - both on Linux and Mac OS X -, while fcntl(F_FULLFSYNC) also asks the disk to flush its own buffers and blocks until the data is physically written to the disk.In a nutshell, it's slower because … -
Tracking changes to fields in Django
-
Tracking changes to fields in Django
A common practice we have used over at Disqus is tracking changes on a model (explicitly) in order to determine if certain actions need to take place when that instance is updated. We tend to use it like "if changed" database triggers. This has been very useful in situations like marking a commen... -
Reactions to "Stupid Template Languages"
My blog post on Stupid Template Languages has had some excellently crafted responses by Armin Ronacher, Mike Bayer, and Steve Holden. I respect and admire each of these developers, and their combined projects have made a real impact on my career. I'm happy that our community is large enough to have a difference of opinion, delighted that our base language of Python allows us the power to play with different options so easily, and hope that we can debate our differences of opinion this year at PyCon. The first round of drinks are on me!Response of Armin Ronacher, creator of Jinja2 and other projectsResponse of Mike Bayer, creator of Mako and SQL AlchemyResponse of Steve Holden, Chairman of the Python Software Foundation and creator of PyCon -
Django forms ChoiceField with dynamic values…
… or how to get a dynamic drop-down list with Django forms The problem: Lets say that you need a form with a drop-down list that have dynamic values. With Django this can be done simple and fast, but if you are new you may get yourself into a trap. In a standard form(with static [...] -
chrisdickinson’s wilson at master – GitHub
chrisdickinson’s wilson. Einen noch vor dem Mittagessen, denn das Framework orientiert sich stark an Django, und da ich ja Django-Fan bin, ist das sicherlich einen eigenen Link wert.