Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Rate your ISP
In June a bunch of great people went with me to a cottage for the weekend to create something. It was our 3rd Wilderness Labs adventure. The outcome is pretty awesome. We built a service to collect simple ISP reviews to help Canadians find their best local ISP. We called it RateMyISP. (Coming up with names might not be our strongest suit.) The idea came from Open Media's Stop the Meter campaign when more Canadians signed a petition protecting indy ISPs than use them. People who use the larger players still wanted the indy ISPs to exist so they would have an option when they become dissatisfied. Trouble is, finding the right local or indy ISP is kind of difficult. I found mine in London, ON thanks to a Reddit comment which is no doubt now buried never to be found again. The comment listed the local ISP options per city in southern Ontario. There had to be a better way and now there is. The service is ready to start absorbing reviews. As we gather reviews over the next few months we will use that information to vastly improve the search. We plan to highlight what areas indy ISPs … -
Unstable HTTP services: what we can do to easily handle that?
The story: I have several HTTP service providers which works quite unstable. Yes, I had to have in mind this during development. But we're all thought that issues are "temporary" and will gone when we going to production. We accurately added logging.error in every place and move on with other stuff.But our expectation about temporary nature of service behavior will never happen. Service sometimes work slowly, sometimes return HTTP errors and so on. We receive tons of exceptions every day. We had to do something with that.The solution: Here is safe_exec decorator which help solve this problem. You can specify how many times you want to try execute function, what's timeout between them and what exceptions are expected during execution decorated function. For example, urllib2.urlopen may generate urllib2.URLError or urllib2.HTTPError.import loggingimport timefrom functools import wraps__all__ = ("safe_exec",)def safe_exec(exceptions, shakes=3, timeout=1, title="", **kwargs): """ Decorator to safely execute function or method within `shakes` trying. In case provide argument `default` exception will not be raised and will return provided value. """ def wrap(func): if not isinstance(exceptions, tuple): raise TypeError( "First argument of safe_exec should be tuple of exceptions" ) @wraps(func) def wrapped(*args, **kwargs): result = None orig_exception = None for shake in range(shakes): try: result = func(*args, **kwargs) break except exceptions, orig_exception: logging.warn("%s: Sorry, … -
Developing RESTful Web APIs with Python, ...
This week's [Python Weekly](http://us2.campaign-archive1.com/?u=e2e180baf855ac797ef407fc7&id=bbe8f42215&e=04306b42c9) has a link to a presentation by [Nicola Iarocci](), called [Developing RESTful Web APIs with Python, Flask and MongoDB](https://speakerdeck.com/u/nicola/p/developing-restful-web-apis-with-python-flask-and-mongodb). I have a few minor concerns with some aspects of the content. > No form validation This concerns me. I've recently started using django's forms for my validation layer for API calls, and also for the generation of the serialised output. It's not completely flawless, but it seems to be working quite well. It certainly is more robust than my hand-rolled scheme of validating data, and using code that is better tested than my own is always a bonus. Instead, as we see later, there is a data validation layer. It has basically the same goal as django's forms, but is somewhat more nested, rather than using classes. Also, using classes makes it easier to have inheritance, a great way to have shared rules. You could do this using the same function in your custom validation, but this feels disconnected. > MongoDB > scalable, high-performance, ... The integrity of my data is important to me. It's very rare that the db is the limiting factor in my system's performance, and having stuff written to disk as soon … -
Provisioning, Deployments and Testing - Oh my!
Here at Imaginary Landscape, we have an initative to explore solutions to some of our on-going deployment meta-problems. Those problems include things like standardizing our Django project structures and the hosting environments in which we host them. Another challenge that we have been considering is testing our sites locally. After ... -
PyCon Philippines 2012 Day 2
The second day of PyCon Philippines 2012 had a really good turnout. My unofficial estimate is that we had about 90% of the attendees from the first day attend (with the unfortunate exception of most of the faculty and students of Agoo Computer College). The day started with... Lightning Talks Unfortunately I don't normally take notes on lightning talks. I'm kicking myself now. Really hard. I'll try and relate some of the talks: Import this and that, a parody talk by Daniel Greenfeld (me). Malcolm comment on it. Getting into space using weather balloons by Frank Pohlmann Ponystrap by Audrey Roy (video from DjangoCon Europe) Call for Tagalog and other Philippine languages translation of Django by Malcolm Tredinnick The obligatory PyCon lighting talk on Vim by Bryan Bibat OpenERP by Frank Pohlmann and Ann Tan-Pohlmann A parody talk by Sony Valdez Then it was on to... Sprints and Tutorials Encouraged at #pyconph seeing so many people declaring themselves beginners and then diving in. Enthusiasm was a bit contagious. —Malcolm Tredinnick on twitter Primary funding for the sprints came from the Django Software Foundation and Python Sprints. That funding went towards food, drinks, and various logistics for handling the estimated 200+ … -
PyCon Philippines 2012 Day 2
The second day of PyCon Philippines 2012 had a really good turnout. My unofficial estimate is that we had about 90% of the attendees from the first day attend (with the unfortunate exception of most of the faculty and students of Agoo Computer College). The day started with... Lightning Talks Unfortunately I don't normally take notes on lightning talks. I'm kicking myself now. Really hard. I'll try and relate some of the talks: Import this and that, a parody talk by Daniel Greenfeld (me). Malcolm comment on it. Getting into space using weather balloons by Frank Pohlmann Ponystrap by Audrey Roy (video from DjangoCon Europe) Call for Tagalog and other Philippine languages translation of Django by Malcolm Tredinnick The obligatory PyCon lighting talk on Vim by Bryan Bibat OpenERP by Frank Pohlmann and Ann Tan-Pohlmann A parody talk by Sony Valdez Then it was on to... Sprints and Tutorials Encouraged at #pyconph seeing so many people declaring themselves beginners and then diving in. Enthusiasm was a bit contagious. —Malcolm Tredinnick on twitter Primary funding for the sprints came from the Django Software Foundation and Python Sprints. That funding went towards food, drinks, and various logistics for handling the estimated 200+ … -
WhisperGifts: The Tech That Let Me Launch
The WhisperGifts re-launch recently went very well! I promised a more technical follow-up with some details about what's new and what's changed, so if you want to know more about what makes WhisperGifts tick then you'll want to read on. Hint: It's a dash of Django, a pinch of Python, and a slathering of open-source software all around. -
WhisperGifts - The Tech That Let Me Launch
The WhisperGifts re-launch recently went very well! I promised a more technical follow-up with some details about what's new and what's changed, so if you want to know more about what makes WhisperGifts tick then you'll want to read on. Hint: It's a dash of Django, a pinch of Python … -
WhisperGifts - The Tech That Let Me Launch
The WhisperGifts re-launch recently went very well! I promised a more technical follow-up with some details about what's new and what's changed, so if you want to know more about what makes WhisperGifts tick then you'll want to read on. Hint: It's a dash of Django, a pinch of Python, and a slathering of open-source software all around. The primary technology behind WhisperGifts is Django, the "web framework for perfectionists with deadlines". My own deadline for this project was rather, ahem, flexible - the new design was a work in progress for 2 years (on-and-off, mostly off due to the birth of our baby) and the back-end re-write happened over a few months early in 2012. Django allows us to iterate quickly. I find the language natural to use and the documentation is epic. There's a number of things that no framework does out of the box; I've tried to rely on open-source to fill as many gaps as possible rather than re-writing things from scratch like I did with the original WhisperGifts site - this is mostly because the open-source ecosystem around Django is now so much larger than it used to be. As an example, originally I rolled … -
PHP, Python and Persuasion
I always find it fascinating to observe conversations in which people's arguments fail to convince each other. A few days ago we witnessed some PHP debates, kicked off by Jeff Attwood. I foolishly got slightly involved on one ‘rebuttal’. At church last Sunday I also chatted with a friend who has used PHP and likes it, and this time I tried to put myself in his shoes. It is often much more helpful talking to people in the flesh, and I think it is always enlightening to look at why we fail to convince. One reason we can't rule out is simple irrationality. All of us are vulnerable to confirmation bias, and people will often go to great lengths to convince themselves that they are doing the right thing and do not need to change their views or practices. You see this all the time when two groups of people share experiences after having made different decisions about how to spend some leisure time. Both groups are often desperate to believe that they haven't missed out, and will seek to persuade each other (but in reality, persuade themselves) that they were in the group that had the most fun. However, … -
Create Text & Online Versions of Emails Automatically
For this i’ve created django-firstclass. Firstclass is a proxy email backend for Django that allows for global email transformations such as automatically creating a plain text version of html emails or automatically creating an online version of the email that can be read in browser. My goal was to have this be a drop in solution requiring no change to a code base. I also wanted this to be flexible enough so that it can work with a wide variety of projects. I accomplished this by adding a middleware pipeline to Django’s email process. I’ve bundled a few useful middleware in and plan to add a few more. Creating your own middleware is simple. Middleware is a single Python class that defines process_message. For example if you wanted to create a middleware that would add a tracking pixel to all of your emails: http://gist.github.com/3048960 You would then simply add TrackingPixelMiddleware to FIRSTCLASS_MIDDLEWARE. https://github.com/amccloud/django-firstclass -
TND dataview and metaclass magic in python - Maarten ter Horst
-
Rethinking the Django-CMS landscape - Diederik van der Boor
-
Document automation (Office) using Django - Henk Vos
-
Building single-page web-applications with Django, Twisted and TxWebsocket - Jeroen van Veen
-
PyCon Philippines 2012 Day 1
PyCon Philippines 2012 (PyCon PH) happened just this past weekend at the University of the Philippines Diliman (UP Diliman) campus in Quezon City, which is part of Metro Manila. I can assure you that PyCon PH was an wonderful, amazing, humbling experience. I'm hoping that this post and others will get across to you why. Arrival Frank Pohlmann, chairman of PyCon Philippines picked us up and drove us to the event. He had worked day and night getting the event ready, all the while running his company, working a job, and being a father to his lovely 21 month old daughter. As we arrived at the venue, Audrey and I were met by our good friend, Filipino-American Bryan Veloso of Github, who was to provide the closing keynote. As soon as Bryan heard that there was going to be a PyCon in the Philippines he gave up his trip to Europython to be a speaker at PyCon PH. Inside the Institute of Electrical and Electronics Engineering, we were greeted Ann Tan-Pohlman, logistics co-chair and volunteer organizer. She had over a dozen volunteers getting ready for the oncoming flood of registrants. More on the herculean efforts of the organizers and volunteers … -
PyCon Philippines 2012 Day 1
PyCon Philippines 2012 (PyCon PH) happened just this past weekend at the University of the Philippines Diliman (UP Diliman) campus in Quezon City, which is part of Metro Manila. I can assure you that PyCon PH was an wonderful, amazing, humbling experience. I'm hoping that this post and others will get across to you why. Arrival Frank Pohlmann, chairman of PyCon Philippines picked us up and drove us to the event. He had worked day and night getting the event ready, all the while running his company, working a job, and being a father to his lovely 21 month old daughter. As we arrived at the venue, Audrey and I were met by our good friend, Filipino-American Bryan Veloso of Github, who was to provide the closing keynote. As soon as Bryan heard that there was going to be a PyCon in the Philippines he gave up his trip to Europython to be a speaker at PyCon PH. Inside the Institute of Electrical and Electronics Engineering, we were greeted Ann Tan-Pohlman, logistics co-chair and volunteer organizer. She had over a dozen volunteers getting ready for the oncoming flood of registrants. More on the herculean efforts of the organizers and volunteers … -
django CMS 2.3 released
-
Multiple File Uploads in Django
Here is a quick example of how to add a multiple file form to your Django application. Most multiple-upload front-ends were created without Django in mind, so interfacing with tools is not always straightforward as it might be with a different language. Thankfully, there are a couple of Django libraries ... -
Our Custom Mixins
UPDATE: We've released a Github repo and a PyPI package with our mixins. Feel free to fork and submit new ones through a pull-request. Let's just start out and say it, Class Based Views. Ooohhhh. Unfortunately the topic of class based views is thought of as somewhat of a dark art in the Django community. It doesn't help that the documentation is still lacking but I find a lot of people, especially on Reddit, refuse to use them. For whatever reason, it's a hard pill for some to swallow. Before DjangoCon 2011, we started playing with class-based views. At first they seemed like a nightmare and without decent docs, we got frustrated really quickly. Skip forward to today and I can't imagine writing old function-based views again. Some argue that the generic views are only for generic applications and that, somehow, their work is far too custom and complex to be handled in a generic class-based view. Based on my experience, 99% of the time, they would be wrong. We plan on covering generic class-based views extensively with GSWD. Today, I'd like to share some mixins we have cooked up, on a rather large client project, that have helped us … -
Generic Layouts in Crispy Forms
Just a quick tip and sanity check, today, about something I ran into with django-crispy-forms, the awesome new form library from Miguel Araujo. This morning, I converted the project we've been building for a client (currently some 1,700 or so files, counting templates, CSS, and icons) from django-uni-form to django-crispy-forms. It's a pretty painless transition, actually. Just do some find-and-replace across your files, basically changing any instance of uni- to crispy- (well, and form to forms), and you're good to go. Then, however, I wanted to convert two large forms that we have, which share 90% of their fields, to using the sharable Layout objects that django-crispy-forms gives us. Basically, the forms looked like this: class FirstForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field", [field3 through field20] class SecondForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field2", [field3 thorugh field20] Obviously that was a lot of repetition that we could cut out now that these inheritable layouts exist. By the way, I'm pretty sure this would have been possible in django-uni-form but likely not as friendly. First I started off by creating the shared resources. … -
AJAX and Django Views
It seems that cleanly and easily doing AJAX views in Django is an area that gives a lot of people trouble. We like to do views as straight HTTP if at all possible, but there are always interactions that would be better served by not having a page load. We're also big fans of django-tastypie but it's a whole other ball of wax on its own, especially if you want to have views that write to the database. So, for the purposes of getting everyone up to speed doing AJAX with Django, we'll ignore Tastypie for now and just stick with ordinary views. Django automatic CSRF To start things off, put this bit of Javascript from the Django docs into a script that's loaded on all the pages where you'll be needing to perform AJAX views. This allows you to ignore the CSRF token for AJAX views, but it will be added as a request header. We previously said this could be seen as a security loophole and that same-origin came into effect. Both of these statements are wrong. AJAX & Form Field Errors Before we get to the Django side, there are a few small scripts that we recycle … -
User-friendlier model forms
Recently, in our large client project, we had need of fields, in a model form, that accepted multiple types of input, but sanitized the data for the model. For example, the rent field, on the form, needs to handle a rent range (e.g. 900-1200), a single amount, or be overridden or extended by other bits of information, like "call for details" or "on approved credit". Obviously we don't want to have to parse this out every time we read the data. So, enter our fields that tear data apart and put it together every time it passes through. Model Let's go over our Rent model first. It's an abstract model so we can use it in multiple places (we have more than one logical model in the system that needs to deal with rent, this way we can use it multiple places without having to hold on to a huge amount of joins). We have several other abstract models that perform the same actions as our Rent model, but I won't show them here. from django.core.exceptions import ValidationError from django.db import models class Rent(models.Model): rent_low = models.PositiveIntegerField() rent_high = models.PositiveIntegerField(blank=True, null=True) rent_percent_income = models.FloatField(blank=True, null=True) rent_oac = models.BooleanField(default=False) rent_call_for_details = … -
Extending time and details
For the fun of it I added an "Extended Room" contrib to Evennia the other night.("Contribs" are optional code snippets and systems that are not part of the actual codebase. They are intended for you to use or dissect as you like in your game development efforts).The ExtendedRoom is a room typeclass meant to showcase some more advanced features than the default one. Its functionality is by all means nothing revolutionary in MUD-world, but it was fun and very simple to do using only Evennia's basic building blocks - the whole thing took me some two hours to code, document and clean up for a contrib push. The "ExtendedRoom" contribution has the following features:Season-based descriptions. The new Room typeclass will change its overall description based on the time of year (the contrib supports the four seasons, you can hack this as you please). It's interesting from an implementation point of view since it doesn't require any Script or ticker at all - it just checks on-demand, whenever it is being looked at, only updating if the season has actually changed. There is also a general description used as a fallback in case of a missing seasonal one.Time-of-day-based descriptions. Within each … -
Testing As a Different Django User
All types of Django auth do basically the same thing: They associate a browser session ID with a Django user if the user logs-in successfully. I found a neat technique to bypass a Django login by modifying with a Django session, which can be useful for testing purposes.Why is ...