A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
# Creating Template | |
$ find . -iname "*.py" -exec xgettext -o messages.pot {} \; | |
# Copy template message.pot into locale/XX/LC_MESSAGES | |
# For example (this is a typical django app tree structure) | |
... | |
│ ├── locale | |
│ │ ├── en | |
│ │ │ └── LC_MESSAGES | |
│ │ │ ├── django.mo |
# -*- coding: utf-8 -*- | |
""" | |
Search features for an elasticsearch / haystack / elasticstack | |
:creationdate: 05/11/15 15:05 | |
:moduleauthor: François GUÉRIN <[email protected]> | |
:modulename: intrautils.search | |
""" | |
import base64 |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
import haystack | |
from django.core.management import call_command | |
from django.test.utils import override_settings | |
TEST_INDEX = { | |
'default': { | |
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', | |
'URL': 'http://127.0.0.1:9200/', |
import __builtin__ | |
original_import = __builtin__.__import__ | |
def log_import(name, globals={}, locals={}, fromlist=[], level=-1): | |
print name | |
return original_import(name, globals=globals, locals=locals, fromlist=fromlist, level=level) | |
__builtin__.__import__ = log_import |
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import | |
from django.conf import settings | |
from haystack.backends.elasticsearch_backend import ( | |
ElasticsearchSearchBackend, ElasticsearchSearchEngine, ElasticsearchSearchQuery) | |
from haystack.query import SearchQuerySet | |
""" | |
Script to identify accounts followed older than 4 months. | |
Source blogpost: http://www.rainbowbreeze.it/identify-your-twitter-followings-older-that-4-months | |
""" | |
import tweetpony | |
from datetime import timedelta, datetime | |
import urllib3.contrib.pyopenssl | |
import time |
# -*- coding: utf-8 -*- | |
from functools import wraps | |
def memoize(obj): | |
""" | |
From Python Decorator Library | |
""" | |
cache = obj.cache = {} |
class MyForm(forms.Form): | |
some_field = forms.CharField() | |
class MyWizard(SessionWizardView): | |
# ...do some stuff... | |
# And a url like: | |
url(r'^wizard/$', views.MyWizard.as_view([MyForm, MyOtherForm])) |