SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
Pluggable Patterns
                           For Reusable Django Applications




Friday, March 11, 2011
An app                           MyBlog App
        should not be               • Categories
                                    • Custom Tagging
        a monolithic                • Custom Comments
        pile of code                • Comment
                                      Moderation
                                    • Assumption of text
                                      markup type
                                    • Single blogs
         For example, most blog     • Multiple Sites
         “apps” available provide
         too much functionality           ACME MONOLITHS
Friday, March 11, 2011
An application should
                            be “pluggable”


Friday, March 11, 2011
A “pluggable” app is
                               Focused
                         Write programs that do one thing and do it well.
                            — Doug McIlroy (inventor of UNIX pipes)

Friday, March 11, 2011
A “pluggable” app is
                            Self-Contained
                               Batteries are included
                             Dependencies are declared

Friday, March 11, 2011
A “pluggable” app is
                             Easily Adaptable
                         Corey’s Law: The less adaptable you make your code, the
                                   sooner you will be tasked to adapt it.

Friday, March 11, 2011
A “pluggable” app is
                            Easily Installed
                                     pip install coolapp
                          You did declare your dependencies, right?

Friday, March 11, 2011
How do we make a
                 “pluggable” application?


Friday, March 11, 2011
Stop thinking like this




                     http://upload.wikimedia.org/wikipedia/commons/archive/a/aa/20090315161532!Ferrari_Enzo_Ferrari.JPG
Friday, March 11, 2011
and think like this




Friday, March 11, 2011
Applications can have
                     very different purposes




                                  http://www.flickr.com/photos/tiemposdelruido/4051083769/
Friday, March 11, 2011
Application Types
                     • Data. Manages specific data and access to it
                     • Utility. Provide aapplication a specific
                       problem for any
                                          way of handling



                     • Decorator.functionality of many applications
                       aggregates
                                  Adds functionality to one or



Friday, March 11, 2011
Situation 1

                   You want to configure your app
                     without modifying its code
                           (e.g. API keys)



Friday, March 11, 2011
Configurable Options
                         Django Supertagging http://github.com/josesoa




                  Internal Name           Setting Name    Default Value




Friday, March 11, 2011
Configurable Options
               Django Debug Toolbar http://github.com/robhudson




Friday, March 11, 2011
Data Apps




                         http://www.flickr.com/photos/29276244@N03/3200630853/
Friday, March 11, 2011
Situation 2

                       Lots of variations
                Each implementation is different
                          (e.g. blogs)



Friday, March 11, 2011
Abstract Models
                                  GLAMKit http://www.glamkit.org/


                              EntryBase


                         FeaturableEntryMixin


                         StatusableEntryMixin


                         TaggableEntryMixin


                    HTMLFormattableEntryMixin




Friday, March 11, 2011
Situation 3

                  A few, well-known of variations
                   (e.g. Use django.contrib.sites?)




Friday, March 11, 2011
Optional Field Settings




Friday, March 11, 2011
Situation 4

                          Optionally use another
                                 application
                         (e.g. Use django-tagging?)



Friday, March 11, 2011
Optional Integration




Friday, March 11, 2011
Situation 5

                             You want to reference
                                different models
                         (e.g. Customizable author field)



Friday, March 11, 2011
Runtime Configurable
                             Foreign Keys
                         Viewpoint http://github.com/washingtontimes




Friday, March 11, 2011
Runtime Configurable
                             Foreign Keys
                         Viewpoint http://github.com/washingtontimes




Friday, March 11, 2011
Utility Apps




                         http://www.flickr.com/photos/s8/3638531205/
Friday, March 11, 2011
Required for
                     template tags or
                  management commands
Friday, March 11, 2011
Decorator Apps




                          http://www.flickr.com/photos/yum9me/2109549869/
Friday, March 11, 2011
New Method   New Field




       Custom Manager           New Admin




Friday, March 11, 2011
Situation 6

                         You want to add a
                          field to a model




Friday, March 11, 2011
Lazy Field Insertion
             Django Categories http://github.com/washingtontimes




Friday, March 11, 2011
Lazy Field Insertion
             Django Categories http://github.com/washingtontimes




Friday, March 11, 2011
Lazy Field Insertion
             Django Categories http://github.com/washingtontimes




Friday, March 11, 2011
Situation 7

                              You want to add a
                         custom manager to a model




Friday, March 11, 2011
Lazy Manager Insertion
                         Django MPTT http://github.com/django-mptt




Friday, March 11, 2011
Adding a manager
                         Django MPTT http://github.com/django-mptt
                   from django.db.models import get_model
                   import django.conf import settings
                   from coolapp.managers import CustomManager

                   MODELS = getattr(settings, 'COOLAPP_MODELS', {})

                   for model_name, mgr_name in MODELS.items():
                       if not isinstance(model_name, basestring):
                           continue

                          model = get_model(*model_name.split('.'))

                          if not getattr(model, mgr_name, False):
                              manager = CustomManager()
                              manager.contribute_to_class(model, mgr_name)



Friday, March 11, 2011
Situation 8

                        You want to customize
                       a model’s ModelAdmin
                  (e.g. Change the widget of a field)



Friday, March 11, 2011
Lazy Registration of a
                         Custom ModelAdmin
                         Django TinyMCE http://github.com/justquick




                                    project’s settings.py
Friday, March 11, 2011
Lazy Registration of a
                         Custom ModelAdmin
                         Django TinyMCE http://github.com/justquick




                                Django-TinyMCE’s models.py
Friday, March 11, 2011
Lazy Registration of a
                         Custom ModelAdmin
                         Django TinyMCE http://github.com/justquick




                                 Django-TinyMCE’s admin.py
Friday, March 11, 2011
Lazy Registration of a
                         Custom ModelAdmin
                         Django TinyMCE http://github.com/justquick




                            bottom of Django-TinyMCE’s admin.py
Friday, March 11, 2011
Touch Points




Friday, March 11, 2011
Touch Points of an App

                         The parts of an application that
                         usually need tweaking
                          • URLs
                          • Templates
                          • View responses

Friday, March 11, 2011
Situation 9

              You want the URLs of your app to
                    live under any prefix
                  (e.g. /blogs/ vs. /weblogs/)



Friday, March 11, 2011
Name your URLs




Friday, March 11, 2011
Name your URLs



                  url Function     name




Friday, March 11, 2011
Reference your
                         URLs by name




Friday, March 11, 2011
Situation 10

                         You want your templates
                          to be easily overridable




Friday, March 11, 2011
“Namespace” Templates
                                               All templates in
                         coolapp                  a template
                                               “name space”
                               templates

                                     coolapp

                                           base.html


Friday, March 11, 2011
“Namespace” Templates
                         coolapp

                               templates

                                     coolapp

       Referenced as                       base.html
    “coolapp/base.html”

Friday, March 11, 2011
Extend one template
                         site_base.html   base.html




                         summary.html     index.html   detail.html
Friday, March 11, 2011
Extend one template
                         site_base.html   base.html




                                          base.html




                         summary.html     index.html   detail.html
Friday, March 11, 2011
Extend one template
                         site_base.html   base.html




                                          base.html




                         summary.html     index.html   detail.html
Friday, March 11, 2011
Extend one template




                             coolapp/base.html
Friday, March 11, 2011
Extend one template




                             coolapp/base.html
Friday, March 11, 2011
Import your blocks
       Allows you to override any of the templates

                                       extra_head.html




                 coolapp/detail.html
Friday, March 11, 2011
Situation 11

                         You want flexibility storing
                              uploaded files




Friday, March 11, 2011
Define a Storage Option




Friday, March 11, 2011
Situation 12
                            You want to alter the
                            data your views use
                         (e.g. Extra context, different
                                   template)



Friday, March 11, 2011
100% more class-
                           based views!

                          django-cbv for
                            backwards
                          compatibility!
Friday, March 11, 2011
My Info

                     • coreyoordt@gmail.com
                     • @coordt
                     • github.com/coordt
                     • github.com/washingtontimes
                     • opensource.washingtontimes.com

Friday, March 11, 2011

Weitere ähnliche Inhalte

Was ist angesagt?

Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMartin Etmajer
 
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCDKubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCDSunnyvale
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices ArchitectureIdan Fridman
 
프론트엔드 코딩 컨벤션 자동화 도구
프론트엔드 코딩 컨벤션 자동화 도구프론트엔드 코딩 컨벤션 자동화 도구
프론트엔드 코딩 컨벤션 자동화 도구Taegon Kim
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programmingPeter Hilton
 
Percona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replicationPercona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replicationmysqlops
 
Gitops: the kubernetes way
Gitops: the kubernetes wayGitops: the kubernetes way
Gitops: the kubernetes waysparkfabrik
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrJohn Allspaw
 
cLoki: Like Loki but for ClickHouse
cLoki: Like Loki but for ClickHousecLoki: Like Loki but for ClickHouse
cLoki: Like Loki but for ClickHouseAltinity Ltd
 
GIT presentation
GIT presentationGIT presentation
GIT presentationNaim Latifi
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring Terry Cho
 
Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE)Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE)Edith Puclla
 
gRPC - 打造輕量、高效能的後端服務
gRPC - 打造輕量、高效能的後端服務gRPC - 打造輕量、高效能的後端服務
gRPC - 打造輕量、高效能的後端服務升煌 黃
 
자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법Sungchul Park
 

Was ist angesagt? (20)

Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
 
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCDKubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
프론트엔드 코딩 컨벤션 자동화 도구
프론트엔드 코딩 컨벤션 자동화 도구프론트엔드 코딩 컨벤션 자동화 도구
프론트엔드 코딩 컨벤션 자동화 도구
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programming
 
Percona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replicationPercona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replication
 
Gitops: the kubernetes way
Gitops: the kubernetes wayGitops: the kubernetes way
Gitops: the kubernetes way
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
 
Terraform
TerraformTerraform
Terraform
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
cLoki: Like Loki but for ClickHouse
cLoki: Like Loki but for ClickHousecLoki: Like Loki but for ClickHouse
cLoki: Like Loki but for ClickHouse
 
GIT presentation
GIT presentationGIT presentation
GIT presentation
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
 
Building with Gradle
Building with GradleBuilding with Gradle
Building with Gradle
 
Git
GitGit
Git
 
Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE)Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE)
 
gRPC - 打造輕量、高效能的後端服務
gRPC - 打造輕量、高效能的後端服務gRPC - 打造輕量、高效能的後端服務
gRPC - 打造輕量、高效能的後端服務
 
자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법자바에서 null을 안전하게 다루는 방법
자바에서 null을 안전하게 다루는 방법
 
Testing in airflow
Testing in airflowTesting in airflow
Testing in airflow
 

Ähnlich wie Pluggable Django Application Patterns PyCon 2011

Using Drupal for School or District Website
Using Drupal for School or District WebsiteUsing Drupal for School or District Website
Using Drupal for School or District Websitedserrato
 
A Look at the Future of HTML5
A Look at the Future of HTML5A Look at the Future of HTML5
A Look at the Future of HTML5Tim Wright
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time Pascal Rettig
 
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)gkamp
 
Meet magento 2011-templating
Meet magento 2011-templatingMeet magento 2011-templating
Meet magento 2011-templatingHans Kuijpers
 
Flowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock
 
Chris Rault - Content construction with ZOO
Chris Rault - Content construction with ZOOChris Rault - Content construction with ZOO
Chris Rault - Content construction with ZOOJoomla Day South Africa
 
iPhone App from concept to product
iPhone App from concept to productiPhone App from concept to product
iPhone App from concept to productjoeysim
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsMuhammad Ikram Ul Haq
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the LazyMaurício Linhares
 
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Goikailan
 
Simon Cross - Facebook Mobile, First - Geomob Feb 2011
Simon Cross -  Facebook Mobile, First - Geomob Feb 2011Simon Cross -  Facebook Mobile, First - Geomob Feb 2011
Simon Cross - Facebook Mobile, First - Geomob Feb 2011GeomobLDN
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slidescarllerche
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Guillaume Laforge
 
Mobile apps using drupal as base system SumitK DrupalCon Chicago
Mobile apps using drupal as base system   SumitK DrupalCon ChicagoMobile apps using drupal as base system   SumitK DrupalCon Chicago
Mobile apps using drupal as base system SumitK DrupalCon ChicagoSumit Kataria
 
Writing jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryWriting jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryRoss Bruniges
 
MarkLogic Developer Community Resources, September 2013
MarkLogic Developer Community Resources, September 2013MarkLogic Developer Community Resources, September 2013
MarkLogic Developer Community Resources, September 2013Eric Bloch
 

Ähnlich wie Pluggable Django Application Patterns PyCon 2011 (20)

Using Drupal for School or District Website
Using Drupal for School or District WebsiteUsing Drupal for School or District Website
Using Drupal for School or District Website
 
A Look at the Future of HTML5
A Look at the Future of HTML5A Look at the Future of HTML5
A Look at the Future of HTML5
 
Groke
GrokeGroke
Groke
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time
 
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)
Regional News in Times of iPad, Twitter & Co. (Cassini Convention, Nov. 2010)
 
Meet magento 2011-templating
Meet magento 2011-templatingMeet magento 2011-templating
Meet magento 2011-templating
 
Flowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDB
 
Chris Rault - Content construction with ZOO
Chris Rault - Content construction with ZOOChris Rault - Content construction with ZOO
Chris Rault - Content construction with ZOO
 
iPhone App from concept to product
iPhone App from concept to productiPhone App from concept to product
iPhone App from concept to product
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applications
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the Lazy
 
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
 
Simon Cross - Facebook Mobile, First - Geomob Feb 2011
Simon Cross -  Facebook Mobile, First - Geomob Feb 2011Simon Cross -  Facebook Mobile, First - Geomob Feb 2011
Simon Cross - Facebook Mobile, First - Geomob Feb 2011
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slides
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
 
Mobile apps using drupal as base system SumitK DrupalCon Chicago
Mobile apps using drupal as base system   SumitK DrupalCon ChicagoMobile apps using drupal as base system   SumitK DrupalCon Chicago
Mobile apps using drupal as base system SumitK DrupalCon Chicago
 
Writing jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQueryWriting jQuery that doesn't suck - London jQuery
Writing jQuery that doesn't suck - London jQuery
 
Anarchist guide to titanium ui
Anarchist guide to titanium uiAnarchist guide to titanium ui
Anarchist guide to titanium ui
 
The Third WordPress
The Third WordPressThe Third WordPress
The Third WordPress
 
MarkLogic Developer Community Resources, September 2013
MarkLogic Developer Community Resources, September 2013MarkLogic Developer Community Resources, September 2013
MarkLogic Developer Community Resources, September 2013
 

Kürzlich hochgeladen

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Pluggable Django Application Patterns PyCon 2011

  • 1. Pluggable Patterns For Reusable Django Applications Friday, March 11, 2011
  • 2. An app MyBlog App should not be • Categories • Custom Tagging a monolithic • Custom Comments pile of code • Comment Moderation • Assumption of text markup type • Single blogs For example, most blog • Multiple Sites “apps” available provide too much functionality ACME MONOLITHS Friday, March 11, 2011
  • 3. An application should be “pluggable” Friday, March 11, 2011
  • 4. A “pluggable” app is Focused Write programs that do one thing and do it well. — Doug McIlroy (inventor of UNIX pipes) Friday, March 11, 2011
  • 5. A “pluggable” app is Self-Contained Batteries are included Dependencies are declared Friday, March 11, 2011
  • 6. A “pluggable” app is Easily Adaptable Corey’s Law: The less adaptable you make your code, the sooner you will be tasked to adapt it. Friday, March 11, 2011
  • 7. A “pluggable” app is Easily Installed pip install coolapp You did declare your dependencies, right? Friday, March 11, 2011
  • 8. How do we make a “pluggable” application? Friday, March 11, 2011
  • 9. Stop thinking like this http://upload.wikimedia.org/wikipedia/commons/archive/a/aa/20090315161532!Ferrari_Enzo_Ferrari.JPG Friday, March 11, 2011
  • 10. and think like this Friday, March 11, 2011
  • 11. Applications can have very different purposes http://www.flickr.com/photos/tiemposdelruido/4051083769/ Friday, March 11, 2011
  • 12. Application Types • Data. Manages specific data and access to it • Utility. Provide aapplication a specific problem for any way of handling • Decorator.functionality of many applications aggregates Adds functionality to one or Friday, March 11, 2011
  • 13. Situation 1 You want to configure your app without modifying its code (e.g. API keys) Friday, March 11, 2011
  • 14. Configurable Options Django Supertagging http://github.com/josesoa Internal Name Setting Name Default Value Friday, March 11, 2011
  • 15. Configurable Options Django Debug Toolbar http://github.com/robhudson Friday, March 11, 2011
  • 16. Data Apps http://www.flickr.com/photos/29276244@N03/3200630853/ Friday, March 11, 2011
  • 17. Situation 2 Lots of variations Each implementation is different (e.g. blogs) Friday, March 11, 2011
  • 18. Abstract Models GLAMKit http://www.glamkit.org/ EntryBase FeaturableEntryMixin StatusableEntryMixin TaggableEntryMixin HTMLFormattableEntryMixin Friday, March 11, 2011
  • 19. Situation 3 A few, well-known of variations (e.g. Use django.contrib.sites?) Friday, March 11, 2011
  • 21. Situation 4 Optionally use another application (e.g. Use django-tagging?) Friday, March 11, 2011
  • 23. Situation 5 You want to reference different models (e.g. Customizable author field) Friday, March 11, 2011
  • 24. Runtime Configurable Foreign Keys Viewpoint http://github.com/washingtontimes Friday, March 11, 2011
  • 25. Runtime Configurable Foreign Keys Viewpoint http://github.com/washingtontimes Friday, March 11, 2011
  • 26. Utility Apps http://www.flickr.com/photos/s8/3638531205/ Friday, March 11, 2011
  • 27. Required for template tags or management commands Friday, March 11, 2011
  • 28. Decorator Apps http://www.flickr.com/photos/yum9me/2109549869/ Friday, March 11, 2011
  • 29. New Method New Field Custom Manager New Admin Friday, March 11, 2011
  • 30. Situation 6 You want to add a field to a model Friday, March 11, 2011
  • 31. Lazy Field Insertion Django Categories http://github.com/washingtontimes Friday, March 11, 2011
  • 32. Lazy Field Insertion Django Categories http://github.com/washingtontimes Friday, March 11, 2011
  • 33. Lazy Field Insertion Django Categories http://github.com/washingtontimes Friday, March 11, 2011
  • 34. Situation 7 You want to add a custom manager to a model Friday, March 11, 2011
  • 35. Lazy Manager Insertion Django MPTT http://github.com/django-mptt Friday, March 11, 2011
  • 36. Adding a manager Django MPTT http://github.com/django-mptt from django.db.models import get_model import django.conf import settings from coolapp.managers import CustomManager MODELS = getattr(settings, 'COOLAPP_MODELS', {}) for model_name, mgr_name in MODELS.items(): if not isinstance(model_name, basestring): continue model = get_model(*model_name.split('.')) if not getattr(model, mgr_name, False): manager = CustomManager() manager.contribute_to_class(model, mgr_name) Friday, March 11, 2011
  • 37. Situation 8 You want to customize a model’s ModelAdmin (e.g. Change the widget of a field) Friday, March 11, 2011
  • 38. Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick project’s settings.py Friday, March 11, 2011
  • 39. Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick Django-TinyMCE’s models.py Friday, March 11, 2011
  • 40. Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick Django-TinyMCE’s admin.py Friday, March 11, 2011
  • 41. Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick bottom of Django-TinyMCE’s admin.py Friday, March 11, 2011
  • 43. Touch Points of an App The parts of an application that usually need tweaking • URLs • Templates • View responses Friday, March 11, 2011
  • 44. Situation 9 You want the URLs of your app to live under any prefix (e.g. /blogs/ vs. /weblogs/) Friday, March 11, 2011
  • 45. Name your URLs Friday, March 11, 2011
  • 46. Name your URLs url Function name Friday, March 11, 2011
  • 47. Reference your URLs by name Friday, March 11, 2011
  • 48. Situation 10 You want your templates to be easily overridable Friday, March 11, 2011
  • 49. “Namespace” Templates All templates in coolapp a template “name space” templates coolapp base.html Friday, March 11, 2011
  • 50. “Namespace” Templates coolapp templates coolapp Referenced as base.html “coolapp/base.html” Friday, March 11, 2011
  • 51. Extend one template site_base.html base.html summary.html index.html detail.html Friday, March 11, 2011
  • 52. Extend one template site_base.html base.html base.html summary.html index.html detail.html Friday, March 11, 2011
  • 53. Extend one template site_base.html base.html base.html summary.html index.html detail.html Friday, March 11, 2011
  • 54. Extend one template coolapp/base.html Friday, March 11, 2011
  • 55. Extend one template coolapp/base.html Friday, March 11, 2011
  • 56. Import your blocks Allows you to override any of the templates extra_head.html coolapp/detail.html Friday, March 11, 2011
  • 57. Situation 11 You want flexibility storing uploaded files Friday, March 11, 2011
  • 58. Define a Storage Option Friday, March 11, 2011
  • 59. Situation 12 You want to alter the data your views use (e.g. Extra context, different template) Friday, March 11, 2011
  • 60. 100% more class- based views! django-cbv for backwards compatibility! Friday, March 11, 2011
  • 61. My Info • coreyoordt@gmail.com • @coordt • github.com/coordt • github.com/washingtontimes • opensource.washingtontimes.com Friday, March 11, 2011