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
 
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 (19)

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

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

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