Permalink
Browse files

symptoms can be made inactive through registry

  • Loading branch information...
1 parent 43d43c0 commit 6edf6ec7dc9d6f4fee67f73f041e98555d87b077 @gotcha gotcha committed Mar 30, 2012
@@ -33,6 +33,11 @@
provides=".interfaces.IDiagnosis"
factory=".diagnosis.diagnosisFromBrain" />
+ <adapter
+ for=".interfaces.ISymptom"
+ provides=".interfaces.IIsActive"
+ factory=".symptoms.ActiveSymptom" />
+
<!-- symptoms -->
<subscriber
@@ -21,7 +21,9 @@ def _update(self):
self._status = self._status and symptom.status
def _updateSymptoms(self):
- self._symptoms = subscribers((self.context,), ISymptom)
+ self._symptoms = [symptom
+ for symptom in subscribers((self.context,), ISymptom)
+ if symptom.isActive]
for symptom in self._symptoms:
self._mapping[symptom.title] = symptom
@@ -2,6 +2,7 @@
from zope.schema import TextLine
from zope.schema import List
+from zope.schema import Bool
from zope.schema import Int
from zope.schema import Text
from zope.schema import Object
@@ -15,6 +16,12 @@ class ISymptom(Interface):
status = Int(title=u'Status')
+class IIsActive(Interface):
+
+ isActive = Bool(title=u'isActive')
+ name = TextLine(title=u'Name')
+
+
class IDiagnosis(Interface):
status = Int(title=u'Status')
@@ -3,8 +3,15 @@
from bs4 import BeautifulSoup
from zope.interface import implements
+from zope.component import getUtility
+from zope.schema import Bool
+
+from plone.registry import Record
+from plone.registry.interfaces import IRegistry
+from plone.registry.interfaces import IPersistentField
from collective.jekyll.interfaces import ISymptom
+from collective.jekyll.interfaces import IIsActive
class SymptomBase(object):
@@ -20,6 +27,37 @@ def _update(self):
raise NotImplemented(
'Update should be computed by inheriting classes.')
+ @property
+ def isActive(self):
+ return IIsActive(self).isActive
+
+
+class ActiveSymptom(object):
+ implements(IIsActive)
+
+ def __init__(self, context):
+ self.context = context
+
+ @property
+ def isActive(self):
+ registry = getUtility(IRegistry)
+ active = registry.get(self.name, None)
+ if active is None:
+ makeRegistryRecord(registry, self)
+ active = True
+ return active
+
+ @property
+ def name(self):
+ klass = self.context.__class__
+ return '.'.join((klass.__module__, klass.__name__))
+
+
+def makeRegistryRecord(registry, symptom):
+ field = IPersistentField(Bool(title=u"Active symptom", description=u"",
+ default=True))
+ registry.records[symptom.name] = Record(field, True)
+
class IdFormatSymptom(SymptomBase):
@@ -37,12 +37,21 @@ class Filter(unittest.TestCase):
def setUp(self):
from collective.jekyll.interfaces import IDiagnosis
from collective.jekyll.interfaces import ISymptom
+ from collective.jekyll.interfaces import IIsActive
from collective.jekyll.diagnosis import Diagnosis
from collective.jekyll.symptoms import SymptomBase
testing.setUp(self)
provideAdapter(Diagnosis, [int], IDiagnosis)
+ class AlwaysActive(object):
+ def __init__(self, context):
+ self.context = context
+
+ isActive = True
+
+ provideAdapter(AlwaysActive, [ISymptom], IIsActive)
+
class PositiveSymptom(SymptomBase):
title = "Positive"
help = "Is positive."

0 comments on commit 6edf6ec

Please sign in to comment.