Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django 1.6: The best new features & the important changes

Django 1.6: The best new features & the important changes

Talk given at the SF Django Meetup on July 25th, 2013.
More details: http://www.meetup.com/The-San-Francisco-Django-Meetup-Group/events/129880002/

7617093fdae20c6fe4b0f7fe954a8aad?s=128

Julien Phalip

July 25, 2013
Tweet

Transcript

  1. DJANGO 1.6: DJANGO 1.6: THE BEST NEW FEATURES THE BEST

    NEW FEATURES & THE IMPORTANT CHANGES & THE IMPORTANT CHANGES presented by Julien Phalip ( ) @julienphalip SF Django Meetup — July 25th, 2013
  2. WHO'S THAT? WHO'S THAT? Julien Phalip ( ) Technical director

    at (Previously known as Odopod) Using Django since 2007 (ver 0.96) Django core committer since 2011 @julienphalip Nurun SF
  3. THE ROAD TO DJANGO 1.6... THE ROAD TO DJANGO 1.6...

  4. TIMELINE TIMELINE Version Date Time since previous release 1.0 Sep

    3, 2008 — 1.1 Jul 29, 2009 11 months 1.2 May 17, 2010 9.5 months 1.3 Mar 23, 2011 10 months 1.4 Mar 23, 2012 12 months 1.5 Feb 26, 2013 11 months 1.6 Late Aug, 2013 6 months
  5. THE FLAGSHIP THE FLAGSHIP NEW FEATURES NEW FEATURES

  6. PYTHON 3 SUPPORT PYTHON 3 SUPPORT Experimental since Django 1.5.

    Now officially supported, without restrictions. New Python.org will run on Django and Python 3. ( ) http://preview.python.org/
  7. PORTING YOUR APPS TO PYTHON 3 PORTING YOUR APPS TO

    PYTHON 3 Guide in official documentation: Jacob Kaplan-Moss' Pycon talk: http://tinyurl.com/django-python3 http://tinyurl.com/jkm-pycon-python3
  8. BETTER TRANSACTION BETTER TRANSACTION MANAGEMENT MANAGEMENT The old API had

    barely changed since 0.9x and was frustrating to work with. New API is leaner, simpler, more explicit, more correct. Easier, fine-grained rollbacks between savepoints. Easier error management.
  9. WARNING: WARNING: BACKWARDS INCOMPATIBLE BACKWARDS INCOMPATIBLE Database-level a u t

    o c o m m i t is now turned on by default: Every SQL statement gets committed right away. Detailed upgrading instructions: For more details, see Aymeric Augustin's DjangoCon Europe talk: http://tinyurl.com/transactions-upgrade http://tinyurl.com/djangocon-eu-transactions
  10. NEW HIGH-LEVEL 'ATOMIC' FUNCTION NEW HIGH-LEVEL 'ATOMIC' FUNCTION t r

    a n s a c t i o n . a t o m i c : Commits on success, rolls back on exceptions. Inspired from http://tinyurl.com/django-atomic https://github.com/Xof/xact
  11. Can be used as decorator: Can be used as context

    manager: Can be nested. f r o m d j a n g o . d b i m p o r t t r a n s a c t i o n @ t r a n s a c t i o n . a t o m i c d e f v i e w f u n c ( r e q u e s t ) : # T h i s c o d e e x e c u t e s i n s i d e a t r a n s a c t i o n . d o _ s t u f f ( ) f r o m d j a n g o . d b i m p o r t t r a n s a c t i o n d e f v i e w f u n c ( r e q u e s t ) : # T h i s c o d e e x e c u t e s i n a u t o c o m m i t m o d e # ( D j a n g o ' s d e f a u l t ) . d o _ s t u f f ( ) w i t h t r a n s a c t i o n . a t o m i c ( ) : # T h i s c o d e e x e c u t e s i n s i d e a t r a n s a c t i o n . d o _ m o r e _ s t u f f ( )
  12. PERSISTENT DATABASE PERSISTENT DATABASE CONNECTIONS CONNECTIONS Before: New connection opened

    for each HTTP request. Now: Same connection reused between requests. One connection per worker thread. New setting: C O N N _ M A X _ A G E (defaults to 0 , i.e. turned off by default) Not as powerful as or ... ... but should still drastically improve performance (See Craig Kerstiens' blog post: ) Caveat: Not extensively tested in production yet... PgBouncer PgPool http://tinyurl.com/fixing-connections
  13. NEW TEST RUNNER NEW TEST RUNNER More in line with

    u n i t t e s t and Python standards. Saner test discovery system.
  14. MORE FLEXIBILITY MORE FLEXIBILITY FOR RUNNING TESTS FOR RUNNING TESTS

    Before: Run all tests in an app, all tests in a certain T e s t C a s e or one test method. Now: Run all tests within a certain directory (recursively), all tests in a certain test file, or all tests in a certain T e s t C a s e , or a particular test method.
  15. NO MORE OF THIS! NO MORE OF THIS! m y

    a p p / t e s t s / _ _ i n i t _ _ . p y : f r o m a a a a a a a i m p o r t * f r o m b b b b b b b b b i m p o r t * f r o m c c c c i m p o r t * f r o m d d d d d d d i m p o r t * f r o m e e e e e e i m p o r t * f r o m f f f i m p o r t *
  16. MORE EXPLICIT MORE EXPLICIT Only run the tests you care

    about. Avoid running tests for third-party code (django.contrib, pip-installed apps).
  17. CAVEATS CAVEATS Tests in m o d e l s

    . p y must be moved to a t e s t * . p y file. Doctests must be explicitly loaded: New runner enabled by default. To revert to the old behavior: http://tinyurl.com/load-doctests T E S T _ R U N N E R = ' d j a n g o . t e s t . s i m p l e . D j a n g o T e s t S u i t e R u n n e r '
  18. OTHER NEW FEATURES OTHER NEW FEATURES Pillow preferred over PIL

    Q u e r y s e t . e a r l i e s t ( ) , . f i r s t ( ) and . l a s t ( ) Database lookups by hour, minute, second BinaryField M o d e l A d m i n . p r e s e r v e _ f i l t e r s HTML5 types for input fields (email, url, number) Admin's jQuery upgraded to 1.9.1 Multiple documentation improvements, including a And many, many small features... Many bug fixes... deployment checklist
  19. BACKWARDS-INCOMPATIBLE CHANGES BACKWARDS-INCOMPATIBLE CHANGES New transactions API: New test runner

    enabled by default. B o o l e a n F i e l d now defaults N o n e instead of F a l s e . Whole list: Should be easy to upgrade for most people. http://tinyurl.com/transactions-incompatible http://tinyurl.com/django-1-6-incompatible
  20. REMOVED FROM DJANGO REMOVED FROM DJANGO Removed contrib apps: databrowse,

    markup & localflavor. django.utils.text.truncate_words() and django.utils.text.truncate_html_words() removed in favor of the django.utils.text.Truncator class Detailed list of past deprecations: http://tinyurl.com/django-1-6-removed
  21. FURTHER NOTES FURTHER NOTES Support for Django 1.4 (security patches)

    probably extended. Python 2.6 still supported in Django 1.6 but probably dropped in Django 1.7.
  22. HOW CAN YOU HELP? HOW CAN YOU HELP? Test your

    apps against the 1.6 beta release or the 1.6.x branch on Github. any regressions or bugs in new features. Help triage in Trac. Contribution guide: Report unreviewed tickets http://tinyurl.com/django-contribute
  23. CREDITS CREDITS & for letting me pick their brains while

    preparing this talk. for inviting me and for running the SF Django Meetup. for kindly hosting this meetup. Aymeric Augustin Carl Meyer Rudy Mutter IGT
  24. THANK YOU THANK YOU FOR LISTENING! FOR LISTENING! ANY QUESTIONS...?

    ANY QUESTIONS...? Get in touch: @julienphalip