DjangoCon 2015 lightning recap

Presenter Notes

Me (Romain Garrigues @rgarrigues)

Presenter Notes

Overall feeling

  • Focused on well being (and burnout/depression witness)
  • Friendly community (lot of first-time speakers)
  • Need to go outside (meet people, see real talks)

Presenter Notes

Architecture / Separating concerns

(@HannaKollo, @codeinthehole)

  • Avoid big views.py files.
  • Use service layers to move business logic from views.

This:

1 def my_view(request):
2     params = request.GET
3     # Lot of code here before returning HttpResponse
4     # ...
5     return HttpResponse("This is a too big view")

could be:

1 from my_project.services import deal_with_data
2 
3 def my_view(request):
4     params = request.GET
5     deal_with_data(params)
6     return HttpResponse("We have separated business from view logic")

Presenter Notes

Testing

(@magopian, @RaeKnowler)

py.test

  • Syntax more pythonic,
  • Interesting options (launch only last failed tests)
  • pytest-django: --reuse-db and --create-db

Added value compare to manage test:

  • verbatim output when test is failing, (dict assertion will give exact missing or excess element, instead of full dict)
  • hide all logging when test are passing by default
  • the console output is more readable and intuitive

Presenter Notes

Testing ... 2

Hypothesis

Use randomised data and find edge cases for you

1 @given(floats())
2 def test_negation_is_self_inverse(x):
3     assert x == -(-x)

Presenter Notes

Django admin

(@olasitarska)

  • Use for: small tricks to improve UI
  • Other themes: django-flat-theme, django-suit (commercial)
  • Don't use for: end-users UI, big customisations
  • Don't allow admin to do massive damage to website. (deleting critical entry, etc)

django admin dashboard with django-flat-theme

Presenter Notes

Security

(@erikpub, @ubernostrum)

  • Test 12 basic security issues: ponycheckup.com
  • Examples of Django protections:
    • Timing attack on password
    • Sanity checks on choice field (can't give unexpected choice to server)
  • Check your package versions requires.io

Presenter Notes

Rabbit hole

(@asendecka, @thomaswturner)

Definition

  • Trying to resolve a problem that takes ages at the end
  • Hard to diagnose
  • Ask for help, do some breaks

Example (Django on Desktop)

Unbelievable stack (Django, C++, Firebird, CEF, Sikuli)

Presenter Notes

Performance issues

(@piquadrat_ch)

Big Three

  • Step 1: reduce SQL queries (select_related, prefetch_related on reverse FKey/M2M)
  • Step 2: do less work
    • move work out of request/response cycle (celery)
    • only fetch what you need (QuerySet.defer())
    • do calculations on the db (annotate, aggregate)
  • Step 3: caching (hard to invalidate, johnny-cache or django-cache-machine)

Tools

  • django-debug-toolbar
  • django-devserver

Presenter Notes

Real-time

(@aaronbassett)

Swamp dragon

swampdragon architecture

Presenter Notes

ORM

(@akaariai)

  • Improving API for lookup, transforms, expressions

HStoreField (PostGreSQL, Django 1.8+)

1 class Dog(models.Model):
2     data = HStoreField()
3 
4 Dog.objects.create(data={'breed': 'labrador', 'owner': 'Bob'})
5 Dog.objects.filter(data__breed='collie')

ArrayField (PostGreSQL, Django 1.8+)

1 class Post(models.Model):
2     tags = ArrayField(models.CharField(max_length=200), blank=True)
3 
4 Post.objects.create(name='First post', tags=['thoughts', 'django', 'd'])
5 Post.objects.filter(tags__contains=['django', 'thoughts'])

Presenter Notes

Useful tools

git-crypt

Encrypt/decrypt files on GitHub

Initialise your repository:

!shell
git-crypt init

Create a .gitattributes file to encrypt (in this example) .key files

!text
secretfile filter=git-crypt diff=git-crypt
*.key filter=git-crypt diff=git-crypt

cookiecutter

Django project templating

CAMEL project

Convert LaTeX documents to data saved in database, and render it through Django.

Presenter Notes

iwoca-logo

  • Lend money to small/medium businesses,
  • Non middle-age technologies

iwoca architecture

Presenter Notes

Conclusion

  • REALLY friendly
  • Take care of yourself !!
  • Not so technical -> djangounderthehood.com
  • Pies in pieminister and welsh cakes were ... waouh.
  • Presentation available @ https://github.com/romgar/presentations/

Presenter Notes