Pluggable Django Application Patterns PyCon 2011
Upcoming SlideShare
Loading in...5
×
 

Pluggable Django Application Patterns PyCon 2011

on

  • 6,923 views

12 Ways to get your apps pluggable or reusable given at PyCon 2011

12 Ways to get your apps pluggable or reusable given at PyCon 2011

Statistics

Views

Total Views
6,923
Views on SlideShare
6,922
Embed Views
1

Actions

Likes
6
Downloads
101
Comments
0

1 Embed 1

http://a0.twimg.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Pluggable Django Application Patterns PyCon 2011 Pluggable Django Application Patterns PyCon 2011 Presentation Transcript

  • Pluggable Patterns For Reusable Django ApplicationsFriday, 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 MONOLITHSFriday, 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 declaredFriday, 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.JPGFriday, March 11, 2011
  • and think like thisFriday, 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 orFriday, 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 ValueFriday, March 11, 2011
  • Configurable Options Django Debug Toolbar http://github.com/robhudsonFriday, 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 HTMLFormattableEntryMixinFriday, March 11, 2011
  • Situation 3 A few, well-known of variations (e.g. Use django.contrib.sites?)Friday, March 11, 2011
  • Optional Field SettingsFriday, March 11, 2011
  • Situation 4 Optionally use another application (e.g. Use django-tagging?)Friday, March 11, 2011
  • Optional IntegrationFriday, 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/washingtontimesFriday, March 11, 2011
  • Runtime Configurable Foreign Keys Viewpoint http://github.com/washingtontimesFriday, March 11, 2011
  • Utility Apps http://www.flickr.com/photos/s8/3638531205/Friday, March 11, 2011
  • Required for template tags or management commandsFriday, March 11, 2011
  • Decorator Apps http://www.flickr.com/photos/yum9me/2109549869/Friday, March 11, 2011
  • New Method New Field Custom Manager New AdminFriday, March 11, 2011
  • Situation 6 You want to add a field to a modelFriday, March 11, 2011
  • Lazy Field Insertion Django Categories http://github.com/washingtontimesFriday, March 11, 2011
  • Lazy Field Insertion Django Categories http://github.com/washingtontimesFriday, March 11, 2011
  • Lazy Field Insertion Django Categories http://github.com/washingtontimesFriday, March 11, 2011
  • Situation 7 You want to add a custom manager to a modelFriday, March 11, 2011
  • Lazy Manager Insertion Django MPTT http://github.com/django-mpttFriday, 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.pyFriday, March 11, 2011
  • Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick Django-TinyMCE’s models.pyFriday, March 11, 2011
  • Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick Django-TinyMCE’s admin.pyFriday, March 11, 2011
  • Lazy Registration of a Custom ModelAdmin Django TinyMCE http://github.com/justquick bottom of Django-TinyMCE’s admin.pyFriday, March 11, 2011
  • Touch PointsFriday, March 11, 2011
  • Touch Points of an App The parts of an application that usually need tweaking • URLs • Templates • View responsesFriday, 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 URLsFriday, March 11, 2011
  • Name your URLs url Function nameFriday, March 11, 2011
  • Reference your URLs by nameFriday, March 11, 2011
  • Situation 10 You want your templates to be easily overridableFriday, March 11, 2011
  • “Namespace” Templates All templates in coolapp a template “name space” templates coolapp base.htmlFriday, 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.htmlFriday, March 11, 2011
  • Extend one template site_base.html base.html base.html summary.html index.html detail.htmlFriday, March 11, 2011
  • Extend one template site_base.html base.html base.html summary.html index.html detail.htmlFriday, March 11, 2011
  • Extend one template coolapp/base.htmlFriday, March 11, 2011
  • Extend one template coolapp/base.htmlFriday, March 11, 2011
  • Import your blocks Allows you to override any of the templates extra_head.html coolapp/detail.htmlFriday, March 11, 2011
  • Situation 11 You want flexibility storing uploaded filesFriday, March 11, 2011
  • Define a Storage OptionFriday, 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.comFriday, March 11, 2011