Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django error notification with jabber
Django has a code error notifications mechanism when a view raises an exception. It will email the people in ADMIN tuple(settings documentation) in settings.py with the full exception information and displays the default 500.html template. This only happens when DEBUG=False in the settings.py. It's possible to set a handle that change this behavior with a handler500 variable in the root urls.py. So, we can easily write a simple view that sends an error notification to our jabber account. First of all, you need to install xmpppy and dnspython: $ easy_install xmpppy $ easy_install dnspython Add to settings.py the jabber parameters such as the jabber id, password, recipient, etc.: JABBER_ERROR_NOTIFICATION = True JABBER_ID = 'your_jabberid@jabberdomain.com' JABBER_PASSWORD = 'your_jabber_password' JABBER_RECIPIENT = 'recipient@jabberdomain.com' JABBER_ERROR_TEXT = 'An error occurred in "Project Name", please check your email.' Start a new app named errors or something else and add it to the INSTALLED_APPS tuple in the settings.py: python manage.py startapp errors Add a handler500 variable with the view in the root urls.py: handler500 = 'errors.views.server_error_jabber' Finally add the view in errors.views that sends a jabber notification and returns a 500 error page: from django.views.defaults import server_error from django.conf import settings import xmpp, time def server_error_jabber(request, template_name='500.html'): … -
Exposing calendar events using iCalendar in Django
I recently wrote simple abstraction for exposing calendar events in Django as iCalendar feeds. It relies on vobject for managing the formatting of the calendar file, so you will need this if you want to try it out. It is available in Debian in the python-vobject package. Save this as a file somewhere in your project: import vobject from django.http import HttpResponse EVENT_ITEMS = ( ('uid', 'uid'), ('dtstart', 'start'), ('dtend', 'end'), ('summary', 'summary'), ('location', 'location'), ('last_modified', 'last_modified'), ('created', 'created'), ) class ICalendarFeed(object): def __call__(self, *args, **kwargs): cal = vobject.iCalendar() for item in self.items(): event = cal.add('vevent') for vkey, key in EVENT_ITEMS: value = getattr(self, 'item_' + key)(item) if value: event.add(vkey).value = value response = HttpResponse(cal.serialize()) response['Content-Type'] = 'text/calendar' return response def items(self): return [] def item_uid(self, item): pass def item_start(self, item): pass def item_end(self, item): pass def item_summary(self, item): return str(item) def item_location(self, item): pass def item_last_modified(self, item): pass def item_created(self, item): pass Now we need to couple this abstraction with a Django queryset. I placed this in a feeds.py in my application: from yourproject.path.icalendar import ICalendarFeed from yourproject.yourapp.models import SomeEvent class SomeEventCalendar(ICalendarFeed): def items(self): return SomeEvent.objects.all() def item_uid(self, item): return str(item.id) def item_start(self, item): return item.start def item_end(self, item): … -
Django Envy
Seriously, can the django and rails camps quit looking over each others' shoulders? The Liquid Templates project brings django's template language to rails. At least it will make transistioning from rails to django easier once that inevitably becomes fashionable. Post to Del.icio.us -
Django request logging
I'm a big believer in the utility of web application logging. Over the years I've almost always found it more useful than debuggers in diagnosing problems. The difficulty is achieving good logging. Here's a solution for Django projects that I'm pretty happy with. -
Automatic versioning of static content for Django sites
A standard performance tweak these days is to set long expiration dates on your site's static content. Here's the best way I've come up with to do that for my Django sites. -
A Django Auth Backend for Second Life
I've started hacking away at a personal project of mine around Second Life. More on that in the days to come, but I did want to share some code created last night while playing around with Second Life logins. I've worked up a Django authentication backend for authenticating users on a Django-based site against Second Life's login process. I've created a Google code project for the code, so cleverly named slauth.This is code of the "release early, release often" variety. There are no docs, no tests, not even a README. I just wanted to get this up while I had 5 minutes today. I welcome feedback, and I'm certain I will be working on this as the larger project evolves. I'm not even certain I'll use this in the final project. I feel uncomfortable taking username and password for another "site," but without a proper login API for site-to-site authentication, this seems to be the only viable route. This uses the same XMLRPC auth process of the Second Life viewer code, which seemed to legitimize it a little for me (since this is how third party viewers have to authenticate). It's certainly better than page scraping the response of the … -
ProfileMiddleware - sprawdź co zajmuje najwięcej czasu
Przy optymalizowaniu ważną rzeczą jest znalezienie miejsc które zajmują najwięcej czasu. Aby to zrobić używamy zmodyfikowanej wersji kodu znalezionego na djangosnippets. Pozwala on zobaczyć metody oraz moduły pożerające najwięcej zasobów. Poniżej wycinek wyników działania: ncalls ... -
Pobieranie tylko niektórych pól z bazy danych.
Niedawno na grupie dyskusyjnej Django pojawił się bardzo ciekawy patch. Entropy Hacker postanowił rozszerzyć dotychczasowe API Djangowego ORM'a o możliwość wyciągania tylko niektórych pól z bazy danych. Nie mówię oczywiście, że takie coś nie istniało. Metoda, która jest dostępna w... -
Special Ops for Django
I do a lot of hacking on django both at work and in my spare time. One of the things I like most about django is the built in admin. It's cheap, fast and reliable. But it doesn't always have the functionality you might want to add, and extending it isn't always the easiest thing to do. So much of what I do ends up being done in an ad hoc mode. It's only after performing a task a few times that you can really begin to get to the bottom of what is common and belongs in a framework, and what isn't. So when it came time to add some features to handle blog spam last week, I guess I finally had enough context to extend django's admin in a hopefully intelligent manner. What I've done is add what I'm calling admin actions to the standard admin mechanisms as defined in the models. The gist of it is that I've added a few new views and a single function decorator that you can use to unleash the additional functionality within the admin. ( BTW: you can get the diff to patch your instance from here. Just apply it to … -
Yet Another Python ORM
I’ve developed a Python ORM that is intended to be a lightweight, high-performance alternative to SQLObject, SQLAlchemy, the Django ORM, etc. Each of the preceding projects attempts to implement a comprehensive feature set. This ORM, however, is intended to be minimal, with as minimal of a configuration as required. -
Some very usable django apps
I was looking for some easy to plug-in django appsfor my new service.Here are some I decided to use:django-taggingdjango-registrationdjango-threadedcommentsdjango-votingThey seem to be rock stable, and easy to use.Check back soon for more info about the new website. -
ImageField and edit_inline revisited
A while back I wrote about using edit inline with image and file fields. Specifically, I suggested adding an uneditable BooleanField as the core field of the related model. This means you don’t have to set the ImageField or FileField to be core (which would cause confusing behaviour). Removing the related model The downside to having an uneditable core field is that you can’t remove the related model instance using admin. At the time, I wasn’t trouble by this so I just left it. In a recent project I needed to associate photos with articles, use edit_inline for the photos and be able to remove them. So here’s an extended workaround. As well as the uneditable BooleanField (“keep”) which keeps the ArticlePhoto from being deleted, we now have a “remove” BooleanField which the user can tick in admin to cause the ArticlePhoto to be deleted. The check for this is in the save() method. class ArticlePhoto(models.Model): article = models.ForeignKey(Article, related_name='photos', edit_inline=models.TABULAR, min_num_in_admin=5) keep = models.BooleanField(core=True, default=True, editable=False) remove = models.BooleanField(default=False) image = CustomImageField() def save(self): if not self.id and not self.image: return if self.remove: self.delete() else: super(ArticlePhoto, self).save() It’s a pretty easy way to work around the problem and gives … -
Beautiful and free icons
While building websites there can be the need for a beautiful and meaningful icon. Up to now I haven't seen many icon collections that satisfied me, either the icon itself is badly drawn or you can't assign an accurate meaning. But that is different with the silk icons of Mark James... Somehow I embosomed his collection, it's the first where I have a look when I need an icon - and not until yesterday. The collection is free (doesn't happen that often), the icons in 16x16 pixels are beautiful and good to use for the things use usually use an icon for ;) There is also an overview over all icons with their titles where you can derive their purpose. All 1000 icons are in the PNG format, the collection currently is in version 1.3. If you like beautiful icons, have a look! -
Beautiful and free icons
While building websites there can be the need for a beautiful and meaningful icon. Up to now I haven't seen many icon collections that satisfied me, either the icon itself is badly drawn or you can't assign an accurate meaning. But that is different with the silk icons of Mark James... Somehow I embosomed his collection, it's the first where I have a look when I need an icon - and not until yesterday. The collection is free (doesn't happen that often), the icons in 16x16 pixels are beautiful and good to use for the things use usually use an icon for ;) There is also an overview over all icons with their titles where you can derive their purpose. All 1000 icons are in the PNG format, the collection currently is in version 1.3. If you like beautiful icons, have a look! -
Beautiful and free icons
While building websites there can be the need for a beautiful and meaningful icon. Up to now I haven't seen many icon collections that satisfied me, either the icon itself is badly drawn or you can't assign an accurate meaning. But that is different with the silk icons of Mark James... Somehow I embosomed his collection, it's the first where I have a look when I need an icon - and not until yesterday. The collection is free (doesn't happen that often), the icons in 16x16 pixels are beautiful and good to use for the things use usually use an icon for ;) There is also an overview over all icons with their titles where you can derive their purpose. All 1000 icons are in the PNG format, the collection currently is in version 1.3. If you like beautiful icons, have a look! -
Sailing on…
Almost four years ago, Adrian posted about a job opening at this little newspaper in the middle of the country. He wrote that World Online is […] one of the most innovative online-news operations in the world. Our main sites […] have garnered an impressive batch of industry awards – and tremendous industry attention – over the past few years. […] We strive for innovation, nimble development and the use of best practices. -
Test IE6 on PC with IE7
If you created webpages you probably want the page to look nearly the same in all browsers. Because there are still many Internet Explorer 6 users out there you should adjust your site for this browser, too. But that's not that easy if you have installed the IE7 because you don't have the IE6 anymore. But a VirtualPC image of Microsoft finds a remedy. It comes with Windows XP and IE6 (or IE7 if you still have the IE6 and want to test IE7). Simply open it in the (free) VirtualPC software and enjoy the IE6 browserworld! go to Download -
Test IE6 on PC with IE7
If you created webpages you probably want the page to look nearly the same in all browsers. Because there are still many Internet Explorer 6 users out there you should adjust your site for this browser, too. But that's not that easy if you have installed the IE7 because you don't have the IE6 anymore. But a VirtualPC image of Microsoft finds a remedy. It comes with Windows XP and IE6 (or IE7 if you still have the IE6 and want to test IE7). Simply open it in the (free) VirtualPC software and enjoy the IE6 browserworld! go to Download -
Test IE6 on PC with IE7
If you created webpages you probably want the page to look nearly the same in all browsers. Because there are still many Internet Explorer 6 users out there you should adjust your site for this browser, too. But that's not that easy if you have installed the IE7 because you don't have the IE6 anymore. But a VirtualPC image of Microsoft finds a remedy. It comes with Windows XP and IE6 (or IE7 if you still have the IE6 and want to test IE7). Simply open it in the (free) VirtualPC software and enjoy the IE6 browserworld! go to Download -
TYPO3: Limit creatable elements per page
Sometimes it is necessary to limit the creatable elements on a page. This is especially useful if you only want to save specific elements within a SysFolder, e.g. within "users" there should be only users. Within the TSConfig of the appropriate page add the following TypoScript having db_tablename be the database table with the elements you want to limit to: mod.web_list.allowedNewTables = db_tablename,db_tablename_2 -
TYPO3: Limit creatable elements per page
Sometimes it is necessary to limit the creatable elements on a page. This is especially useful if you only want to save specific elements within a SysFolder, e.g. within "users" there should be only users. Within the TSConfig of the appropriate page add the following TypoScript having db_tablename be the database table with the elements you want to limit to: mod.web_list.allowedNewTables = db_tablename,db_tablename_2 -
TYPO3: Limit creatable elements per page
Sometimes it is necessary to limit the creatable elements on a page. This is especially useful if you only want to save specific elements within a SysFolder, e.g. within "users" there should be only users. Within the TSConfig of the appropriate page add the following TypoScript having db_tablename be the database table with the elements you want to limit to: mod.web_list.allowedNewTables = db_tablename,db_tablename_2 -
getting ReviewBoard running
I made some notes on getting Review Board up and running. I thought they might be useful for someone else wishing to do the same… I implemented review board on a virtual machine, with the VM running Ubuntu Gutsy. I … Continue reading → -
StaticGenerator 1.2
StaticGenerator for Django has been updated to version 1.2. This is a minor release, though it is backwards incompatible. -
djangopeople.net, GeoDjango and PostGIS
Michael Trier's "This Week In Django" podcast is turning into something of a gem mine. I'm particularly taken with one website he mentioned, djangopeople.net. Plus, thoughts on GeoDjango and PostGIS, and the iPhone's Wi-Fi Locations technology.