Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Structuring flask apps, a how-to for those coming from Django
The other day a friend of mine was trying out flask-peewee and he had some questions about the best way to structure his app to avoid triggering circular imports. For someone new to flask, this can be a bit of a puzzler, especially if you're coming from django which automatically imports your modules. In this post I'll walk through how I like to structure my flask apps to avoid circular imports. In my examples I'll be showing how to use "flask-peewee", but the same technique should be applicable for other flask plugins. I'll walk through the modules I commonly use in my apps, then show how to tie them all together and provide a single entrypoint into your app. Project layout I use a structure that may look familiar to users of the django framework: admin.py - Where you register models with the site admin interface api.py - Where you register models to be exposed via a REST-ful API app.py - Your "Flask" application, configuration, and database. auth.py - The authentication system used to protect access to the admin. main.py - this is the secret sauce models.py - Database models for use with your ORM, business logic, etc. views.py - … -
Recent Revsys Updates
Recent Revsys Updates -
Raspberry pi
Abans de festes en Xisco (a.k.a Zigazaga) em va dur la Raspberry, la idea era provar-la per mirar de substituir els ordenadors Pentium IV dels nins, però sobretot veure de primera mà aquest petit dispositiu del qual se n'estava parlant tant a la xarxa. Tanmateix el cost d'un dispositiu així si fa no fa és el d'un sopar sense postres, així que l'experiment si sortia malament tampoc no era excessivament complicat. Xisco va dur la Rasberry i una capseta, tot queda molt compacte, la veritat. Una visita al magatzem xinès del costat de l'oficina va proporcionar el cable per connectar el monitor i vaig reciclar una tarja SD de 32 Gb que tenia sense utilitzar i que ara torna a ser al caixò dels cables. La instal·lació va ser cosa de baixar-se la Rasbian, crear el disc d'instal·lació i seguir les instruccions, en poc menys d'una hora el sistema complet i funcionant, amb l'entorn gràfic i tot. Es pot fer feina, però va molt justet de velocitat. Els nins estan acostumats a jugar online, a l'OpenOffice i ja vaig veure que no aniria gairebé la cosa. Tot i això per fer feina ofimàtica i programar va prou bé. Així que … -
Managing Django Translations with Transifex
We manage a number of open source Django apps here at Caktus. While many of us here are proficient in a number of programming languages, the same can’t be said for our ability to read or write in languages other than English. The Django community is global and we want our apps to support other languages. For that we’ve turned to Transifex which it the same tool Django itself uses for translations. -
Managing Django Translations with Transifex
We manage a number of open source Django apps here at Caktus. While many of us here are proficient in a number of programming languages, the same can’t be said for our ability to read or write in languages other than English. The Django community is global and we want our apps to support other languages. For that we’ve turned to Transifex which it the same tool Django itself uses for translations. If you aren’t familiar with Transifex, it’s an open-source localization platform. There are paid plans for private projects, but you can have a free plan if you are managing translations for an open source project. You can import your translation files, add new languages and review translation progress all with managed teams of translators. You can also make use of machine translation services such as Google Translate or Microsoft Translator. Setting up a project is simple. Once you have an account, you choose to add a new project from the dashboard. You need to pick a name which you can simply match to your project name if it is available. You also need to pick a source language, for us that would be English, and a license. We … -
Filepicker.io and South
I've heard good things about filepicker.io, which is a service that makes file uploading a much better experience. Unfortunately, the Django package for filepicker.io doesn't work with South. When I try to create a migration using the filepicker.io field using code like the following... # products/models.py from django.db import models from django_filepicker.models import FPFileField class Product(models.Model): title = models.CharField(max_length=255) file = FPFileField(upload_to='uploads') ...when I try to run the command: (tsd)$ python manage.py schemamigration products --initial It results in this unpleasant looking response: (tsd)$ python manage.py schemamigration products --initial Creating migrations directory at '/Users/danielgreenfeld/code/tsp/tsp/products/migrations'... Creating __init__.py in '/Users/danielgreenfeld/code/tsp/tsp/products/migrations'... ! Cannot freeze field 'products.product.fpfile' ! (this field has class django_filepicker.models.FPFileField) ! Cannot freeze field 'products.release.fpfile' ! (this field has class django_filepicker.models.FPFileField) ! South cannot introspect some fields; this is probably because they are custom ! fields. If they worked in 0.6 or below, this is because we have removed the ! models parser (it often broke things). ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork The last line in the error report is important. I'll repeat it to illustrate it more clearly: ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork Experience working on other projects has taught me I can simply add two lines of code … -
Filepicker.io and South
I've heard good things about filepicker.io, which is a service that makes file uploading a much better experience. Unfortunately, the Django package for filepicker.io doesn't work with South. When I try to create a migration using the filepicker.io field using code like the following... # products/models.py from django.db import models from django_filepicker.models import FPFileField class Product(models.Model): title = models.CharField(max_length=255) file = FPFileField(upload_to='uploads') ...when I try to run the command: (tsd)$ python manage.py schemamigration products --initial It results in this unpleasant looking response: (tsd)$ python manage.py schemamigration products --initial Creating migrations directory at '/Users/danielgreenfeld/code/tsp/tsp/products/migrations'... Creating __init__.py in '/Users/danielgreenfeld/code/tsp/tsp/products/migrations'... ! Cannot freeze field 'products.product.fpfile' ! (this field has class django_filepicker.models.FPFileField) ! Cannot freeze field 'products.release.fpfile' ! (this field has class django_filepicker.models.FPFileField) ! South cannot introspect some fields; this is probably because they are custom ! fields. If they worked in 0.6 or below, this is because we have removed the ! models parser (it often broke things). ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork The last line in the error report is important. I'll repeat it to illustrate it more clearly: ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork Experience working on other projects has taught me I can simply add two lines of code … -
PUN: Python Usergroup Nederland: what is it?
Summary: 6-8 free meetings per year with a couple of talks and some drinks afterwards. Find new meetings on the Dutch Django association meetup page. The Python Usergroup Netherlands (PUN) is "that which I make summaries of :-)". So I sometimes get the question "what is it?" in my inbox. I got one such question yesterday, so I'll blog my answer :-) The evenings Mostly, the PUN means a meeting every couple of months. The format is two 30-minute talks and 6 5-minute "lightning talks". In the lightning talks everybody can introduce a project (s)he worked on lately, for instance. The bigger 30-minute talks can be anything from "this is how we use python at company XYZ", "3D prototyping with Python", "Plone's new layout engine", etc. The talks are normally in English as not everyone understands Dutch. If we suspect there are only native Dutch speakers around someone might ask whether everyone understands Dutch, in that case we just speak Dutch, naturally :-) Some separate notes: The evenings are free. You don't need to be a member and you don't need to register. Registering (=clicking "I'll be there" on meetup.com) is appreciated, though, as it gives the organizer an idea … -
Off to Europe!
I feel like I'm dreaming, but we're on our way to Europe! A few weeks Audrey and I decided to move. While looking at possible rentals or even mortgages, we were idly (dreaming really... still paying off debts incurred from last year) looking at how much a room/apartment would cost to rent in Europe. To our surprise, we found a lot of good options that cost less then it would to pay monthly rent/mortgage in Los Angeles. o_O Then, we discovered an amazing travel deal. It combined a very cheap red-eye flight from Los Angeles to Fort Lauderdale, and a slow trans-atlantic ship from Port Miami to Barcelona, about as much as a cheap hotel but with free food! If we avoid alcohol and any extra fees, it's actually extremely inexpensive. Being mostly disconnected from the internet would mean we could really focus on a couple of critical projects. If only we had a business justification for going to Europe... It just so happens that we have business in Europe. Our plan is to spend a few months in Europe before returning back to the USA. We'll work hard on the ship, work hard when we arrive, and just get … -
Off to Europe!
I feel like I'm dreaming, but we're on our way to Europe! A few weeks Audrey and I decided to move. While looking at possible rentals or even mortgages, we were idly (dreaming really... still paying off debts incurred from last year) looking at how much a room/apartment would cost to rent in Europe. To our surprise, we found a lot of good options that cost less then it would to pay monthly rent/mortgage in Los Angeles. o_O Then, we discovered an amazing travel deal. It combined a very cheap red-eye flight from Los Angeles to Fort Lauderdale, and a slow trans-atlantic ship from Port Miami to Barcelona, about as much as a cheap hotel but with free food! If we avoid alcohol and any extra fees, it's actually extremely inexpensive. Being mostly disconnected from the internet would mean we could really focus on a couple of critical projects. If only we had a business justification for going to Europe... It just so happens that we have business in Europe. Our plan is to spend a few months in Europe before returning back to the USA. We'll work hard on the ship, work hard when we arrive, and just get … -
Summary of the Dutch Python meeting in Delft
We had a Python meeting tonight (18 april 2013) in Delft at the fox IT offices. I especially liked the open source marketing talk, telling us how to properly tell others about our great projects. (Note: my brother Maurits also made a summary) Github test commit info - Reinout van Rees I gave a quick lighting talk about my githubinfo script that gives you reports on the amount of tests in the last week per project and per developer. Handy for raising awareness for testing amongst your colleages if you mail around the results once a week! The source code is at https://github.com/nens/githubinfo . I already blogged about it, so you can read more there. Devops at fox IT - Ronald Evers Ronald works on detact, a fraud detection for online banking, trying to detect fraud in http traffic for online banking. They sell it to banks. The low-level stuff is in c++, the rest in Python. How do they make it? They use git, so they can use Gerrit, a code review tool. Every commit gets pushed first into a special gerrit branch on github and ends up in the gerrit tool. Every commit needs two upvotes before it … -
Caktus sponsoring and speaking on mobile health at SwitchPoint 2013
SwitchPoint is a one-of-a-kind conference and a unique opportunity to learn, share ideas, and hear about global and mobile health efforts around the world. We had a great time at SwitchPoint last year. I’m excited to announce that Caktus, for the second year in a row, is sponsoring [SwitchPoint 2013]{style=“color: rgb(17, 85, 204);”}. -
Caktus sponsoring and speaking on mobile health at SwitchPoint 2013
SwitchPoint is a one-of-a-kind conference and a unique opportunity to learn, share ideas, and hear about global and mobile health efforts around the world. We had a great time at SwitchPoint last year. I’m excited to announce that Caktus, for the second year in a row, is sponsoring SwitchPoint 2013. At Caktus, we enjoy working on projects that have a positive social impact and have had the opportunity to implement mobile health projects around the world, including in Nigeria, Rwanda, Zambia and Malawi. Caktus currently leads the development of RapidSMS, a free and open-source framework (built in Django) for dynamic data collection, logistics coordination and communication through text messaging (SMS). RapidSMS is used widely across Africa and other parts of the world to improve patient outcomes and save lives in urban and rural areas. Over the past 11 months, Caktus has organized efforts around improving the RapidSMS core codebase, including infrastructure enhancements and coordinating community involvement and participation. Additionally, Caktus is collaborating on UNICEF’s 1000 Days Product, which tracks the first 1000 days between a woman’s pregnancy and her child’s second birthday. 1000 days not only tracks nutrition, which is very important during early child development, but also includes mobile … -
Scheduling Periodic Tasks with Celery 2.3.3 and Django 1.4
There are going to be times in the life of your application when you'll need to perform tasks - making requests to APIs, sending emails, or storing large amounts of data, for example. To do that, you'll most likely want to implement some sort of job queue - that is, a system that lines these tasks up and executes them. Celery is a task queue commonly used with Django - it's open source, easy to integrate with many other languages and frameworks, and it can execute tasks either asynchronously (in the background) or synchronously (wait until ready). This article is going to talk about a very basic Celery implementation for Django - you'll need to have Django installed already, and we'll discuss installing and configuring celery, django-celery (Celery integration for Django), and RabbitMQ (the recommended message broker for celery). If you're using an older version of Celery, it may be a little challenging finding the right docs - for 2.3.3, start with this link: http://docs.celeryproject.org/en/v2.3.3/ And you may want to bookmark this for future reference - the Celery account on GitHub contains repositories for the official celeryproject, as well as django-celery and kombu. https://github.com/celery Installing and configuring Before you get … -
Two Scoops of Django is in print!
Since I was a child I wanted to be a published author. I've dreamt of people reading my book. While one could say that dream was fulfilled when we launched the e-book version in January, it's not the same as seeing the printed copy. Today I got to see my dream come true, a printed book is out there with my name on it. Also, I have a confession to make. When it comes to technical books, I really prefer the print version. For me, nothing beats being able to flip through pages of a hardcopy next to a keyboard, or simply reading while I'm on a bus, train, or plane. So this adds to my excitement when I get to say that the book that Audrey Roy and I wrote together is in print. Note: As of April 17th it's only available in the US. However, it's in the queue for being available for Amazon Europe. Enough people are asking that we are also looking into getting it bulk shipped to Django Circus. While it's been an amazing journey, it's also been a long hard road. Starting with a late night dinner with Randall Degges, his wife Samantha, and … -
Two Scoops of Django is in print!
Since I was a child I wanted to be a published author. I've dreamt of people reading my book. While one could say that dream was fulfilled when we launched the e-book version in January, it's not the same as seeing the printed copy. Today I got to see my dream come true, a printed book is out there with my name on it. Also, I have a confession to make. When it comes to technical books, I really prefer the print version. For me, nothing beats being able to flip through pages of a hardcopy next to a keyboard, or simply reading while I'm on a bus, train, or plane. So this adds to my excitement when I get to say that the book that Audrey Roy and I wrote together is in print. Note: As of April 17th it's only available in the US. However, it's in the queue for being available for Amazon Europe. Enough people are asking that we are also looking into getting it bulk shipped to Django Circus. While it's been an amazing journey, it's also been a long hard road. Starting with a late night dinner with Randall Degges, his wife Samantha, and … -
Logging time, part 2: gtimelog on the commandline
Using github for timelogging is fine, but I longed back to the days when I used a hacked-up of gtimelog that worked on the commandline. I looked in my private git repository with my old subversion stuff and found it. Why gtimelog? Well, in my case, on the commandline, it works quite well. Type in tl weblog on the commandline when I've written a blog entry. Type in tl ror_export when I've worked on that particular project. I've hooked up commandline completion. The end result is a timelog.txt file with a simple line-based format: 2013-04-16 09:36: arrived** 2013-04-16 10:08: compu 2013-04-16 10:31: omnifocus 2013-04-16 11:15: neerslagradar 2013-04-16 11:37: email_en_newsgroups 2013-04-16 11:50: email_en_newsgroups 2013-04-16 12:30: lizard_unbillable 2013-04-16 13:15: lunch** You can modify it afterwards if needed. Lightweight. I get a daily or weekly report out of it like this: Blokkendoos 3 hours 24 min Compu 32 min Email_en_newsgroups 35 min Lizard_unbillable 2 hours 6 min Neerslagradar 44 min The regular gtimelog requires gtk, which isn't handy on OSX. On debian/ubuntu you can apt-get install it. You get a window-based interface that way and can click entries and have a constant overview and so. That said, I hacked up a modified version … -
Logging time, part 1: github for timelogging
I've got to keep track of what I work on. The company I work for (Nelen & Schuurmans) is pretty much focused on projects, so that's what you should book your hours on. This is both for billing to clients and for internal bookkeeping: projects should be profitable, ideally, so we need to keep track of it. Now... how to do this? I fill in my hours two or three times during the month. And my memory isn't that good that I remember everything. So I look in my agenda for free days, meetings, that sort of stuff. But the majority of my work isn't in my agenda, it is in code. And the code... is in github, mostly. So what I do when filling in my hours is looking at the github timeline. See https://github.com/reinout, at the bottom is my contribution activity. That tells me enough on what I did in the last week. A different view is gitspective, see for instance my timeline. It gives you a different timeline, better for filling in your hours than github's. Apart from one detail: it misses the private repositories you worked on. And our Django sites are all private because of … -
Django and RequireJS
Until very recently, I was very happy with [django-compressor](http://django-compressor.readthedocs.org/en/latest/). It does a great job of combining and minifying static media files, specifically JavaScript and CSS files. It will manage compilation, allowing you to use, for example, SASS and CoffeeScript. Not that I do. But, for me, the best part was the cache invalidation. By combining JavaScript (or CSS) into files that get named according to a hash of their contents, it's trivial for clients to not have an old cached JS or CSS file. However, recently I have begun using [RequireJS](http://requirejs.org). This enables me to declare dependencies, and greatly simplify the various pages within my site that use specific JavaScript modules. But this does not play so well with django-compressor. The problem lies with the fact that there is no real way to tell RequireJS that "instead of ``js/file.js``, it should use ``js/file.123ABC.js``", where ``123ABC`` is determined by the static files caching storage. RequireJS will do optimisation, and this includes combining files, but that's not exactly what I want. I could create a built script for each page that has a ``require()`` call in it, but that would mean ``jQuery`` etc get downloaded seperately for each different script. I have … -
Django for Web Prototyping
Or how to use the benefits of Django template system during the PSD to HTML phase There are two main approaches to start designing a new project – Photoshop mock-up or an HTML prototype. The first one is more traditional and well established in the web industry. The second one is more alternative and (maybe)modern. I remember a video of Jason Fried from 37 Signals where he talks about design and creativity. You can see it at http://davegray.nextslide.com/jason-fried-on-design. There he explains how he stays away from the Photoshop in the initial phase to concetrate on the things that you can interact with instead of focusing on design details. I am not planning to argue which is the better method, the important thing here is that sooner or later you get to the point where you have to start the HTML coding. Unfortunately frequently this happens in a pure HTML/CSS environment outside of the Django project and then we waste some extra amount of time to convert it to Django templates. Wouldn’t be awesome if you can give the front-end developers something that they can install/run with a simple command and still to allow them to work in the Django environment … -
Generating NCX files with Python
With the help of fellow Python developer Matt Harrison's excellent Ebook Formatting: KF8, Mobi & EPUB, we managed to create pretty decent looking Kindle and ePub versions of Two Scoops of Django. One of many things we did was focus on providing an excellent table of contents. Of course we provided one inside the content of the book, but much like the PDF version we also provided one that various ebook readers can display in sidebars or drop down menus. Unfortunately, building this navigation isn't well documented (except for Matt's book), and I've yet to see any good ways to generate it via code. Which is why I present the following code. It looks at the HTML that KindleGen and ePub generators demand and pulls from it a chapter-based table of contents. Then constructs a .ncx file, which is what ebook readers use to generate the sidebar/dropdown table of contents. Our requirements: Jinja2 Django BeautifulSoup4 And now the code: #!/usr/bin/python # -*- coding: utf-8 -*- from bs4 import BeautifulSoup from django.utils.text import slugify from jinja2 import Template TEMPLATE = Template("""<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"> <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en"> <head> <!-- The content of dtb:uid must …