bugfixes and beyond
DESCRIPTION
The slides of the talk I gave at the Django Usergroup Berlin.TRANSCRIPT
Bugfixes and Beyond
Jannis Leidel
Django Usergroup BerlinApril 5, 2011
1.3“bugfix release”
How many fixes?*
1,330 changed files
85,030 additions
39,884 deletions
* translation updates excluded
What‘s removed?
AdminSite.root()
Authentication backends that don’t support anonymous users and object permissions.
See http://django.me/deprecation for past present and future deprecation
Security fixes!Added CSRF validation for AJAX requests.
Placed restrictions on filters in the admin interface.
Stopped rendering passwords in PasswordInput.
Stopped allowing password resets for inactive accounts.
Data loss bugs, yikes!
FileField file deletion.
See https://gist.github.com/889692
Backwards incompatibleClearable FileField widget is default (override it if you want the old behavior).
No more PROFANITIES_LIST
Localflavor corrections for Canada, Indonesia, and the USA.
FormSets can no longer take empty data.
Initial SQL no longer works in tests (use fixtures instead)
What‘s new?Class-based views
Logging
Static files
Caching
Internationalization
and many more…
Class-based views
Hello, view!
# hello/views.pyfrom django.views.generic import TemplateView
class HelloView(TemplateView): template_name = "hello.html"
def get_context_data(self, **kwargs): return { 'greeted': 'world', }
URLconf, ahoy!
# hello/urls.pyfrom django.conf.urls.defaults import *
from hello.views import HelloView
urlpatterns = patterns('', (r'^hello/', HelloView.as_view()),)
as_view args, yeah!
# hello/urls.pyfrom django.conf.urls.defaults import *
from hello.views import HelloView
# as_view args passed to HelloView.__init__()urlpatterns = patterns('', (r'^hello/', HelloView.as_view( template_name="ciao.html" )),)
Other well-knowns
ListView, DetailView, RedirectView
ArchiveIndexView, YearArchiveView, MonthArchiveView, WeekArchiveView, DayArchiveView, TodayArchiveView, DateDetailView
FormView, CreateView, UpdateView, DeleteView
Logging
Yup, good ol‘ logging
import logging
logging.info("Yay!")
Okay, there is more…
LOGGING setting to configure logging filters and handler, e.g. database handlers
Built-in loggers django, django.request, django.db.backends
Built-in handler AdminEmailHandler, sending to adresses in the ADMINS setting
Static files
The notorious life of the MEDIA_* settings
“media” – files uploaded/generated by users, e.g. via FileField and ImageField
“static” – static assets that are part of your site, e.g. Stylesheets, Images, JavaScript
django.contrib.staticfilescollects static files from multiplelocations into a central location
STATIC_ROOT = "/var/www/static/"STATIC_URL = "/static/"
Using staticfiles in development
Add 'django.contrib.staticfiles' to INSTALLED_APPS
Put static files in <app>/static
Add additional paths (e.g. “project files”) to STATICFILES_DIRS setting (optional)
Deployment
Use collectstatic management command to collect all files in one location
Uses standard storage API, able to deploy to S3 and other cloud storages*
Or, use your own deployment tool with STATIC_ROOT
Caching
Multiple backends# settings.pyCACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'my_cache_table', }, 'redis': { 'BACKEND': 'my_cache.backends.RedisCache', 'LOCATION': '127.0.0.1:6379', 'DATABASE': 11, }}
# hello/whatever.pyfrom django.core.cache import get_cache
redis = get_cache('redis')
print redis.get('greeting')
MOAR features!Versions
cache.set('greeting', 'world', version=2)
Prefixes
KEY_PREFIX = 'dutch-edition'
Key transformations
def minor_version_key(key, key_prefix, version): if key == "frontpage": version = "%s.%s" % (version, settings.MINOR_VERSION) return ':'.join( [key_prefix, version, str(key)])
Internationalization
Contexts, finally!# hello/views.pyfrom django.utils.translation import \
pgettext_lazy
month = pgettext_lazy("month name", "May")
# hello/locale/de/LC_MESSAGES/django.pomsgctxt "month name"msgid "May"msgstr "Mai"
Leave a comment# hello/views.pyfrom django.utils.translation import \ ugettext_lazy
class HelloView(TemplateView): template_name = "hello.html"
def get_context_data(self, **kwargs): # Translators: The people you greet greeted = ugettext_lazy("world") return { 'greeted': greeted, }
Leave a comment# hello/templates/base.html{% comment %}Translators: Remember to translate this correctly, dammit!{% endcomment %}{% blocktrans %} Hello, world!{% endblocktrans %}
# hello/locale/de/LC_MESSAGES/django.po#. TRANSLATORS: Remember to translate this correctly, dammit!msgid "Hello, world!"msgstr "Hallo Welt!"
More information
1.3 release notes http://django.me/releases-1.3
Questions?
@jezdez