[Checkins] SVN: megrok.feeds/trunk/src/megrok/feeds/ Successfullly
moved the configuration of a Feed into a grokker.
Brandon Rhodes
brandon at rhodesmill.org
Sat Jul 19 17:03:22 EDT 2008
Log message for revision 88618:
Successfullly moved the configuration of a Feed into a grokker.
Changed:
U megrok.feeds/trunk/src/megrok/feeds/components.py
U megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py
U megrok.feeds/trunk/src/megrok/feeds/meta.py
-=-
Modified: megrok.feeds/trunk/src/megrok/feeds/components.py
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/components.py 2008-07-19 20:29:13 UTC (rev 88617)
+++ megrok.feeds/trunk/src/megrok/feeds/components.py 2008-07-19 21:03:21 UTC (rev 88618)
@@ -6,5 +6,8 @@
class IFeedable(Interface):
pass # marker interface
+class Feed(object):
+ pass
+
class AtomFeed(Atom_1_0_FeedView):
pass
Modified: megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py 2008-07-19 20:29:13 UTC (rev 88617)
+++ megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py 2008-07-19 21:03:21 UTC (rev 88618)
@@ -43,29 +43,33 @@
#
-from vice.outbound.core.interfaces import IFeed, IFeedItem
-
from zope.interface import Interface
-from megrok.feeds.components import IFeedable
-
-# need three things:
-# (1) we need to create an adapter from MammothBox to IFeed
-# (2) we need to mark MammothBox as IFeedable
-# (3) we need to create a View that makes an IFeedable render
-
class IMammoth(Interface):
name = schema.TextLine(title=u"Name")
size = schema.TextLine(title=u"Size", default=u"Quite normal")
-class MammothBox(object): #grok.Container): #grok.Application, #grok.Container
- grok.implements(IFeedable) #(2)
+class MammothBox(object):
+ pass
+class Mammoth(grok.Model):
+ grok.implements(IMammoth)
+ name = FieldProperty(IMammoth['name'])
+ size = FieldProperty(IMammoth['size'])
+
+# The actions necessary to put a Feed on top of these objects.
+
+from megrok.feeds.components import Feed, AtomFeed
+#from vice.outbound.core.interfaces import IFeedItem
from datetime import datetime
-class MammothBoxFeed(grok.Adapter): #(1)
+class Atom(AtomFeed):
+ """This is what makes /atom return an Atom feed."""
+
+class MammothBoxFeed(Feed):
+ """This makes a MammothBox able to be rendered as a feed."""
grok.context(MammothBox)
- grok.provides(IFeed)
+
def __init__(self, context):
self.context = context
self.description = 'A box full of mammoths.'
@@ -87,21 +91,11 @@
while False:
yield None
-from megrok.feeds.components import AtomFeed
+#class MammothItem(grok.Adapter):
+# """This makes a Mammoth eligible to appear as a feed item."""
+# grok.context(Mammoth)
+# grok.implements(IFeedItem)
+# def __init__(self, context):
+# self.context = context
+# self.title = 'Mammoth %s' % self.name
-class Atom(AtomFeed):
- pass
-
-class Mammoth(grok.Model):
- grok.implements(IMammoth)
-
- name = FieldProperty(IMammoth['name'])
- size = FieldProperty(IMammoth['size'])
-
-class MammothItem(grok.Adapter): #(3)
- grok.context(Mammoth)
- grok.implements(IFeedItem)
- def __init__(self, context):
- self.context = context
- self.title = 'Mammoth %s' % self.name
- # DUH, don't need this yet, will finish later
Modified: megrok.feeds/trunk/src/megrok/feeds/meta.py
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/meta.py 2008-07-19 20:29:13 UTC (rev 88617)
+++ megrok.feeds/trunk/src/megrok/feeds/meta.py 2008-07-19 21:03:21 UTC (rev 88618)
@@ -5,10 +5,35 @@
from megrok.feeds import components
from zope import interface, component
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from vice.outbound.core.interfaces import IFeed
def default_view_name(factory, module=None, **data):
return factory.__name__.lower()
+class FeedGrokker(martian.ClassGrokker):
+ martian.component(components.Feed)
+ martian.directive(grok.context)
+
+ def grok(self, name, factory, module_info, **kw):
+ return super(FeedGrokker, self).grok(name, factory, module_info, **kw)
+
+ def execute(self, factory, config, context, **kw):
+ adapts = (context,)
+
+ config.action(
+ discriminator=('adapter', adapts, interface.Interface, u''),
+ callable=component.provideAdapter,
+ args=(factory, adapts, IFeed, u''),
+ )
+
+ config.action(
+ discriminator=None,
+ callable=interface.classImplements,
+ args=(context, components.IFeedable),
+ )
+
+ return True
+
class AtomFeedGrokker(martian.ClassGrokker):
martian.component(components.AtomFeed)
martian.directive(grok.layer, default=IDefaultBrowserLayer)
More information about the Checkins
mailing list