SlideShare a Scribd company logo
Pluggable Patterns
  For Reusable Django Applications
Project
Project




Configuration   URL routing   Templates
Project
 Application    Application   Application




 Application    Application   Application




 Application    Application   Application



Configuration   URL routing   Templates
Here there be power!
                  Project
 Application      Application   Application




 Application      Application   Application




 Application      Application   Application



Configuration     URL routing   Templates
We need a better definition
 for “Django Application”
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
An application should
   be “pluggable”
A “pluggable” app is
      Focused
Write programs that do one thing and do it well.
   — Doug McIlroy (inventor of UNIX pipes)
A “pluggable” app is
   Self-Contained
      Batteries are included
    Dependencies are declared
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.
A “pluggable” app is
   Easily Installed
            pip install coolapp
 You did declare your dependencies, right?
How do we make a
“pluggable” application?
Stop thinking like this




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




   http://www.flickr.com/photos/motagirl2/4301276868/
Applications can have
very different purposes




http://www.photoshoproadmap.com/imagenes/blog/lego-brushes/lego-bricks-high-resolution.jpg
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
Data Apps




http://www.geeky-gadgets.com/wp-content/uploads/2009/08/lego-usb-hub_2.jpg
Situation 1

       Lots of variations
Each implementation is different
          (e.g. blogs)
Abstract Models
            GLAMKit http://www.glamkit.org/


        EntryBase


   FeaturableEntryMixin


   StatusableEntryMixin


    TaggableEntryMixin


HTMLFormattableEntryMixin
Situation 2

A few, well-known of variations
 (e.g. Use django.contrib.sites?)
Optional Field Settings
Situation 3

 Optionally use another
        application
(e.g. Use django-tagging?)
Optional Integration
Optional Integration
Situation 3

    You want to reference
       different models
(e.g. Customizable author field)
Configurable
        Foreign Keys
Viewpoint http://github.com/washingtontimes
Situation 3

You want to provide hooks for
       other applications
(e.g. While processing in a view)
Emit Signals
Satchmo http://www.satchmoproject.com/
Utility Apps




http://www.1000steine.com/brickset/images/852759-1.jpg
Utility apps are
just code libraries
Projects with
template tags need one
Does it need to be in
                      ?

Yes, if you have:
• Templates
• Template Tags
• Management Commands
Decorator Apps




http://trendland.net/wp-content/uploads/2008/12/lego-ring.jpg
CoolApp
 New Method                New Field
Custom Manager             New Admin
Registering for Decoration
Simple Model Registry
Model-Data Registry
Lazy Registration
Situation 4

     You want to add a
      field to a model
(e.g. Link to another model)
Simple Model Registry
Situation 5

     You want to add a
    method to a model
(e.g. Link to another model)
Adding methods
Situation 6

      You want to customize
     a model’s ModelAdmin
(e.g. Change the widget of a field)
Lazy Registration of a
Custom ModelAdmin
Lazy Registration of a
Custom ModelAdmin
Lazy Registration of a
Custom ModelAdmin
Touch Points
Touch Points of an App
The parts of an application that
usually need tweaking
 • URLs
 • Templates
 • Configurable options
 • View responses
Situation 7

You want the URLs of your app to
      live under any prefix
    (e.g. /blogs/ vs. /weblogs/)
Name your URLs
Reference your
URLs by name
Situation 8

You want your templates
 to be easily overridable
“Namespace” Templates
  coolapp

        templates

              coolapp

                    base.html
“Namespace” Templates
                        All templates in
  coolapp                  a template
                        “name space”
        templates

              coolapp

                    base.html
“Namespace” Templates
  coolapp
                          All templates
        templates        extend a single
                            template
              coolapp

                    base.html
“Namespace” Templates
  coolapp

        templates       This template simply

              coolapp

                    base.html
Import your blocks
Allows you to override any of the templates

                              extra_head.html



                              content.html
      base.html
Situation 9

You want to configure your app
  without modifying its code
        (e.g. API keys)
Configurable Options
 Django Supertagging http://github.com/josesoa




Internal Name     Setting Name    Default Value
Configurable Options
Django Debug Toolbar http://github.com/robhudson
Define a Storage Option
Situation 10
   You want to alter the
   data your views use
(e.g. Extra context, different
          template)
Add keyword arguments
Django Registration http://bitbucket.org/ubernostrum
Class-based Views
http://github.com/bfirsh/django-class-based-views
http://github.com/pegasus/django-baseviews
http://code.djangoproject.com/ticket/6735
http://codysoyland.com/2010/feb/3/thread-safe-object-
oriented-views-django/
http://www.toddreed.name/content/django-view-class/
To be continued…
My Info

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

More Related Content

What's hot (20)

PDF
AEM Sightly Deep Dive
Gabriel Walt
 
PDF
10 reasons to migrate from AEM 5 to 6.1
Tricode (part of Dept)
 
PPTX
BDD, Behat & Drupal
Bozhidar Boshnakov
 
PPTX
5 x HTML5 worth using in APEX (5)
Christian Rokitta
 
PDF
[2015/2016] JavaScript
Ivano Malavolta
 
PPTX
The Open-source Eclipse Plugin for Force.com Development, Summer ‘14
Salesforce Developers
 
PPTX
Build single page applications using AngularJS on AEM
AdobeMarketingCloud
 
PPT
Introduction To Code Igniter
Amzad Hossain
 
PPTX
Publishing API documentation -- Presentation
Tom Johnson
 
PPTX
Publishing API documentation -- Workshop
Tom Johnson
 
PDF
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins
 
PDF
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
PDF
Instagram filters (8 24)
Ivy Rueb
 
PPT
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
Johnny Oldenburger
 
PDF
Instagram filters (8 24)
Ivy Rueb
 
PPT
Getting started with angular js
Maurice De Beijer [MVP]
 
PDF
ElggCamp Santiago - Dev Edition
Brett Profitt
 
PPTX
Eclipse Overview
Lars Vogel
 
PDF
Add-On Development: EE Expects that Every Developer will do his Duty
reedmaniac
 
PDF
[2015/2016] Require JS and Handlebars JS
Ivano Malavolta
 
AEM Sightly Deep Dive
Gabriel Walt
 
10 reasons to migrate from AEM 5 to 6.1
Tricode (part of Dept)
 
BDD, Behat & Drupal
Bozhidar Boshnakov
 
5 x HTML5 worth using in APEX (5)
Christian Rokitta
 
[2015/2016] JavaScript
Ivano Malavolta
 
The Open-source Eclipse Plugin for Force.com Development, Summer ‘14
Salesforce Developers
 
Build single page applications using AngularJS on AEM
AdobeMarketingCloud
 
Introduction To Code Igniter
Amzad Hossain
 
Publishing API documentation -- Presentation
Tom Johnson
 
Publishing API documentation -- Workshop
Tom Johnson
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins
 
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
Instagram filters (8 24)
Ivy Rueb
 
Engage - Expanding XPages with Bootstrap Plugins for ultimate usability
Johnny Oldenburger
 
Instagram filters (8 24)
Ivy Rueb
 
Getting started with angular js
Maurice De Beijer [MVP]
 
ElggCamp Santiago - Dev Edition
Brett Profitt
 
Eclipse Overview
Lars Vogel
 
Add-On Development: EE Expects that Every Developer will do his Duty
reedmaniac
 
[2015/2016] Require JS and Handlebars JS
Ivano Malavolta
 

Similar to Pluggable patterns (20)

PDF
Reusable Apps
DjangoCon2008
 
PPTX
Concepts and applications of Django.pptx
sushmitjivtode4
 
PDF
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
PDF
Django in the Real World
Jacob Kaplan-Moss
 
PDF
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PDF
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Jer Clarke
 
PDF
Handlebars and Require.js
Ivano Malavolta
 
ODP
Web Development in Django
Lakshman Prasad
 
PDF
Apache Cordova
Ivano Malavolta
 
PPTX
Googleappengineintro 110410190620-phpapp01
Tony Frame
 
PPTX
Seattle bestpractices2010
Olaseni Odebiyi
 
PDF
بررسی چارچوب جنگو
railsbootcamp
 
PPTX
Introduction to Google App Engine with Python
Brian Lyttle
 
PPTX
Top 8 Improvements in Drupal 8
Angela Byron
 
PDF
Architecting iOS Project
Massimo Oliviero
 
PDF
Implementing a Symfony Based CMS in a Publishing Company
Marcos Labad
 
PDF
Dev days Szeged 2014: Plugin system in drupal 8
Bram Goffings
 
PDF
Mongodb at-gilt-groupe-seattle-2012-09-14-final
MongoDB
 
PDF
Handlebars & Require JS
Ivano Malavolta
 
Reusable Apps
DjangoCon2008
 
Concepts and applications of Django.pptx
sushmitjivtode4
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Django in the Real World
Jacob Kaplan-Moss
 
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Jer Clarke
 
Handlebars and Require.js
Ivano Malavolta
 
Web Development in Django
Lakshman Prasad
 
Apache Cordova
Ivano Malavolta
 
Googleappengineintro 110410190620-phpapp01
Tony Frame
 
Seattle bestpractices2010
Olaseni Odebiyi
 
بررسی چارچوب جنگو
railsbootcamp
 
Introduction to Google App Engine with Python
Brian Lyttle
 
Top 8 Improvements in Drupal 8
Angela Byron
 
Architecting iOS Project
Massimo Oliviero
 
Implementing a Symfony Based CMS in a Publishing Company
Marcos Labad
 
Dev days Szeged 2014: Plugin system in drupal 8
Bram Goffings
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
MongoDB
 
Handlebars & Require JS
Ivano Malavolta
 
Ad

Pluggable patterns