cornerstone.soup Lighning Talk on Plone Conference 2009

860 views

Published on

shows how to use cornerstone.soup, a lightweight mass-data storage inside zodb for zope2 and plone

Published in: Technology, Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
860
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

cornerstone.soup Lighning Talk on Plone Conference 2009

  1. 1. Plone Conference 2009 Budapest Lightning Talk cornerstone.soup isolated container for queryable records Jens Klein <jens@bluedynamics.com> 2010-10-29 Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  2. 2. Use-Cases Need Container for many entities (mass-data) of non-CMSish content, like: – Votes, – Data from a Poll, – Orders in a Webshop, – measuring data, – (fill in your use-case here) tested with Plone 3.3 Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  3. 3. Soup Characteristics ● isolated: all in one persistent local utility; ● stores generic „Records“: – persistent items – with attributes passed in at construction time as keyword arguments. ● has its own local index (ZopeToolKit); ● fetches items by query. Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  4. 4. Recipe Cook your own Soup Heat editor in a large soucepan, subclass the soup 1 object and give it an appropriate id: >>> from cornerstone.soup import Soup >>> class MySoup(Soup): ... id = u'mysoup' Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  5. 5. Recipe Cook your own Soup Provide a Catalog Factory and cook for 2-3 minutes, until 2 softened but not colored. >>> from zope.interface import implements >>> from zope.catalog.catalog import Catalog >>> from zope.catalog.field import FieldIndex >>> from cornerstone.soup.interfaces import ICatalogFactory >>> class MyCatalogFactory(object): ... implements(ICatalogFactory) ... ... def __call__(self): ... catalog = Catalog() ... catalog[u'name'] = FieldIndex(field_name='name', ... field_callable=False) ... return catalog Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  6. 6. Recipe Cook your own Soup Add one utility registered under the same name as 3 the soup-id, stirring, for 20 seconds: <utility name="mysoup" factory=".mymodule.MyCatalogFactory" provides="cornerstone.soup.interfaces.ICatalogFactory" /> Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  7. 7. Recipe Cook your own Soup 4 Add two local utilities to componentregistry.xml registered under the same name as the soup-id, and bring to boil. <utilities> <utility name="mysoup" factory="mymodule.MySoup" interface="cornerstone.soup.interfaces.ISoup" /> <utility name="mysoup" factory="five.intid.intid.OFSIntIds" interface="zope.app.intid.interfaces.IIntIds" /> </utilities> Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  8. 8. Recipe Cook your own Soup Start your Plone, turn heat to low, cover and 5 simmer for some minutes. Go to portal_setup and import your packages GenericSetup profile. Season and add a little more data if desired. >>> from zope.component import getUtility >>> from cornerstone.soup.interfaces import ISoup >>> soup = getUtility(ISoup, name=u'mysoup') >>> from cornerstone.soup import Record >>> rec = Record(name=u'rec1') >>> soup.add(rec) >>> rec = Record(name=u'rec2') >>> soup.add(rec) Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  9. 9. Enjoy your soup bon appetit! Query data: >>> soup.query(name=u'rec1') [<Record at /.../record-0>] >>> soup.query(name=u'rec2') [<Record at /.../record-1>] Modify data: >>> rec.data['name'] = u'rec1' >>> soup.reindex([rec]) >>> soup.query(name=u'rec1') [<Record at /.../record-0>, <Record at /.../record-1>] Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz
  10. 10. Ingredients and complete recipe http://pypi.python.org/pypi/cornerstone.soup Creative Commons Namensnennung- Keine kommerzielle Nutzung- Keine Bearbeitung 3.0 Österreich Lizenz

×