bugfixes and beyond

31
Bugfixes and Beyond Jannis Leidel Django Usergroup Berlin April 5, 2011

Upload: jannis-leidel

Post on 25-May-2015

3.930 views

Category:

Technology


0 download

DESCRIPTION

The slides of the talk I gave at the Django Usergroup Berlin.

TRANSCRIPT

Page 1: Bugfixes and Beyond

Bugfixes and Beyond

Jannis Leidel

Django Usergroup BerlinApril 5, 2011

Page 2: Bugfixes and Beyond

1.3“bugfix release”

Page 3: Bugfixes and Beyond

How many fixes?*

1,330 changed files

85,030 additions

39,884 deletions

* translation updates excluded

Page 4: Bugfixes and Beyond

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

Page 5: Bugfixes and Beyond

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.

Page 6: Bugfixes and Beyond

Data loss bugs, yikes!

FileField file deletion.

See https://gist.github.com/889692

Page 7: Bugfixes and Beyond

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)

Page 8: Bugfixes and Beyond

What‘s new?Class-based views

Logging

Static files

Caching

Internationalization

and many more…

Page 9: Bugfixes and Beyond

Class-based views

Page 10: Bugfixes and Beyond

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', }

Page 11: Bugfixes and Beyond

URLconf, ahoy!

# hello/urls.pyfrom django.conf.urls.defaults import *

from hello.views import HelloView

urlpatterns = patterns('', (r'^hello/', HelloView.as_view()),)

Page 12: Bugfixes and Beyond

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" )),)

Page 13: Bugfixes and Beyond

Other well-knowns

ListView, DetailView, RedirectView

ArchiveIndexView, YearArchiveView, MonthArchiveView, WeekArchiveView, DayArchiveView, TodayArchiveView, DateDetailView

FormView, CreateView, UpdateView, DeleteView

Page 14: Bugfixes and Beyond

Logging

Page 15: Bugfixes and Beyond

Yup, good ol‘ logging

import logging

logging.info("Yay!")

Page 16: Bugfixes and Beyond

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

Page 17: Bugfixes and Beyond

Static files

Page 18: Bugfixes and Beyond

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

Page 19: Bugfixes and Beyond

django.contrib.staticfilescollects static files from multiplelocations into a central location

Page 20: Bugfixes and Beyond

STATIC_ROOT = "/var/www/static/"STATIC_URL = "/static/"

Page 21: Bugfixes and Beyond

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)

Page 22: Bugfixes and Beyond

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

Page 23: Bugfixes and Beyond

Caching

Page 24: Bugfixes and Beyond

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')

Page 25: Bugfixes and Beyond

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)])

Page 26: Bugfixes and Beyond

Internationalization

Page 27: Bugfixes and Beyond

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"

Page 28: Bugfixes and Beyond

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, }

Page 29: Bugfixes and Beyond

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!"

Page 30: Bugfixes and Beyond

More information

1.3 release notes http://django.me/releases-1.3

Page 31: Bugfixes and Beyond

Questions?

@jezdez