Bugfixes and Beyond
-
Upload
jannis-leidel -
Category
Technology
-
view
3.932 -
download
0
description
Transcript of Bugfixes and Beyond
![Page 1: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/1.jpg)
Bugfixes and Beyond
Jannis Leidel
Django Usergroup BerlinApril 5, 2011
![Page 2: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/2.jpg)
1.3“bugfix release”
![Page 3: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/3.jpg)
How many fixes?*
1,330 changed files
85,030 additions
39,884 deletions
* translation updates excluded
![Page 4: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/6.jpg)
Data loss bugs, yikes!
FileField file deletion.
See https://gist.github.com/889692
![Page 7: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/8.jpg)
What‘s new?Class-based views
Logging
Static files
Caching
Internationalization
and many more…
![Page 9: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/9.jpg)
Class-based views
![Page 10: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/13.jpg)
Other well-knowns
ListView, DetailView, RedirectView
ArchiveIndexView, YearArchiveView, MonthArchiveView, WeekArchiveView, DayArchiveView, TodayArchiveView, DateDetailView
FormView, CreateView, UpdateView, DeleteView
![Page 14: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/14.jpg)
Logging
![Page 15: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/15.jpg)
Yup, good ol‘ logging
import logging
logging.info("Yay!")
![Page 16: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/16.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/17.jpg)
Static files
![Page 18: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/18.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/19.jpg)
django.contrib.staticfilescollects static files from multiplelocations into a central location
![Page 20: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/20.jpg)
STATIC_ROOT = "/var/www/static/"STATIC_URL = "/static/"
![Page 21: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/21.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/22.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/23.jpg)
Caching
![Page 24: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/24.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/25.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/26.jpg)
Internationalization
![Page 27: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/27.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/28.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/29.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/30.jpg)
More information
1.3 release notes http://django.me/releases-1.3
![Page 31: Bugfixes and Beyond](https://reader034.fdocuments.net/reader034/viewer/2022052619/55621f44d8b42af6668b4697/html5/thumbnails/31.jpg)
Questions?
@jezdez