Djangocon 09 Presentation - Pluggable Applications

Nowell Strite
Nowell StritePrincipal Engineer at WiserTogether
Pluggable Applications
      DjangoCon 2009

       Nowell Strite
       Shawn Rider
Road Map




•  Background 
•  Current Approaches 
•  Our Use Case / Requirements 
•  A Proposed Solu=on 
•  Some Live Examples 
•  Q & A 
A little background



PBS manages several major internal sites:




                              and more…
A little background



And many of these use Django to some
               degree:
A little background
A little background
PBS needs Django



•  Serving a diverse array of sites 
•  Built on a diverse technical architecture 
•  Many repe==ve components desired by producers 
   and users 
•  Ease of implementa=on is crucial 
•  But highly specific implementa=on details and 
   goals are oIen more important to producers 
Reusable Apps Save the Day



The Reusable App design paKern helps us: 
  –  Easy to share func=onality with other projects 
  –  Quick to get features up and running 
  –  Possible to expand and enhance func=onality 
Reusable Apps Save the Day… Sort of…



The Reusable App design paKern has some 
  limita=ons 
•  Apps are expected to live at one URL  
   (e.g. hKp://example.com/comments/) 
•  Current conven=on of adding ‘extra_context’ 
   params are not sa=sfactory 
•  Conven=onal template replacement is not always 
   flexible enough  
Template Tags to the Rescue



Template Tags allow apps to expose func=onality 
     inside templates for other apps and site 
                   components 
Template Tags to the Rescue … Sort of…



But template tags are also limited: 
  –  Form pos=ng becomes complicated 
  –  Generic inser=on of data into page context can 
     be dangerous 
  –  Addi=onal logic, such as complex permissions 
     checks, are difficult to enforce or bypass via 
     generic template tags 
The Use Case: PBS TeacherLine Peer Connection


Peer Connection features:

1. Access to a robust database of curated resources
2. Community features to allow educators to share and
discuss these resources

Because discussion is so important in this setting, many
objects in Peer Connection support discussions.

Given that the purpose of the site is partially to learn to
use technology, a clean user experience is essential.
The Use Case: PBS TeacherLine Peer Connection


Our Requirements:

•  Sensible URLs that follow our patterns elsewhere on
the site
•  Allow discussions app to interact with other apps and
objects in expected ways
•  Allow posting of data and error handling in the same
location – no redirects to stand-alone pages to fix a
message post.
•  Flexibility to enforce permissions and other variations
of display in an ad-hoc way.
Our Solution: Make the Reusable App Pluggable



By making an app “pluggable” we gain some extra 
  features: 
  –  Apps can be presented at various URLs 
     throughout the site 
  –  Each presenta=on can define context in a clean, 
     DRY manner 
  –  Form pos=ng and error handling can happen in 
     the logical loca=on for the user 
The Use Case: PBS TeacherLine Peer Connection


       Two examples of how discussions appear in Peer
       Connection:




/community/network/pbs-staff/group/tl-technology/discuss/


                                                             /content/module/216/discuss/
The Use Case: PBS TeacherLine Peer Connection


       Two examples of how discussions appear in Peer
       Connection:




/community/network/pbs-staff/group/tl-technology/discuss/


                                                             /content/module/216/discuss/
The Use Case: PBS TeacherLine Peer Connection


       Two examples of how discussions appear in Peer
       Connection:




/community/network/pbs-staff/group/tl-technology/discuss/


                                                             /content/module/216/discuss/
The Use Case: PBS TeacherLine Peer Connection


                Content generated by the pluggable app:




                                                             /content/module/216/discuss/


/community/network/pbs-staff/group/tl-technology/discuss/
The Use Case: PBS TeacherLine Peer Connection


  Content required by the presenting app templates:




                                                             /content/module/216/discuss/


/community/network/pbs-staff/group/tl-technology/discuss/
Make it So




By making our discussions app pluggable, we solved our
problems and fulfilled our requirements.

       But what kind of work does it take to get there?
Make it So




Parts of Pluggable Apps
 •  Pluggable URL definition
 •  Pluggable application views definition
 •  Subclass / instantiation of Pluggable
    application
Pluggable URL Definition




from
pluggables
import
PluggableApp,
url,
include,
patterns

class
ComplaintsApp(PluggableApp):




urlpatterns
=
patterns('complaints.views.traditional',








url(r'^$',
'index',
name='complaints_index'),








url(r'^create/$',
'edit',
name='complaints_create'),








url(r'^(?P<complaint_id>d+)/edit/$',
'edit',

name='complaints_edit'),








url(r'^(?P<complaint_id>d+)/delete/$',
'delete',

name='complaints_delete'),




)
Pluggable Application Views Definition




def
index(request):




complaints
=
Complaint.objects.pluggable(request)




form
=
ComplaintForm()




template
=
request.pluggable.config.get('template’)




base_template
=
request.pluggable.config.get('base_template’)





return
render_to_response(template,
{








'complaints':
complaints,








'form':
form,








'base_template':
base_template,








},
context_instance=RequestContext(request))
Subclass / Instantiation of Pluggable Application


class
SillyWalkComplaintsApp(ComplaintsApp):




def
pluggable_config(self,
request,
walk_slug=None):








return
{'base_template':
'sillywalks/view.html'}





def
pluggable_view_context(self,
request,
walk_slug):








try:












sillywalk
=
SillyWalk.objects.get(slug=walk_slug)








except
SillyWalk.DoesNotExist:












raise
Http404








return
sillywalk





def
pluggable_template_context(self,
request,
walk_slug):








return
{'sillywalk':
request.pluggable.view_context}

complaints_app
=
SillyWalkComplaintsApp('sillywalks')
And Now For Something Completely Different




 Let’s see some live examples…
Thank You For Your Time



Code referenced in this presentation is available at:
          http://bit.ly/django-pluggables

                Nowell Strite
               Twitter: @nowells
             Email: nowell@strite.org

                  Shawn Rider
                 Twitter: @shawnr
          Email: shawn@shawnrider.com
1 of 26

Recommended

Principles of MVC for PHP Developers by
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP DevelopersEdureka!
3.1K views17 slides
Enable Domino Data Access Services (DAS) by
Enable Domino Data Access Services (DAS)Enable Domino Data Access Services (DAS)
Enable Domino Data Access Services (DAS)Slobodan Lohja
1.6K views9 slides
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F... by
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...Sencha
1.5K views54 slides
ASP.NET MVC From The Ground Up by
ASP.NET MVC From The Ground UpASP.NET MVC From The Ground Up
ASP.NET MVC From The Ground UpKevin Griffin
3.2K views19 slides
NodeJs-resume by
NodeJs-resumeNodeJs-resume
NodeJs-resumeDeepak Dara
5.6K views3 slides
React Component Library Design @WalmartLabs by
React Component Library Design @WalmartLabsReact Component Library Design @WalmartLabs
React Component Library Design @WalmartLabschaseadamsio
1.6K views21 slides

More Related Content

What's hot

jQuery From the Ground Up by
jQuery From the Ground UpjQuery From the Ground Up
jQuery From the Ground UpKevin Griffin
1.3K views30 slides
Take your drupal sites offline by
Take your drupal sites offlineTake your drupal sites offline
Take your drupal sites offlineChris Ward
4.2K views15 slides
Flux architecture by
Flux architectureFlux architecture
Flux architectureBoyan Mihaylov
2.6K views19 slides
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012 by
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012Atlassian
3.9K views20 slides
Reactjs by
Reactjs Reactjs
Reactjs Neha Sharma
10.5K views27 slides
React introduction by
React introductionReact introduction
React introductionKashyap Parmar
164 views28 slides

What's hot(20)

jQuery From the Ground Up by Kevin Griffin
jQuery From the Ground UpjQuery From the Ground Up
jQuery From the Ground Up
Kevin Griffin1.3K views
Take your drupal sites offline by Chris Ward
Take your drupal sites offlineTake your drupal sites offline
Take your drupal sites offline
Chris Ward4.2K views
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012 by Atlassian
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012
User Macros: Making Your Own Improvements to Confluence - Atlassian Summit 2012
Atlassian3.9K views
Reactjs by Neha Sharma
Reactjs Reactjs
Reactjs
Neha Sharma10.5K views
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC by Mohamed Meligy
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVCApplying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Applying Domain Driven Design on Asp.net MVC – Part 1: Asp.net MVC
Mohamed Meligy3.1K views
Single Page WebApp Architecture by Morgan Cheng
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng12.9K views
ASP .NET MVC by eldorina
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina1K views
The Complementarity of React and Web Components by Andrew Rota
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
Andrew Rota32.3K views
Build single page applications using AngularJS on AEM by connectwebex
Build single page applications using AngularJS on AEMBuild single page applications using AngularJS on AEM
Build single page applications using AngularJS on AEM
connectwebex7.8K views
Let's Take Drupal Offline! by Dick Olsson
Let's Take Drupal Offline!Let's Take Drupal Offline!
Let's Take Drupal Offline!
Dick Olsson6.7K views
ASP.NET MVC Presentation by ivpol
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol23.6K views
Rails review by Alan Hecht
Rails reviewRails review
Rails review
Alan Hecht925 views
React & Redux, how to scale? by KMS Technology
React & Redux, how to scale?React & Redux, how to scale?
React & Redux, how to scale?
KMS Technology749 views
Architecting ASP.NET MVC Applications by Gunnar Peipman
Architecting ASP.NET MVC ApplicationsArchitecting ASP.NET MVC Applications
Architecting ASP.NET MVC Applications
Gunnar Peipman5.7K views
Cordova: Making Native Mobile Apps With Your Web Skills by Clay Ewing
Cordova: Making Native Mobile Apps With Your Web SkillsCordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web Skills
Clay Ewing3K views
Building single page applications by SC5.io
Building single page applicationsBuilding single page applications
Building single page applications
SC5.io7K views

Viewers also liked

CodeIgniter - PHP MVC Framework by silicongulf.com by
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comChristopher Cubos
4.7K views41 slides
PHP & MVC by
PHP & MVCPHP & MVC
PHP & MVCChris Weldon
14.3K views19 slides
The Agile Process - Taming Your Process To Work For You by
The Agile Process - Taming Your Process To Work For YouThe Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For YouNowell Strite
1.5K views21 slides
Introduction To CodeIgniter by
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniterschwebbie
12K views19 slides
ACL in CodeIgniter by
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgnitermirahman
13.5K views16 slides
Embracing Distributed Version Control by
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version ControlNowell Strite
1.3K views28 slides

Viewers also liked(8)

CodeIgniter - PHP MVC Framework by silicongulf.com by Christopher Cubos
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
Christopher Cubos4.7K views
The Agile Process - Taming Your Process To Work For You by Nowell Strite
The Agile Process - Taming Your Process To Work For YouThe Agile Process - Taming Your Process To Work For You
The Agile Process - Taming Your Process To Work For You
Nowell Strite1.5K views
Introduction To CodeIgniter by schwebbie
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
schwebbie12K views
ACL in CodeIgniter by mirahman
ACL in CodeIgniterACL in CodeIgniter
ACL in CodeIgniter
mirahman13.5K views
Embracing Distributed Version Control by Nowell Strite
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version Control
Nowell Strite1.3K views
RESTful API Design & Implementation with CodeIgniter PHP Framework by Bo-Yi Wu
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu59.7K views
Introduction to Python by Nowell Strite
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite167.9K views

Similar to Djangocon 09 Presentation - Pluggable Applications

Progressive Web Apps - deep dive by
Progressive Web Apps - deep diveProgressive Web Apps - deep dive
Progressive Web Apps - deep diveKenneth Rohde Christiansen
204 views152 slides
H2O World - Building a Smarter Application - Tom Kraljevic by
H2O World - Building a Smarter Application - Tom KraljevicH2O World - Building a Smarter Application - Tom Kraljevic
H2O World - Building a Smarter Application - Tom KraljevicSri Ambati
1.9K views21 slides
DSL (Domain Specific Language) for Maps Mashups by
DSL (Domain Specific Language) for Maps MashupsDSL (Domain Specific Language) for Maps Mashups
DSL (Domain Specific Language) for Maps Mashupsaliraza786
1.3K views60 slides
PWA for PHP Developers by
PWA for PHP DevelopersPWA for PHP Developers
PWA for PHP DevelopersBen Marks
3.1K views28 slides
Progressive Web Apps by
Progressive Web AppsProgressive Web Apps
Progressive Web AppsSaikiran Sheshagiri
220 views35 slides
venki 2.7 by
venki 2.7venki 2.7
venki 2.7venkateswarlu konakanchi
157 views3 slides

Similar to Djangocon 09 Presentation - Pluggable Applications(20)

H2O World - Building a Smarter Application - Tom Kraljevic by Sri Ambati
H2O World - Building a Smarter Application - Tom KraljevicH2O World - Building a Smarter Application - Tom Kraljevic
H2O World - Building a Smarter Application - Tom Kraljevic
Sri Ambati1.9K views
DSL (Domain Specific Language) for Maps Mashups by aliraza786
DSL (Domain Specific Language) for Maps MashupsDSL (Domain Specific Language) for Maps Mashups
DSL (Domain Specific Language) for Maps Mashups
aliraza7861.3K views
PWA for PHP Developers by Ben Marks
PWA for PHP DevelopersPWA for PHP Developers
PWA for PHP Developers
Ben Marks3.1K views
Intro To Django by Udi Bauman
Intro To DjangoIntro To Django
Intro To Django
Udi Bauman2.6K views
resume_2016_low_rez by James Gray
resume_2016_low_rezresume_2016_low_rez
resume_2016_low_rez
James Gray115 views
Progressive Web Apps - Overview & Getting Started by Gaurav Behere
Progressive Web Apps - Overview & Getting StartedProgressive Web Apps - Overview & Getting Started
Progressive Web Apps - Overview & Getting Started
Gaurav Behere287 views
Ramesh Babu Resume Latest by Ramesh Babu
Ramesh Babu Resume LatestRamesh Babu Resume Latest
Ramesh Babu Resume Latest
Ramesh Babu307 views
M.M.H.Masud by Md. Masud
M.M.H.MasudM.M.H.Masud
M.M.H.Masud
Md. Masud619 views
Google Cloud Developer Challenge - GDG Belgaum by sandeephegde
Google Cloud Developer Challenge - GDG BelgaumGoogle Cloud Developer Challenge - GDG Belgaum
Google Cloud Developer Challenge - GDG Belgaum
sandeephegde2.3K views
Resume Partha Roy by Partha Roy
Resume Partha RoyResume Partha Roy
Resume Partha Roy
Partha Roy178 views
The Hitchhiker's Guide to Building a Progressive Web App by Christopher Nguyen
The Hitchhiker's Guide to Building a Progressive Web AppThe Hitchhiker's Guide to Building a Progressive Web App
The Hitchhiker's Guide to Building a Progressive Web App
Christopher Nguyen381 views
Applied progressive decoupling weather.com, angular, and drupal by Acquia
Applied progressive decoupling  weather.com, angular, and drupalApplied progressive decoupling  weather.com, angular, and drupal
Applied progressive decoupling weather.com, angular, and drupal
Acquia2K views
Applications of the REST Principle by elliando dias
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
elliando dias438 views

Recently uploaded

Black and White Modern Science Presentation.pptx by
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptxmaryamkhalid2916
14 views21 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
209 views20 slides
Future of Learning - Khoong Chan Meng by
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan MengNUS-ISS
33 views7 slides
Attacking IoT Devices from a Web Perspective - Linux Day by
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
15 views68 slides
Combining Orchestration and Choreography for a Clean Architecture by
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean ArchitectureThomasHeinrichs1
69 views24 slides
Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
130 views15 slides

Recently uploaded(20)

Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views

Djangocon 09 Presentation - Pluggable Applications

  • 1. Pluggable Applications DjangoCon 2009 Nowell Strite Shawn Rider
  • 2. Road Map •  Background  •  Current Approaches  •  Our Use Case / Requirements  •  A Proposed Solu=on  •  Some Live Examples  •  Q & A 
  • 3. A little background PBS manages several major internal sites: and more…
  • 4. A little background And many of these use Django to some degree:
  • 7. PBS needs Django •  Serving a diverse array of sites  •  Built on a diverse technical architecture  •  Many repe==ve components desired by producers  and users  •  Ease of implementa=on is crucial  •  But highly specific implementa=on details and  goals are oIen more important to producers 
  • 8. Reusable Apps Save the Day The Reusable App design paKern helps us:  –  Easy to share func=onality with other projects  –  Quick to get features up and running  –  Possible to expand and enhance func=onality 
  • 9. Reusable Apps Save the Day… Sort of… The Reusable App design paKern has some  limita=ons  •  Apps are expected to live at one URL   (e.g. hKp://example.com/comments/)  •  Current conven=on of adding ‘extra_context’  params are not sa=sfactory  •  Conven=onal template replacement is not always  flexible enough  
  • 10. Template Tags to the Rescue Template Tags allow apps to expose func=onality  inside templates for other apps and site  components 
  • 11. Template Tags to the Rescue … Sort of… But template tags are also limited:  –  Form pos=ng becomes complicated  –  Generic inser=on of data into page context can  be dangerous  –  Addi=onal logic, such as complex permissions  checks, are difficult to enforce or bypass via  generic template tags 
  • 12. The Use Case: PBS TeacherLine Peer Connection Peer Connection features: 1. Access to a robust database of curated resources 2. Community features to allow educators to share and discuss these resources Because discussion is so important in this setting, many objects in Peer Connection support discussions. Given that the purpose of the site is partially to learn to use technology, a clean user experience is essential.
  • 13. The Use Case: PBS TeacherLine Peer Connection Our Requirements: •  Sensible URLs that follow our patterns elsewhere on the site •  Allow discussions app to interact with other apps and objects in expected ways •  Allow posting of data and error handling in the same location – no redirects to stand-alone pages to fix a message post. •  Flexibility to enforce permissions and other variations of display in an ad-hoc way.
  • 14. Our Solution: Make the Reusable App Pluggable By making an app “pluggable” we gain some extra  features:  –  Apps can be presented at various URLs  throughout the site  –  Each presenta=on can define context in a clean,  DRY manner  –  Form pos=ng and error handling can happen in  the logical loca=on for the user 
  • 15. The Use Case: PBS TeacherLine Peer Connection Two examples of how discussions appear in Peer Connection: /community/network/pbs-staff/group/tl-technology/discuss/ /content/module/216/discuss/
  • 16. The Use Case: PBS TeacherLine Peer Connection Two examples of how discussions appear in Peer Connection: /community/network/pbs-staff/group/tl-technology/discuss/ /content/module/216/discuss/
  • 17. The Use Case: PBS TeacherLine Peer Connection Two examples of how discussions appear in Peer Connection: /community/network/pbs-staff/group/tl-technology/discuss/ /content/module/216/discuss/
  • 18. The Use Case: PBS TeacherLine Peer Connection Content generated by the pluggable app: /content/module/216/discuss/ /community/network/pbs-staff/group/tl-technology/discuss/
  • 19. The Use Case: PBS TeacherLine Peer Connection Content required by the presenting app templates: /content/module/216/discuss/ /community/network/pbs-staff/group/tl-technology/discuss/
  • 20. Make it So By making our discussions app pluggable, we solved our problems and fulfilled our requirements. But what kind of work does it take to get there?
  • 21. Make it So Parts of Pluggable Apps •  Pluggable URL definition •  Pluggable application views definition •  Subclass / instantiation of Pluggable application
  • 23. Pluggable Application Views Definition def
index(request): 



complaints
=
Complaint.objects.pluggable(request) 



form
=
ComplaintForm() 



template
=
request.pluggable.config.get('template’) 



base_template
=
request.pluggable.config.get('base_template’) 



return
render_to_response(template,
{ 







'complaints':
complaints, 







'form':
form, 







'base_template':
base_template, 







},
context_instance=RequestContext(request))
  • 24. Subclass / Instantiation of Pluggable Application class
SillyWalkComplaintsApp(ComplaintsApp): 



def
pluggable_config(self,
request,
walk_slug=None): 







return
{'base_template':
'sillywalks/view.html'} 



def
pluggable_view_context(self,
request,
walk_slug): 







try: 











sillywalk
=
SillyWalk.objects.get(slug=walk_slug) 







except
SillyWalk.DoesNotExist: 











raise
Http404 







return
sillywalk 



def
pluggable_template_context(self,
request,
walk_slug): 







return
{'sillywalk':
request.pluggable.view_context} complaints_app
=
SillyWalkComplaintsApp('sillywalks')
  • 25. And Now For Something Completely Different Let’s see some live examples…
  • 26. Thank You For Your Time Code referenced in this presentation is available at: http://bit.ly/django-pluggables Nowell Strite Twitter: @nowells Email: nowell@strite.org Shawn Rider Twitter: @shawnr Email: shawn@shawnrider.com

Editor's Notes

  1. Welcome and introductions Today we want to present to you a design pattern that has been useful to us at PBS. This pattern allows applications to be presented by other objects or applications and at multiple contextualized URLs.
  2. PBS manages a lot of websites Some of these are created internally by PBS project teams Of the sites created internally many contain some significant Django component (switch to next slide as you’re saying this)
  3. This is not to say that all of these sites are solely powered by Django, but all of these sites rely on Django-based components. And some of them are completely powered by Django.
  4. PBS also hosts sites for independent producers, such as ken burns or weta or itvs Of these sites, some also use Django. (proceed as saying this)
  5. Again, not all of these sites use Django exclusively, but they use Django to varying degrees, mostly to supply specialty content and functionality.
  6. Since 2006, PBS has been using Django Django helps us solve problems in a variety of ways For all the reasons listed here, Django is a useful framework for us PBS was initially built largely on Perl scripts outputting static HTML But there was also some mix-in of Java and earlier Python frameworks such as Zope/Plone As we move forward, we must be able to support existing functionality while we build new functionality Django is flexible enough to allow us to do this Django has also allowed us to begin building components that can be leveraged by stations and producers building their own Django sites
  7. (N) Historically, reusable apps have been very helpful for spreading around similar functionality across different websites and projects.
  8. Reusable apps have a few limitations: They are designed to live at a single URL location To supply extra context info one must overload the URLconf, which gets messy quickly To have a reusable app appear to be styled like a different part of the site can require many different templates.
  9. Template Tags are often used to combine functionality from different apps into single pages.
  10. Template Tags are also very useful, but have some drawbacks: Form posts and handling errors in form posts are especially problematic. The user experience of submitting a post and being taken to a standalone error resolution or preview page is unacceptable. Context data can be added and manipulated with Template tags, but only if the tag has been written that way (many reusable apps template tags do not have the ability to accept arbitrary context data – and why should they?) Additional logic can be difficult to enforce or bypass
  11. (S) It’s helpful to look at a real-world example. In this case, we will examine a use case we were confronted with during the development of our social networking tool for educators’ professional development, PBS TeacherLine Peer Connection. Peer Connection is a social site that helps educators fulfill professional development requirements. It provides two major features: Access to curated content and community features. The site is designed to support real-world instructional coaching and mentoring programs in place at many schools, and it is intended to both help teachers become more comfortable with modern networked technologies as well as helping them develop their teaching practice.
  12. So as we set out to add a discussions feature to almost every object in the site (Networks, Groups, Learning Modules, Resources), we needed to adhere to a set of requirements. These were essential requirements, not all of which can be fulfilled with the traditional approaches.
  13. By making an app “pluggable” we gain extra features:
  14. These are two examples of how discussions appear in Peer Connection. One discussion area is attached to a Group, which is a subset of a Network. The other discussion area is attached to a Professional Development Module, which is a piece of curated content from the PBS team. It is essential that these discussions display under the URL hierarchy set up for displaying Networks, Groups, instructional Modules, etc.
  15. As you can see, the presentation of the pluggable discussion app’s functionality on these pages is surrounded by differentiated navigation that fits with the presenting application. So in this example, you can see that Discussions are a first-class link under the left sidebar navigation of your Group listing.
  16. However, when presented as a part of an instructional Module, the discussion area is accessed through a sub-navigation that is not part of the first-class navigation structure for the instructional Module.
  17. This content is generated by the pluggable app. The pluggable app knows nothing about the presenting application And the presenting app knows nothing about the pluggable application or its required context.
  18. (N)
  19. This is the URL conf Similar to traditional, but embedded in an class that inherits form PluggableApp This definition is only required once – any other app or object in my site project could present this application using this URL configuration
  20. By default any common Django design approach will work fwith the Pluggables pattern. However, pluggable applications also support class-based views, which might provide even more flexibility to your project.
  21. For each app that presents a pluggable application, there are three points at which you may customize behavior. If customization is required, you must create one of these classes for every application that will present a pluggable application. In this example we are looking at the configuration for presenting the Complaints app within the Silly Walks application. The pluggable_config defines a dictionary of configuration parameters that can be customized. The pluggable_view_context supplies any expected objects that the pluggable application needs to work. In this case, the pluggable application requires an object to attach complaints to, and we are giving it a SillyWalk to use for that object, anchoring your complaint to this object. This is a common use case, but certainly not required by every pluggable application. Finally, the pluggable_template_context determines which data should be passed through to the template itself. This may be required for rendering various aspects of the template that are dependent on the presenting application.
  22. Follow PEP8 with our examples