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
| # encoding: utf-8 | |
| # Derived from Piotr Maliński's example with a few modifications to use logging and : | |
| # http://www.rkblog.rk.edu.pl/w/p/profiling-django-object-size-and-memory-usage-pympler/ | |
| from pympler import muppy | |
| from pympler.muppy import summary | |
| from pympler.asizeof import asizeof | |
| from django.conf import settings | |
| import logging |
| # encoding: utf-8 | |
| from django.core.exceptions import ImproperlyConfigured | |
| from django.http import HttpResponseRedirect | |
| from django.utils.text import force_text | |
| from django.views.generic import View | |
| from django.views.generic.base import ContextMixin, TemplateResponseMixin | |
| class MultipleFormMixin(ContextMixin): | |
| """MultipleFormMixin -- Mixin that provides methods to show and handle |
| from django import forms | |
| from django.core.exceptions import ValidationError | |
| from .models import Foo | |
| class VersionNumberFormMixin(forms.Form): | |
| version_number = forms.IntegerField(min_value=0, widget=forms.HiddenInput) | |
| def __init__(self, *args, **kwargs): |
| import pip | |
| try: | |
| from setuptools import setup, find_packages | |
| except ImportError: | |
| from distutils.core import setup, find_packages | |
| links = [] # for repo urls (dependency_links) | |
| requires = [] # for package names |
| import concurrent.futures | |
| import muffin | |
| app = muffin.Application( | |
| 'process_executor' | |
| ) | |
| ''' | |
| Cache the generic relation field of all the objects | |
| in the queryset, using larger bulk queries ahead of time. | |
| Improved from original by Daniel Roseman: | |
| http://blog.roseman.org.uk/2010/02/22/django-patterns-part-4-forwards-generic-relations/ | |
| and | |
| justinfx's gist cache_generics.py : |
| from django.views.generic import ListView | |
| from django.views.generic.edit import FormMixin | |
| from django.db.models import Q | |
| class SearchView(FormMixin, ListView): | |
| template_name_suffix = '_search' | |
| filter_operator = 'contains' | |
| allow_or_operator = False | |
| def get_filter_operator(self): |