Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
I don't belive in software complexity
Ok, building software could be complex, but it doesn't have to. Recently I read this quote Complexity happens when you don't understand a problem fully It's true. We, the software craftsmen, have a very difficult task upon us: building tools for proposes we don't understand fully. I got it screeching my fingers with a bit of bioinformatics. In finance is no different. Today I saw poor JMS -
Four Libs Good, Two Libs Better
Our approach to site construction used to favor collecting open source apps and gluing them together in order to build up scaffolding quickly and to reuse the efforts of others. This is still a prominent part of how we operate, but we also don’t automatically reach for an app just because one exists — even ones we know are high quality. -
Four Libs Good, Two Libs Better
Click here to see this post in it's natural habitat and to watch and leave comments. [with apologies to Mr. Orwell] I’ve noticed a subtle shift in how we approach building up new sites over the last couple of years. Our approach to site construction used to favor collecting open source apps and gluing them together in order to build up scaffolding quickly and to reuse the efforts of others. This is still a prominent part of how we operate, but we also don’t automatically reach for an app just because one exists—even ones we know are high quality. In the past, pip requirements with dozens of dependencies was common for larger sites. These days we tend to use a lot more discretion before adding an entry to those files. While reusable apps can seem to offer productivity gains by providing the base for a feature with minimal effort, there can be a lot of hidden time costs that only surface intermittently throughout the life of a project (often at inconvenient times). Apps pull in their own dependencies, which you then need to manage. Some parts of the app provide exactly what you need, while others can be problematic. You’re … -
SM.Org software update 2012
Over the course of a few recent weeks I updated this site to a more modern software and revised some previously made choices. This one was loooong overdue considering that I still ran Ubuntu 9.10 before the update meaning that the system was almost 3 years old. Here are some mostly useless but probably fascinating notes about it. Core system upgrades Running a comparatively low-load site I had a luxury not to plan for complex procedures minimizing downtime. What I did was just SSHing on the host and running do-release-upgrade under "screen" five times in a row. Linode's upgrade docs were holding my hand during the process. Currently the site runs on Ubuntu 12.04 "Precise" and 3.0 Linux kernel. It's good to have modern packages! Notable moments (read: long downtimes) during the upgrades: Ubuntu's integrated mail stack was good back then and these days it's just wonderful! Upon installing a single package "mail-stack-delivery" you get yourself a completely set up mail server that can send mail, accept mail from outside and that provides an IMAP interface to your mailbox. It even does necessary SSL key generation magic for me, so I can do authorization from my mail client securely. What … -
Auto-building Sphinx docs
Here’s a quick way to automatically regenerate your Sphinx docs as you make changes to the source. There’s probably a million ways to do this; here’s mine: $ pip install watchdog $ watchmedo shell-command \ --patterns="*.txt" \ --ignore-pattern='_build/*' \ --recursive \ --command='make html' -
Django book: abort abort abort
-
Django Class Based View: email form with CAPTCHA
Yesterday I showed how to implement a simple email form for Django using Class Based Views. Today I'm going to extend yesterday's work to use the excellent RECAPTCHA service to help reduce spam content. This version requires pip installing the following into your virtualenv. pip install django-crispy-forms so we can do Python driven layouts. pip install django-floppyforms so we get HTML5 elements for free. pip install django-recaptcha to do the RECAPTCHA work. Don't forget to add the app to your INSTALLED_APPS in settings.py: INSTALLED_APPS += ( 'crispy_forms', 'floppyforms', 'captcha', ) Generate your KEYs from the RECAPTCHA site and add them in settings.py: RECAPTCHA_PUBLIC_KEY = '6LcVu9ESAAAAANVWwbM5-PLuLES94GQ2bIYmSNTG' RECAPTCHA_PRIVATE_KEY = '6LcVu9ESAAAAAGxz7aEIACWRa3CVnXN3mFd-cajP' In myapp.forms.py: from captcha.fields import ReCaptchaField # Only import different from yesterday from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit import floppyforms as forms class ContactForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) subject = forms.CharField(required=True) message = forms.CharField(widget=forms.Textarea) captcha = ReCaptchaField() # Only field different from yesterday def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) super(ContactForm, self).__init__(*args, **kwargs) In myapp.views.py: # Unchanged from yesterday. :-) from django.conf import settings from django.core.mail import send_mail from django.views.generic import FormView from myapp.forms import ContactForm class ContactFormView(FormView): form_class = ContactForm template_name = "myapp/email_form.html" success_url = … -
Django Class Based View: email form with CAPTCHA
Yesterday I showed how to implement a simple email form for Django using Class Based Views. Today I'm going to extend yesterday's work to use the excellent RECAPTCHA service to help reduce spam content. This version requires pip installing the following into your virtualenv. pip install django-crispy-forms so we can do Python driven layouts. pip install django-floppyforms so we get HTML5 elements for free. pip install django-recaptcha to do the RECAPTCHA work. Don't forget to add the app to your INSTALLED_APPS in settings.py: INSTALLED_APPS += ( 'crispy_forms', 'floppyforms', 'captcha', ) Generate your KEYs from the RECAPTCHA site and add them in settings.py: RECAPTCHA_PUBLIC_KEY = '6LcVu9ESAAAAANVWwbM5-PLuLES94GQ2bIYmSNTG' RECAPTCHA_PRIVATE_KEY = '6LcVu9ESAAAAAGxz7aEIACWRa3CVnXN3mFd-cajP' In myapp.forms.py: from captcha.fields import ReCaptchaField # Only import different from yesterday from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit import floppyforms as forms class ContactForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) subject = forms.CharField(required=True) message = forms.CharField(widget=forms.Textarea) captcha = ReCaptchaField() # Only field different from yesterday def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) super(ContactForm, self).__init__(*args, **kwargs) In myapp.views.py: # Unchanged from yesterday. :-) from django.conf import settings from django.core.mail import send_mail from django.views.generic import FormView from myapp.forms import ContactForm class ContactFormView(FormView): form_class = ContactForm template_name = "myapp/email_form.html" success_url = … -
Django Unchained
As you have hopefully already noticed, our website works very nicely on mobile devices. However since many of you will be visiting Switzerland from abroad, you might not have an (affordable) data connection on those devices when you're at the conference.That's why I'm very happy to announce the guys at exopoint have very kindly made all the information you need for DjangoCon Europe 2012 available offline using their app. If you have an iPhone, an Android Phone or a Windows Phone, head over to their website using your mobile device phone to install the app. Once you've done that, open the link again to add DjangoCon Europe to the app.Should that not work for you, just search the app market/store of your phone for the "exopoint" app and install it. After the installation, tap the "+" icon in the app and search for "Djangocon".If you want to fully unchain your phone for DjangoCon and get a local SIM card, we have put up a summary of your options on our newest information page about Zurich. -
Simple Django email form using CBV
Here's a simple FormView Class Based Views for Django. Here is a sample of how to do one as a simple email form. There is no CAPTCHA in this example, that's the topic of a future blog post. This version requires the following packages pip installed into your virtualenv. django-crispy-forms so we can do Python driven layouts. django-floppyforms so we get HTML5 elements for free. They also need to be added to your list of INSTALLED_APPS: INSTALLED_APPS += ( 'crispy_forms', 'floppyforms', ) In myapp.forms.py: from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit import floppyforms as forms class ContactForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) subject = forms.CharField(required=True) message = forms.CharField(widget=forms.Textarea) def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) super(ContactForm, self).__init__(*args, **kwargs) In myapp.views.py: from django.conf import settings from django.core.mail import send_mail from django.views.generic import FormView from myapp.forms import ContactForm class ContactFormView(FormView): form_class = ContactForm template_name = "myapp/email_form.html" success_url = '/email-sent/' def form_valid(self, form): message = "{name} / {email} said: ".format( name=form.cleaned_data.get('name'), email=form.cleaned_data.get('email')) message += "\n\n{0}".format(form.cleaned_data.get('message')) send_mail( subject=form.cleaned_data.get('subject').strip(), message=message, from_email='contact-form@myapp.com', recipient_list=[settings.LIST_OF_EMAIL_RECIPIENTS], ) return super(ContactFormView, self).form_valid(form) In templates/myapp/email_form.html: {% extends 'base.html' %} {% load crispy_forms_tags %} {% block title %}Send an email{% endblock %} {% block content %} <div class="row"> <div … -
Simple Django email form using CBV
Here's a simple FormView Class Based Views for Django. Here is a sample of how to do one as a simple email form. There is no CAPTCHA in this example, that's the topic of a future blog post. This version requires the following packages pip installed into your virtualenv. django-crispy-forms so we can do Python driven layouts. django-floppyforms so we get HTML5 elements for free. They also need to be added to your list of INSTALLED_APPS: INSTALLED_APPS += ( 'crispy_forms', 'floppyforms', ) In myapp.forms.py: from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit import floppyforms as forms class ContactForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) subject = forms.CharField(required=True) message = forms.CharField(widget=forms.Textarea) def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) super(ContactForm, self).__init__(*args, **kwargs) In myapp.views.py: from django.conf import settings from django.core.mail import send_mail from django.views.generic import FormView from myapp.forms import ContactForm class ContactFormView(FormView): form_class = ContactForm template_name = "myapp/email_form.html" success_url = '/email-sent/' def form_valid(self, form): message = "{name} / {email} said: ".format( name=form.cleaned_data.get('name'), email=form.cleaned_data.get('email')) message += "\n\n{0}".format(form.cleaned_data.get('message')) send_mail( subject=form.cleaned_data.get('subject').strip(), message=message, from_email='contact-form@myapp.com', recipient_list=[settings.LIST_OF_EMAIL_RECIPIENTS], ) return super(ContactFormView, self).form_valid(form) In templates/myapp/email_form.html: {% extends 'base.html' %} {% load crispy_forms_tags %} {% block title %}Send an email{% endblock %} {% block content %} <div class="row"> <div … -
Compiling Dust.js templates with django-mediagenerator
Compiling Dust.js templates with django-mediagenerator Here at 2General we’ve used django-mediagenerator as the asset manager in many of our latest projects. It combines the best parts of Django’s own staticfiles implementation and the older django-compressor app. Dust.js is a fast, asynchronous JavaScript-based templating engine which runs both in browsers and on Node.js. We haven’t used Dust.js extensively yet, but we immediately noticed that if we’re planning to use it, we need to compile Dust.js templates during our normal build process, i.e. be able to add them in our mediagenerator bundles. Jump to code example » Use our improved django-mediagenerator fork Unfortunately django-mediagenerator project is somewhat abandoned as its original authors decided to call it quits last year. However, there’s an “official” Github fork which hasn’t received any updates yet and our own fork which we have updated with these improvements: Improved performance of the development mode (MEDIA_DEV_MODE=True) through caching Support for compiling Dust.js templates in JavaScript bundles Django-mediagenerator assets (usually JavaScript files and stylesheets) are organized into “bundles” in your settings.py. On a production server all the files in a bundle are served as one concatenated and minified file. The created files are versioned with a hash, so django-mediagenerator also … -
How to install Node.js packages and Ruby gems in virtualenv
How to install Node.js packages and Ruby gems in virtualenv Virtualenv is a superb tool for creating isolated environments for development with Python. However, if your project requires libraries in other languages, you may want to install them in your virtual environment as well. Here’s how to do it with Node.js packages and Ruby gems. If you’re using virtualenvwrapper (and you should), you can put this in your postactivate script. Otherwise make sure some other way that these variables are set: # node.js packages export npm_config_prefix=$VIRTUAL_ENV # ruby gems export GEM_HOME=$VIRTUAL_ENV export GEM_PATH="" Installing Node.js packages As an example, to install the Less CSS compiler in the virtual environment, use: $ npm install -g less (Note the -g option!) The lessc script will be conveniently symlinked into $VIRTUAL_ENV/bin: $ echo "div { a { color: #f00; } }" > my.less $ lessc my.less div a { color: #f00; } The virtualenv trick requires a fairly recent version of Node.js. If you’re on an Ubuntu box, the easiest way to get one is the following (tested on 11.10 and 12.04): $ sudo add-apt-repository ppa:chris-lea/node.js $ sudo apt-get update $ sudo apt-get install -y npm Installing Ruby gems Ruby gems are installed … -
Django Job – Worcestershire, United Kingdom
My company is hiring. Details here. -
May 12th, 2012 LA Open Source Recap
On May 12th, 2012, over 50 Python, C++, Ruby, PHP, JavaScript, and Node.js developers arrived to code on a variety of projects. It was awesome! Tons of open source projects saw contributions, and people across languages and frameworks worked together. Event Background Less then two weeks before May 12, a bunch of us Los Angeles area Python developers were hanging out and wishing we had a local sprint to attend that was just about developers working on open source projects. It was then that Audrey Roy and I, along with an army of hardworking volunteers, decided to stop wishing and make it happen on May 12th. We lined up a venue, contacted awesome sponsors Spire.io, Heroku, Github, Cars.com, and Cartwheel Academy. As we did that, we also invited people from the many Los Angeles programming communities in Los Angeles to join us. The result of everyone's hard work? We filled up all sixty spots in less than 96 hours! Some of the projects worked on included: Salt Stack: https://github.com/saltstack/salt A node.js-powered streaming terminal, allowing for shared input at a terminal among several participants. A JavaScript powered astrolabe. Settlers of Catan analytics in JavaScript. OpenFrameworks, a cross-platform toolkit for creative coding … -
May 12th, 2012 LA Open Source Recap
On May 12th, 2012, over 50 Python, C++, Ruby, PHP, JavaScript, and Node.js developers arrived to code on a variety of projects. It was awesome! Tons of open source projects saw contributions, and people across languages and frameworks worked together. Event Background Less then two weeks before May 12, a bunch of us Los Angeles area Python developers were hanging out and wishing we had a local sprint to attend that was just about developers working on open source projects. It was then that Audrey Roy and I, along with an army of hardworking volunteers, decided to stop wishing and make it happen on May 12th. We lined up a venue, contacted awesome sponsors Spire.io, Heroku, Github, Cars.com, and Cartwheel Academy. As we did that, we also invited people from the many Los Angeles programming communities in Los Angeles to join us. The result of everyone's hard work? We filled up all sixty spots in less than 96 hours! Some of the projects worked on included: Salt Stack: https://github.com/saltstack/salt A node.js-powered streaming terminal, allowing for shared input at a terminal among several participants. A JavaScript powered astrolabe. Settlers of Catan analytics in JavaScript. OpenFrameworks, a cross-platform toolkit for creative coding … -
Lizard sprint week
-
Announcing our final keynote speaker: Karen Tracey
I'm thrilled to announce that our final keynote speaker for DjangoCon Europe 2012 will be Karen Tracey.Karen has been using Django since 2006 and is a core developer of Django now. She loves crosswords and constructs her own for several newspapers, including the New York Times, and it is her work on crosswords that initially brought her to Django, as she was seeking a frontend for her database of crosswords. She also wrote the book Django Testing and Debugging and works for Caktus. Besides her work on and with Django, Karen enjoys volunteering for a cat rescue organization dedicated to improving the lives and reducing the population of homeless cats in the Triangle area. -
Release 0.6.17
We just released LFS 0.6.17. This is a yet another bugfix release of the 0.6 branch. Changes Bugfix: fixed update cart after login for configurable products; #issue gh #8 Bugfix: make PayPal callbacks work with CSRF protection; issue #197 (Dmitry Chaplinsky) Bugfix: Fixed wrong arguments in calls to voucher API (Pavel Zagrebelin) Bugfix: catch wrong floats in calculate_packing Information You can find more information and help on following locations: Documentation on PyPI Demo Releases on PyPI Source code on bitbucket.org and github. Google Group lfsproject on Twitter IRC LFS moved to github See here for more. LFS on EuroPython 2012 We are sprinting on this year's EuroPython in Florence. Don't hesitate to join us, see https://ep2012.europython.eu/p3/sprints/ and LFS sprint topics for more. -
Release 0.7.4
We just released LFS 0.7.4. This is a yet another bugfix release of the 0.7 branch. Changes Improved shipping and payment method management: display form errors; using ajax; issue #151. Bugfix: send order_paid signal after successful callback arrived from PayPal; issue #198. Bugfix: make PayPal callbacks work with csrf protection; issue #197. Bugfix: catch wrong floats in calculate_packing. Bugfix: fixed update cart after login for configurable products; #issue gh #8 Bugfix: cleaned up parameters and arguments of PriceCalculator. Bugfix: don't pass request to PriceCalculator base_packing_price methods. Bugfix: fixed calculation of package prices for configurable products. Bugfix: Fixed wrong arguments in calls to voucher API. (Pavel Zagrebelin) Information You can find more information and help on following locations: Documentation on PyPI Demo Releases on PyPI Source code on bitbucket.org and github. Google Group lfsproject on Twitter IRC LFS moved to github See here for more. LFS on EuroPython 2012 We are sprinting on this year's EuroPython in Florence. Don't hesitate to join us, see https://ep2012.europython.eu/p3/sprints/ and LFS sprint topics for more. -
Nous projectes i nous reptes
Aquestes darreres setmanes, mesos fins i tot, han estat força intenses. Amb projectes que han duit moltes hores i que al final han sortit. Rasec de Guillermo i companyia va representar posar en marxa una aplicació que va duu més de tres mesos de feina, però amb uns resultats inicials més que encoratjadors. Pel nostre client de referència en el món turístic Fiesta Hotel Group hem posat en marxa tres noves webs en poc temps: http://www.ushuaiabeachhotel.com/. Unes fotografies realment precioses que fan ganes d'anar-hi. Sa Talaia Boutique Villa. En la mateixa línia que l'anterior i amb la idea de donar aquesta sensació de proximitat i unió entre els dos conceptes d'hotel. Hotel Mallorca Rocks Com concepte d'hotel-concert, que tans bona acollida ha tingut dins Palma com a alternativa al sol i platja tradicional. Tot això amb Python i Django com podreu suposar. Pel tipus de feina en que ens anam especialitzant cada projecte és un poc diferent. Al nostre voltant hi ha empreses que se dediquen a "fer planes web" que duen molts anys i quan veus el que han fet te n'adones que han anat repetint el mateix patró, el mateix disseny una i una altra vegada. És una … -
Reasons to love Django, part x of y
I needed to add a boolean field to a model. For many web apps, this typically involves: modifying the model layer, so that the field becomes available as an attribute on retrieved objects, and can be queried against etc. creating a database migration script that can be run immediately on the development box, and later for staging and production. running the migration against the development DB. updating any admin screens for editing the field. checking the changes and scripts into source control. deploying - including pushing source code and running migration scripts etc. Using Django, from a cold start (no editor/IDE open), this just took me 1 minute 45 seconds of work for steps 1 - 5, and an additional 45 seconds waiting for step 6, total 2 minutes 30 seconds, and I wasn't rushing. Step 1 is a one line code addition. Pretty much everything else can and should be generated automatically. Step 2 is taken care of by a one line command using South, as is step 3 and the database part of step 6 (which is run de-rigueur from my deployment scripts). Step 4 is taken care of by Django's admin, which introspects the model and generates … -
Using environment variables on Gondor
A trouble when using git/hg-based push to application servers is that everything has to be in the repo. So no more production_settings.py etc on the production server. This is easly solved by using the environment and let it provide the variables to us. On Gondor this is currently undocumented but you can always dig through the (source)[https://github.com/eldarion/gondor-client/blob/master/gondor/main.py] for the client to figure it out;-) So a quick chat in the #gondor channel at Freenode helped me with... -
Using environment variables on Gondor
A trouble when using git/hg-based push to application servers is that everything has to be in the repo. So no more production_settings.py etc on the production server. This is easly solved by using the environment and let it provide the variables to us. On Gondor this is currently undocumented but you can always dig through the (source)[https://github.com/eldarion/gondor-client/blob/master/gondor/main.py] for the client to figure it out;-) So a quick chat in the #gondor channel at Freenode helped me with... -
Export to CSV using the Django ORM
Django apps tend to be pretty data heavy. One common task is exporting sets of data to csv (comma separated values), a plain text file which can be loaded up in a spreadsheet and manipulated further. The first thing to do is make sure you know about the Python csv library. If you are exporting all of you data with respect to one model, here is a quick way to do it and keep your code cleaner using values_list and the Django ORM query shorthand. Start by defining your export as a data structure. export_info = [ ("Role", "role__name"), ("Department", "department"), ("Last Name", "person__last_name"), ("First Name", "person__first_name"), ] The first item in the tuple is the row header and the second item is an ORM path to the value you want. It will be passed in to values_list. One quirk to note is if you have a relationship and you don't specify the field on the relationship are you interested in you will just get the id for the object. The model's unicode method isn't called. For a better idea here is what the models would look like in this example. class Position(models.Model): role = models.ForeignKey("Role") department = models.CharField(max_length=256) person …