Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
BitField's in Django
Today we're releasing another heavily used component from the DISQUS code base, our BitField class. While not a true BIT field (it uses a BIGINT), it still allows you the convenience of accessing the values as if they were bit flags. When I joined DISQUS about 7 months ago, we were using a Q-lik... -
Facebook aided registration in Django
How to use new Facebook registration tool to show and handle a registration form with data prepopulated from a Facebook account. -
Merry Christmas
Merry Christmas and a happy 2011, everyone! Actually we wanted to finish a little present, but December was just too full with other stuff. Looks like Thomas will have to play Santa in January. ;) This blog started more or less one year ago. Back then we still were on a blogspot subdomain. A few months later Django-nonrel was ready for hosting a simple site, so we moved everything on a custom domain (allbuttonspressed.com) hosted on App Engine with Django-nonrel. Now this blog has more than 700 subscribers and we really need to get some feedback from you, so we can improve our articles in 2011. Please help us by filling out this short survey. Thanks a lot! Have a nice Christmas and a successful 2011. Leave a comment -
A stateful problem
So, this week we dropped some security updates, which you should definitely check out if you haven’t seen them yet. We also released the first 1.3 beta, which is an important milestone since it means 1.3 is now feature-frozen and will get only bugfix and polishing work until the final release. Quite a few useful things made it in between alpha and beta, and a couple just barely slipped in under the wire. One ... Read full entry -
django-anonymizer released
An app to help protect your customers' data when in development. -
A stateful problem
So, this week we dropped some security updates, which you should definitely check out if you haven’t seen them yet. We also released the first 1.3 beta, which is an important milestone since it means 1.3 is now feature-frozen and will get only bugfix and polishing work until the final release. Quite a few useful things made it in between alpha and beta, and a couple just barely slipped in under the ... Read full entry -
Django model migrations with South: how-to migrate ForeignKey relation to ManyToMany
Yesterday I had an non-trivial for newbie South user issue: I need to migrate a big database table with existing FK relations to M2M relations and keep in safety all of existing data during migration.So, I hadn't figure out in documentation how I can do it without handmade migration code in forward method. Below I described how I've fixed it:1. Here is my initial model (sample), my application called app1class TestData(models.Model): field1 = models.CharField(max_length=200) field2 = models.CharField(max_length=200)class Knight(models.Model): name = models.CharField(max_length=100) additional_field_new_name = models.CharField(\ max_length=155, default='') data = models.ForeignKey(TestData)2. I've added new column data_new to Knight model with M2M relation to TestData:data_new = models.ManyToManyField(TestData, \ related_name='testdata_info')3. Start schema migration:python manage.py schemamigration app1 --auto4. Change forward method in our new migration, code after creation of new column/proxy model:for obj in orm.Knight.objects.all(): obj.data_new.add(obj.data) obj.save()5. Make migration:python manage.py migrate app16. Remove column data from model and make migration; rename m2m column data_new to data and start schema migration# remove column "data" from modelpython manage.py schemamigration app1 --autopython manage.py migrate app1# rename m2m column from "data_new" to "data"python manage.py schemamigration app1 --auto7. At this point I need to keep all existing data in proxy table but South won't do that for me. So, I need to change … -
An easy Django ForeignKey performance +1
Today, Christophe Pettus wrote about an easy way to get better database performance from a ForeignKey reference. Don’t do: pub_id = b.publisher.id Do do: pub_id = b.publisher_id After you read his post, you’ll think, “But of course!” Joe Bob says check it out. Tagged: Django -
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
-
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