Skip to content

Commit

Permalink
Use decorator to declare what gets adapted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 2, 2021
1 parent 9928a0a commit 052b317
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/zc/sourcefactory/browser/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import zc.sourcefactory.mapping


@zope.component.adapter(zc.sourcefactory.mapping.ValueMappingSource,
zope.publisher.interfaces.browser.IBrowserRequest)
@zope.interface.implementer(zope.browser.interfaces.ITerms)
class MappedTerms(object):
"""A terms implementation that knows how to handle a source that was
created through a source factory.
"""

zope.component.adapts(zc.sourcefactory.mapping.ValueMappingSource,
zope.publisher.interfaces.browser.IBrowserRequest)

def __init__(self, source, request):
self.base = zope.component.getMultiAdapter(
[source.base, request], zope.browser.interfaces.ITerms)
Expand Down
12 changes: 4 additions & 8 deletions src/zc/sourcefactory/browser/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
import zc.sourcefactory.source


@zope.component.adapter(zc.sourcefactory.source.FactoredSource,
zope.publisher.interfaces.browser.IBrowserRequest)
@zope.interface.implementer(zope.browser.interfaces.ITerms)
class FactoredTerms(object):
"""A terms implementation that knows how to handle a source that was
created through a source factory.
"""

zope.component.adapts(
zc.sourcefactory.source.FactoredSource,
zope.publisher.interfaces.browser.IBrowserRequest)

def __init__(self, source, request):
self.source = source
self.request = request
Expand All @@ -46,15 +44,13 @@ def getValue(self, token):
return self.source.factory.getValue(self.source, token)


@zope.component.adapter(zc.sourcefactory.source.FactoredContextualSource,
zope.publisher.interfaces.browser.IBrowserRequest)
class FactoredContextualTerms(FactoredTerms):
"""A terms implementation that knows how to handle a source that was
created through a contextual source factory.
"""

zope.component.adapts(
zc.sourcefactory.source.FactoredContextualSource,
zope.publisher.interfaces.browser.IBrowserRequest)

def getTerm(self, value):
title = self.source.factory.getTitle(self.source.context, value)
token = self.source.factory.getToken(self.source.context, value)
Expand Down

0 comments on commit 052b317

Please sign in to comment.