SlideShare a Scribd company logo
Event Driven Programming in
           Plone
                     Matt Hamilton


    ...or how to extend Plone the lazy way



                Matt Hamilton
             Technical Director, Netsight
Who am I?


                    - Matt Hamilton
                    - Technical Director of
                         Netsight Internet Solutions

                    - A Plone ‘integrator’
                matth@netsight.co.uk
                     @hammertoe


Matt Hamilton       European Plone Symposium 2010, Sorrento          2
Who is this talk for?


           - Integrators
           - Those newish to Plone, they can
                assemble together a site from a
                number of products, but don't really
                want to alter them

           - I consider myself 'experienced' but this
                was a bit of an epiphany for me


Matt Hamilton           European Plone Symposium 2010, Sorrento   3
What is the problem?




                          ?
Matt Hamilton   European Plone Symposium 2010, Sorrento   4
What is the problem?




                I want to change the functionality of an
                existing product, but don't want to
                change the guts of it.




Matt Hamilton             European Plone Symposium 2010, Sorrento   5
What is the problem?




                Came from a real life problem.
                Developing Netsight's new website.
                Wanted to use plone.app.discussion, but
                needed to add spam checking on
                comments




Matt Hamilton            European Plone Symposium 2010, Sorrento   6
What is the problem?




Matt Hamilton   European Plone Symposium 2010, Sorrento   7
What is the problem?




                plone.app.discussion has captcha
                support already, but I wanted to add
                Akismet support, but no easy extension
                point




Matt Hamilton            European Plone Symposium 2010, Sorrento   8
Admittedly, I could have offered to
                refactor the whole p.a.discussion code ;)




Matt Hamilton             European Plone Symposium 2010, Sorrento   9
Considered Approaches


           - I could subclass the product and
                override it
                ➡ A lot of boiler-plate for small change

           - I could use an adapter and adapt the
                behaviour
                ➡ No adapter lookup where I needed it

           - I could 'just hack it in the original code'
                ➡ Yuck! Maintainability nightmare


Matt Hamilton                European Plone Symposium 2010, Sorrento   10
Eureka!

Matt Hamilton   European Plone Symposium 2010, Sorrento   11
Eureka!




                Use Events!


Matt Hamilton    European Plone Symposium 2010, Sorrento        12
Eureka!




           - I realised I could leave p.a.discussion
                alone, and just listen for an event for
                when a comment is added and then
                check it for spam

           - I can listen for an event from Plone and
                then do the behaviour afterwards



Matt Hamilton            European Plone Symposium 2010, Sorrento        13
Advantages




           - Leave the existing code alone
           - Work around lack of suitable extension
                point

           - Very little boilerplate code
           - All happens in same transaction still

Matt Hamilton           European Plone Symposium 2010, Sorrento           14
Zope's Event System




           - Events
           - Subscribers


Matt Hamilton        European Plone Symposium 2010, Sorrento   15
A Simple Event
    in configure.zcml:

    <subscriber
      for=".interfaces.IMyObject
           .interfaces.IMyEvent"
      handler=".events.myEventHandler"
      />


    in events.py:

    def myEventHandler( object, event):
        object.doSomeThing()


Matt Hamilton           European Plone Symposium 2010, Sorrento       16
Event Simpler Event


   in events.py:

   from five import grok
   from interfaces import IMyObject, IMyEvent

   @@grok.subscribe(IMyObject, IMyEvent)
   def myEventHandler( object, event):
       object.doSomeThing()




Matt Hamilton      European Plone Symposium 2010, Sorrento   17
Example - Spam Checking

     in events.py:

     from five import grok
     from plone.app.discussion.interfaces 
                        import IComment
     from zope.lifecycleevent.interfaces 
                        import IObjectAddedEvent

     @@grok.subscribe(IComment,
                     IObjectAddedEvent)
     def checkForSpam( comment, event):
         wf = getToolByName(comment,
                            'portal_workflow')
         if is_spam(comment.text):
              wf.doActionFor(comment, ‘spam’)


Matt Hamilton        European Plone Symposium 2010, Sorrento   18
Next Example - GetPaid




            GetPaid is an eCommerce add-on to
            Plone

            ➡ Allows you to mark any piece of
              content as ‘buyable’




Matt Hamilton         European Plone Symposium 2010, Sorrento   19
PloneConf 2010 Registration

                       User clicks ‘register’


         User fills in ‘add attendee’ form, and hits submit


         Event fired indicating object added to container


      Event subscriber marks item as buyable, adds to
       shopping cart, and then redirects to cart view
Matt Hamilton         European Plone Symposium 2010, Sorrento   20
GetPaid Example

     from Products.CMFCore.utils import getToolByName
     from getpaid.core.interfaces import workflow_states
     import interfaces

     def handlePaymentReceived( order, event ):

             if event.destination !=workflow_states.order.finance.CHARGED:
                 return
                
             for item in order.shopping_cart.values():
                 ob = item.resolve()
                 workflow = getToolByName( ob, 'portal_workflow')
                 state = workflow.getInfoFor( ob, 'review_state' )          
                 if state == 'published':
                     return
                 workflow.doActionFor( ob, 'publish')



Matt Hamilton              European Plone Symposium 2010, Sorrento    21
Other Ideas



           - Whenever a Folder is created, add
                some default content to it

           - When a Page is added, set some
                metadata fields

           - When an Event is added, check that an
                expiry date has been set no more than
                12 months in the future


Matt Hamilton           European Plone Symposium 2010, Sorrento            22
Questions?
        Matt Hamilton


matth@netsight.co.uk

More Related Content

Similar to Plone: Event Driven Programming

Soirée BPM - Introduction Logica
Soirée BPM - Introduction LogicaSoirée BPM - Introduction Logica
Soirée BPM - Introduction Logica
Normandy JUG
 
Internationalizing a React Application with Polyglot
Internationalizing a React Application with PolyglotInternationalizing a React Application with Polyglot
Internationalizing a React Application with Polyglot
Jonathan Petitcolas
 
Survival of the Fittest: Modernize your NonStop applications today
Survival of the Fittest: Modernize your NonStop applications todaySurvival of the Fittest: Modernize your NonStop applications today
Survival of the Fittest: Modernize your NonStop applications today
Thomas Burg
 
Open Mobile Broadcasting Phones
Open Mobile Broadcasting PhonesOpen Mobile Broadcasting Phones
Open Mobile Broadcasting Phones
Francois Lefebvre
 
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
Codemotion
 
Running a Plone product on Substance D
Running a Plone product on Substance DRunning a Plone product on Substance D
Running a Plone product on Substance D
Makina Corpus
 
Export consulting for IT&C companies
Export consulting for IT&C companiesExport consulting for IT&C companies
Export consulting for IT&C companies
Ailanthus Advance SL
 
How To Write A Robot For Google Wave
How To Write A Robot For Google WaveHow To Write A Robot For Google Wave
How To Write A Robot For Google Wave
MaximumHit Ltd
 
Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010
Christian Morbidoni
 
OroCRM CTO Yoav Kutner Presents at Meet Magento
OroCRM CTO Yoav Kutner Presents at Meet MagentoOroCRM CTO Yoav Kutner Presents at Meet Magento
OroCRM CTO Yoav Kutner Presents at Meet Magento
Jary Carter
 
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GITPuppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
Martin Alfke
 
Matomo: Your data compass
Matomo: Your data compassMatomo: Your data compass
Matomo: Your data compass
Kristina D.C. Hoeppner
 
Agile cymru Slicing Stories July 2015
Agile cymru   Slicing Stories July 2015Agile cymru   Slicing Stories July 2015
Agile cymru Slicing Stories July 2015
BeLiminal
 
easy_install digipy &amp; mlboost
easy_install digipy &amp; mlboosteasy_install digipy &amp; mlboost
easy_install digipy &amp; mlboost
Francis Piéraut
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
Mosky Liu
 
Rat Pack Remote Control - a technical Internet of Things (tm) basics primer
Rat Pack Remote Control - a technical Internet of Things (tm) basics primerRat Pack Remote Control - a technical Internet of Things (tm) basics primer
Rat Pack Remote Control - a technical Internet of Things (tm) basics primer
Sven Kräuter
 
Roadmap monthly newsletter - June 2011
Roadmap monthly newsletter -  June 2011Roadmap monthly newsletter -  June 2011
Roadmap monthly newsletter - June 2011
Frotcom
 
iPhone Apps with HTML5
iPhone Apps with HTML5iPhone Apps with HTML5
iPhone Apps with HTML5
Mayflower GmbH
 
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
Institut Lean France
 
Building a winning video marketing strategy - #MozCon 2013
Building a winning video marketing strategy - #MozCon 2013Building a winning video marketing strategy - #MozCon 2013
Building a winning video marketing strategy - #MozCon 2013
Phil Nottingham
 

Similar to Plone: Event Driven Programming (20)

Soirée BPM - Introduction Logica
Soirée BPM - Introduction LogicaSoirée BPM - Introduction Logica
Soirée BPM - Introduction Logica
 
Internationalizing a React Application with Polyglot
Internationalizing a React Application with PolyglotInternationalizing a React Application with Polyglot
Internationalizing a React Application with Polyglot
 
Survival of the Fittest: Modernize your NonStop applications today
Survival of the Fittest: Modernize your NonStop applications todaySurvival of the Fittest: Modernize your NonStop applications today
Survival of the Fittest: Modernize your NonStop applications today
 
Open Mobile Broadcasting Phones
Open Mobile Broadcasting PhonesOpen Mobile Broadcasting Phones
Open Mobile Broadcasting Phones
 
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
Rat Pack Remote Control – an Internet of Things basics hands on workshop by S...
 
Running a Plone product on Substance D
Running a Plone product on Substance DRunning a Plone product on Substance D
Running a Plone product on Substance D
 
Export consulting for IT&C companies
Export consulting for IT&C companiesExport consulting for IT&C companies
Export consulting for IT&C companies
 
How To Write A Robot For Google Wave
How To Write A Robot For Google WaveHow To Write A Robot For Google Wave
How To Write A Robot For Google Wave
 
Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010
 
OroCRM CTO Yoav Kutner Presents at Meet Magento
OroCRM CTO Yoav Kutner Presents at Meet MagentoOroCRM CTO Yoav Kutner Presents at Meet Magento
OroCRM CTO Yoav Kutner Presents at Meet Magento
 
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GITPuppet Camp Germany 2020 - Puppet Control Repo and GIT
Puppet Camp Germany 2020 - Puppet Control Repo and GIT
 
Matomo: Your data compass
Matomo: Your data compassMatomo: Your data compass
Matomo: Your data compass
 
Agile cymru Slicing Stories July 2015
Agile cymru   Slicing Stories July 2015Agile cymru   Slicing Stories July 2015
Agile cymru Slicing Stories July 2015
 
easy_install digipy &amp; mlboost
easy_install digipy &amp; mlboosteasy_install digipy &amp; mlboost
easy_install digipy &amp; mlboost
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
 
Rat Pack Remote Control - a technical Internet of Things (tm) basics primer
Rat Pack Remote Control - a technical Internet of Things (tm) basics primerRat Pack Remote Control - a technical Internet of Things (tm) basics primer
Rat Pack Remote Control - a technical Internet of Things (tm) basics primer
 
Roadmap monthly newsletter - June 2011
Roadmap monthly newsletter -  June 2011Roadmap monthly newsletter -  June 2011
Roadmap monthly newsletter - June 2011
 
iPhone Apps with HTML5
iPhone Apps with HTML5iPhone Apps with HTML5
iPhone Apps with HTML5
 
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
Lean Thinking in IT by Marie-Pia Ignace, Lean IT Summit 2014
 
Building a winning video marketing strategy - #MozCon 2013
Building a winning video marketing strategy - #MozCon 2013Building a winning video marketing strategy - #MozCon 2013
Building a winning video marketing strategy - #MozCon 2013
 

More from Matt Hamilton

Ceci n’est pas un canard - Machine Learning and Generative Adversarial Networks
Ceci n’est pas un canard - Machine Learning and Generative Adversarial NetworksCeci n’est pas un canard - Machine Learning and Generative Adversarial Networks
Ceci n’est pas un canard - Machine Learning and Generative Adversarial Networks
Matt Hamilton
 
Ceci N'est Pas Un Canard – and Other Machine Learning Stories
Ceci N'est Pas Un Canard – and Other Machine Learning StoriesCeci N'est Pas Un Canard – and Other Machine Learning Stories
Ceci N'est Pas Un Canard – and Other Machine Learning Stories
Matt Hamilton
 
Intro to Machine Learning and AI
Intro to Machine Learning and AIIntro to Machine Learning and AI
Intro to Machine Learning and AI
Matt Hamilton
 
Open Source, The Natural Fit for Content Management in the Enterprise
Open Source, The Natural Fit for Content Management in the EnterpriseOpen Source, The Natural Fit for Content Management in the Enterprise
Open Source, The Natural Fit for Content Management in the Enterprise
Matt Hamilton
 
Supercharge Your Career with Open Source
Supercharge Your Career with Open SourceSupercharge Your Career with Open Source
Supercharge Your Career with Open Source
Matt Hamilton
 
How to get started with the Pluggable Authentication System
How to get started with the Pluggable Authentication SystemHow to get started with the Pluggable Authentication System
How to get started with the Pluggable Authentication System
Matt Hamilton
 
Plone and Single-Sign On - Active Directory and the Holy Grail
Plone and Single-Sign On - Active Directory and the Holy GrailPlone and Single-Sign On - Active Directory and the Holy Grail
Plone and Single-Sign On - Active Directory and the Holy Grail
Matt Hamilton
 
Mistakes Made and Lessons Learnt Scaling Plone post-Launch
Mistakes Made and Lessons Learnt Scaling Plone post-LaunchMistakes Made and Lessons Learnt Scaling Plone post-Launch
Mistakes Made and Lessons Learnt Scaling Plone post-Launch
Matt Hamilton
 
Plone Symposium East 2011 Keynote: Plone, A Solution not a Product
Plone Symposium East 2011 Keynote: Plone, A Solution not a ProductPlone Symposium East 2011 Keynote: Plone, A Solution not a Product
Plone Symposium East 2011 Keynote: Plone, A Solution not a Product
Matt Hamilton
 
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
Matt Hamilton
 
The Flexibility of Open Source - Plone in the Public Sector
The Flexibility of Open Source - Plone in the Public SectorThe Flexibility of Open Source - Plone in the Public Sector
The Flexibility of Open Source - Plone in the Public Sector
Matt Hamilton
 
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
Matt Hamilton
 
Lipstick on a Pig - European Plone Symposium 2009
Lipstick on a Pig - European Plone Symposium 2009Lipstick on a Pig - European Plone Symposium 2009
Lipstick on a Pig - European Plone Symposium 2009
Matt Hamilton
 
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
Matt Hamilton
 
NextGen Roadshow Bmex Case Study
NextGen Roadshow Bmex Case StudyNextGen Roadshow Bmex Case Study
NextGen Roadshow Bmex Case Study
Matt Hamilton
 
Open Source and Content Management (+audio)
Open Source and Content Management (+audio)Open Source and Content Management (+audio)
Open Source and Content Management (+audio)
Matt Hamilton
 

More from Matt Hamilton (16)

Ceci n’est pas un canard - Machine Learning and Generative Adversarial Networks
Ceci n’est pas un canard - Machine Learning and Generative Adversarial NetworksCeci n’est pas un canard - Machine Learning and Generative Adversarial Networks
Ceci n’est pas un canard - Machine Learning and Generative Adversarial Networks
 
Ceci N'est Pas Un Canard – and Other Machine Learning Stories
Ceci N'est Pas Un Canard – and Other Machine Learning StoriesCeci N'est Pas Un Canard – and Other Machine Learning Stories
Ceci N'est Pas Un Canard – and Other Machine Learning Stories
 
Intro to Machine Learning and AI
Intro to Machine Learning and AIIntro to Machine Learning and AI
Intro to Machine Learning and AI
 
Open Source, The Natural Fit for Content Management in the Enterprise
Open Source, The Natural Fit for Content Management in the EnterpriseOpen Source, The Natural Fit for Content Management in the Enterprise
Open Source, The Natural Fit for Content Management in the Enterprise
 
Supercharge Your Career with Open Source
Supercharge Your Career with Open SourceSupercharge Your Career with Open Source
Supercharge Your Career with Open Source
 
How to get started with the Pluggable Authentication System
How to get started with the Pluggable Authentication SystemHow to get started with the Pluggable Authentication System
How to get started with the Pluggable Authentication System
 
Plone and Single-Sign On - Active Directory and the Holy Grail
Plone and Single-Sign On - Active Directory and the Holy GrailPlone and Single-Sign On - Active Directory and the Holy Grail
Plone and Single-Sign On - Active Directory and the Holy Grail
 
Mistakes Made and Lessons Learnt Scaling Plone post-Launch
Mistakes Made and Lessons Learnt Scaling Plone post-LaunchMistakes Made and Lessons Learnt Scaling Plone post-Launch
Mistakes Made and Lessons Learnt Scaling Plone post-Launch
 
Plone Symposium East 2011 Keynote: Plone, A Solution not a Product
Plone Symposium East 2011 Keynote: Plone, A Solution not a ProductPlone Symposium East 2011 Keynote: Plone, A Solution not a Product
Plone Symposium East 2011 Keynote: Plone, A Solution not a Product
 
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
Mountain Tops to Archipelagos - The People Behind Plone (+AUDIO)
 
The Flexibility of Open Source - Plone in the Public Sector
The Flexibility of Open Source - Plone in the Public SectorThe Flexibility of Open Source - Plone in the Public Sector
The Flexibility of Open Source - Plone in the Public Sector
 
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
Plone - Revised Roadmap: Plone 3,4,5 and beyond - Dutch Plone Users Day (+AUDIO)
 
Lipstick on a Pig - European Plone Symposium 2009
Lipstick on a Pig - European Plone Symposium 2009Lipstick on a Pig - European Plone Symposium 2009
Lipstick on a Pig - European Plone Symposium 2009
 
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
Kent Connects: Harnessing Open Source for Shared Services and Partnership Wor...
 
NextGen Roadshow Bmex Case Study
NextGen Roadshow Bmex Case StudyNextGen Roadshow Bmex Case Study
NextGen Roadshow Bmex Case Study
 
Open Source and Content Management (+audio)
Open Source and Content Management (+audio)Open Source and Content Management (+audio)
Open Source and Content Management (+audio)
 

Recently uploaded

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

Plone: Event Driven Programming

  • 1. Event Driven Programming in Plone Matt Hamilton ...or how to extend Plone the lazy way Matt Hamilton Technical Director, Netsight
  • 2. Who am I? - Matt Hamilton - Technical Director of Netsight Internet Solutions - A Plone ‘integrator’ matth@netsight.co.uk @hammertoe Matt Hamilton European Plone Symposium 2010, Sorrento 2
  • 3. Who is this talk for? - Integrators - Those newish to Plone, they can assemble together a site from a number of products, but don't really want to alter them - I consider myself 'experienced' but this was a bit of an epiphany for me Matt Hamilton European Plone Symposium 2010, Sorrento 3
  • 4. What is the problem? ? Matt Hamilton European Plone Symposium 2010, Sorrento 4
  • 5. What is the problem? I want to change the functionality of an existing product, but don't want to change the guts of it. Matt Hamilton European Plone Symposium 2010, Sorrento 5
  • 6. What is the problem? Came from a real life problem. Developing Netsight's new website. Wanted to use plone.app.discussion, but needed to add spam checking on comments Matt Hamilton European Plone Symposium 2010, Sorrento 6
  • 7. What is the problem? Matt Hamilton European Plone Symposium 2010, Sorrento 7
  • 8. What is the problem? plone.app.discussion has captcha support already, but I wanted to add Akismet support, but no easy extension point Matt Hamilton European Plone Symposium 2010, Sorrento 8
  • 9. Admittedly, I could have offered to refactor the whole p.a.discussion code ;) Matt Hamilton European Plone Symposium 2010, Sorrento 9
  • 10. Considered Approaches - I could subclass the product and override it ➡ A lot of boiler-plate for small change - I could use an adapter and adapt the behaviour ➡ No adapter lookup where I needed it - I could 'just hack it in the original code' ➡ Yuck! Maintainability nightmare Matt Hamilton European Plone Symposium 2010, Sorrento 10
  • 11. Eureka! Matt Hamilton European Plone Symposium 2010, Sorrento 11
  • 12. Eureka! Use Events! Matt Hamilton European Plone Symposium 2010, Sorrento 12
  • 13. Eureka! - I realised I could leave p.a.discussion alone, and just listen for an event for when a comment is added and then check it for spam - I can listen for an event from Plone and then do the behaviour afterwards Matt Hamilton European Plone Symposium 2010, Sorrento 13
  • 14. Advantages - Leave the existing code alone - Work around lack of suitable extension point - Very little boilerplate code - All happens in same transaction still Matt Hamilton European Plone Symposium 2010, Sorrento 14
  • 15. Zope's Event System - Events - Subscribers Matt Hamilton European Plone Symposium 2010, Sorrento 15
  • 16. A Simple Event in configure.zcml: <subscriber for=".interfaces.IMyObject .interfaces.IMyEvent" handler=".events.myEventHandler" /> in events.py: def myEventHandler( object, event): object.doSomeThing() Matt Hamilton European Plone Symposium 2010, Sorrento 16
  • 17. Event Simpler Event in events.py: from five import grok from interfaces import IMyObject, IMyEvent @@grok.subscribe(IMyObject, IMyEvent) def myEventHandler( object, event): object.doSomeThing() Matt Hamilton European Plone Symposium 2010, Sorrento 17
  • 18. Example - Spam Checking in events.py: from five import grok from plone.app.discussion.interfaces import IComment from zope.lifecycleevent.interfaces import IObjectAddedEvent @@grok.subscribe(IComment, IObjectAddedEvent) def checkForSpam( comment, event): wf = getToolByName(comment, 'portal_workflow') if is_spam(comment.text): wf.doActionFor(comment, ‘spam’) Matt Hamilton European Plone Symposium 2010, Sorrento 18
  • 19. Next Example - GetPaid GetPaid is an eCommerce add-on to Plone ➡ Allows you to mark any piece of content as ‘buyable’ Matt Hamilton European Plone Symposium 2010, Sorrento 19
  • 20. PloneConf 2010 Registration User clicks ‘register’ User fills in ‘add attendee’ form, and hits submit Event fired indicating object added to container Event subscriber marks item as buyable, adds to shopping cart, and then redirects to cart view Matt Hamilton European Plone Symposium 2010, Sorrento 20
  • 21. GetPaid Example from Products.CMFCore.utils import getToolByName from getpaid.core.interfaces import workflow_states import interfaces def handlePaymentReceived( order, event ):     if event.destination !=workflow_states.order.finance.CHARGED:         return             for item in order.shopping_cart.values():         ob = item.resolve()         workflow = getToolByName( ob, 'portal_workflow')         state = workflow.getInfoFor( ob, 'review_state' )                   if state == 'published':             return         workflow.doActionFor( ob, 'publish') Matt Hamilton European Plone Symposium 2010, Sorrento 21
  • 22. Other Ideas - Whenever a Folder is created, add some default content to it - When a Page is added, set some metadata fields - When an Event is added, check that an expiry date has been set no more than 12 months in the future Matt Hamilton European Plone Symposium 2010, Sorrento 22
  • 23. Questions? Matt Hamilton matth@netsight.co.uk