django from nightmare to dream
play

Django, from nightmare to dream with Best Practices by Stphane - PowerPoint PPT Presentation

Django, from nightmare to dream with Best Practices by Stphane Wirtel EuroPython 2017 - Rimini/y ;-) 11 Luglio 2017 1 / 69 Hello, I am Stphane Python Freelancer Open Source = My Passion/Job PythonFOSDEM CPython contributor PSF, EPS


  1. Django, from nightmare to dream with Best Practices by Stéphane Wirtel EuroPython 2017 - Rimini/y ;-) 11 Luglio 2017 1 / 69

  2. Hello, I am Stéphane Python Freelancer Open Source = My Passion/Job PythonFOSDEM CPython contributor PSF, EPS members, CSA from PSF former core dev of Odoo (Open Source ERP) blah blah Python blah 2 / 69

  3. ep2017.europython.org 3 / 69

  4. EuroPython website -> epcon https://github.com/EuroPython/epcon 4 / 69

  5. with epcon, we can do... conference management 5 / 69

  6. with epcon, we can do... conference management ticket management 6 / 69

  7. with epcon, we can do... conference management ticket management statistics (attendees, speakers, (un)assigned or orphan tickets) 7 / 69

  8. with epcon, we can do... conference management ticket management statistics (attendees, speakers, (un)assigned or orphan tickets) invoice/refund 8 / 69

  9. with epcon, we can do... conference management ticket management statistics (attendees, speakers, (un)assigned or orphan tickets) invoice/refund helpdesk 9 / 69

  10. with epcon, we can do... conference management ticket management statistics (attendees, speakers, (un)assigned or orphan tickets) invoice/refund helpdesk notifications by email 10 / 69

  11. with epcon, we can do... conference management ticket management statistics (attendees, speakers, (un)assigned or orphan tickets) invoice/refund helpdesk notifications by email hotel and room booking sim card 11 / 69

  12. epcon is a good tool for EuroPython 12 / 69

  13. but ... 13 / 69

  14. 14 / 69

  15. State of Union Python 2.7 (support 2020) 15 / 69

  16. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) 16 / 69

  17. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) 17 / 69

  18. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite 18 / 69

  19. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) 19 / 69

  20. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian 20 / 69

  21. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code 21 / 69

  22. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code no async for jobs 22 / 69

  23. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code no async for jobs no Continuous Integration / Continuous Deployment 23 / 69

  24. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code no async for jobs no Continuous Integration / Continuous Deployment no API for external tools need to export data (mobile app, ticket search app, etc...) 24 / 69

  25. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code no async for jobs no Continuous Integration / Continuous Deployment no API for external tools need to export data (mobile app, ticket search app, etc...) no syslog, just send error with exception to the mailing list. 25 / 69

  26. State of Union Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (Python 168 files and 27487 lines of code) no documentation , some comments are in Italian duplicated/ dead code no async for jobs no Continuous Integration / Continuous Deployment no API for external tools need to export data (mobile app, ticket search app, etc...) no syslog, just send error with exception to the mailing list. settings were hardcoded , no environment variables 26 / 69

  27. 27 / 69

  28. and seriously we are not alone in this case. 28 / 69

  29. But, don't forget one thing ! 29 / 69

  30. in fact, there is a lot of things 30 / 69

  31. in fact, there is a lot of things Many former developers (it's an open source project) Inherited from PyCon Italia 2009 31 contributors since 2009 (first version) 31 / 69

  32. in fact, there is a lot of things Many former developers (it's an open source project) Inherited from PyCon Italia 2009 31 contributors since 2009 (first version) Volunteers 32 / 69

  33. in fact, there is a lot of things Many former developers (it's an open source project) Inherited from PyCon Italia 2009 31 contributors since 2009 (first version) Volunteers Free time 33 / 69

  34. in fact, there is a lot of things Many former developers (it's an open source project) Inherited from PyCon Italia 2009 31 contributors since 2009 (first version) Volunteers Free time No web dev, but data scientist, backend dev 34 / 69

  35. We have a real challenge 35 / 69

  36. We have a real challenge Continuous Integration / Continuous Deployment 36 / 69

  37. We have a real challenge Continuous Integration / Continuous Deployment Documentation 37 / 69

  38. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration 38 / 69

  39. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests 39 / 69

  40. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests Write Code/Refactoring 40 / 69

  41. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests Write Code/Refactoring Quality of code 41 / 69

  42. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests Write Code/Refactoring Quality of code Profiling 42 / 69

  43. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests Write Code/Refactoring Quality of code Profiling Deployment 43 / 69

  44. We have a real challenge Continuous Integration / Continuous Deployment Documentation Configuration Tests Write Code/Refactoring Quality of code Profiling Deployment Monitoring 44 / 69

  45. Continuous Integration Travis (https://www.travis.org) language: python python: - "2.7" install: - pip install -r requirements-dev.txt script: "python manage.py compilemessages && python manage.py test" 45 / 69

  46. Documentation Sphinx 46 / 69

  47. Con�guration django-dotenv Your .env file POSTGRES_USER="postgres" POSTGRES_PASSWORD="" SECRET_KEY="whoami" ALLOWED_HOSTS='' CSRF_COOKIE_SECURE= False DEBUG= True ENVIRONMENT='LOCAL' DJANGO_SETTINGS_MODULE=dev-settings Your manage.py file import dotenv if __name__ == '__main__': dotenv.read_dotenv() os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") ... 47 / 69

  48. Tests unittest / pytest django.test / pytest-django mock / pytest-mock 48 / 69

  49. Tests coverage / pytest-cov django-coverage-plugin 49 / 69

  50. Tests django-test-without-migrations and pytest-django python manage test --nomigrations # or pytest --nomigrations 50 / 69

  51. Tests factory_boy and django-factoryboy class TalkFactory (factory.django.DjangoModelFactory): class Meta : model = 'conference.Talk' title = factory.LazyAttribute( lambda talk: fake.sentence(nb_words=6, variable_nb_words= sub_title = factory.Faker('sentence', nb_words=12, variable_nb_words= True ) slug = factory.LazyAttribute( lambda talk: slugify(talk.title)) level = factory.Iterator(conference.models.TALK_LEVEL, getter= lambda x: x[0]) status = factory.Iterator(conference.models.TALK_STATUS, getter= lambda x: x[0]) conference = factory.Iterator(conference.models.Conference.objects.all().values_list( language = factory.Iterator(TALK_LANGUAGES, getter= lambda x: x[0]) Definition of a Factory in app/tests/factories/model.py 51 / 69

  52. Write Code/Refactoring These tools will help your code With the tests, you can start to rewrite the bad code pyflake8 , pylint vulture django-pdb and --ipdb pdbpp (pdb++) (for pytest ) or ipdb 52 / 69

Recommend


More recommend