Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Feature Switches in Django with Gargoyle
-
Mailing list for Disqus open source projects
A couple of weeks ago we launched our engineering blog and project site where we aggregate our engineers’ blog posts and list open source projects we maintain. Since then, we released two more projects — feature switches platform called Gargoyle and a pluggable Django app called Nexus. And to... -
Feature Switches in Django with Gargoyle
A while back we talked about using feature switches to deal with partial deployment. This allows you to easily deploy to portions of your audience, or bring out less finalized features without hiding them behind branches and the likes. This last week we hosted a company hack day here at DISQUS, a... -
Redirect to the originally requested page after django registration and email activation
For my newly-launched, django-based social shopping site Wantbox.com, I have implemented @ubernostrum‘s ubiquitous django-registration 0.7 to handle user registrations. Recently I completed a Wantbox feature that required me to redirect a new user back to their initially requested, authorization-required page after their registration and email activation. Below are the step-by-steps actions I took to accomplish this. Step One: Pass the “next” parameter from the login form to the registration form When a user requests a view adorned with the “@login_required()” decorator, Django automatically checks if that user “is_authenticated()” and redirects them to your login form if they are not. You’ll notice that there is a “?next=/foo/bar/” parameter tacked onto the end of the login page URL so you can send the use back to the requested page upon login. In my case, the user needs to register, not log in, so my first step was to pass this “next” parameter to the registration form. Under my login form I added this link: Not a member yet? <a href="{% url registration_register %}?next={{ request.REQUEST.next|urlencode }}">Sign up here</a> Step Two: Modify the registration form On your registration form, add a hidden input field to store the “next” parameter that you just passed in … -
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
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
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 … -
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...