SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a Plone: Event Driven Programming

Soirée BPM - Introduction Logica
Soirée BPM - Introduction LogicaSoirée BPM - Introduction Logica
Soirée BPM - Introduction LogicaNormandy JUG
 
Internationalizing a React Application with Polyglot
Internationalizing a React Application with PolyglotInternationalizing a React Application with Polyglot
Internationalizing a React Application with PolyglotJonathan 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 todayThomas Burg
 
Open Mobile Broadcasting Phones
Open Mobile Broadcasting PhonesOpen Mobile Broadcasting Phones
Open Mobile Broadcasting PhonesFrancois 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 DMakina Corpus
 
Export consulting for IT&C companies
Export consulting for IT&C companiesExport consulting for IT&C companies
Export consulting for IT&C companiesAilanthus 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 WaveMaximumHit Ltd
 
Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010Linked Open Camera @ Fammi Sapere 2010
Linked Open Camera @ Fammi Sapere 2010Christian 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 MagentoJary 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 GITMartin Alfke
 
Agile cymru Slicing Stories July 2015
Agile cymru   Slicing Stories July 2015Agile cymru   Slicing Stories July 2015
Agile cymru Slicing Stories July 2015BeLiminal
 
easy_install digipy &amp; mlboost
easy_install digipy &amp; mlboosteasy_install digipy &amp; mlboost
easy_install digipy &amp; mlboostFrancis Piéraut
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013Mosky 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 primerSven Kräuter
 
Roadmap monthly newsletter - June 2011
Roadmap monthly newsletter -  June 2011Roadmap monthly newsletter -  June 2011
Roadmap monthly newsletter - June 2011Frotcom
 
iPhone Apps with HTML5
iPhone Apps with HTML5iPhone Apps with HTML5
iPhone Apps with HTML5Mayflower 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 2014Institut 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 2013Phil Nottingham
 

Semelhante a 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
 

Mais de 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 NetworksMatt 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 StoriesMatt Hamilton
 
Intro to Machine Learning and AI
Intro to Machine Learning and AIIntro to Machine Learning and AI
Intro to Machine Learning and AIMatt 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 EnterpriseMatt Hamilton
 
Supercharge Your Career with Open Source
Supercharge Your Career with Open SourceSupercharge Your Career with Open Source
Supercharge Your Career with Open SourceMatt 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 SystemMatt 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 GrailMatt 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-LaunchMatt 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 ProductMatt 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 SectorMatt 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 2009Matt 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 StudyMatt 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
 

Mais de 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)
 

Último

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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 

Último (20)

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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 

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