|
20 | 20 |
|
21 | 21 | from AccessControl import Unauthorized |
22 | 22 | from Acquisition import aq_base |
| 23 | +from bika.lims.interfaces import IAnalysis |
23 | 24 | from plone.dexterity.interfaces import IDexterityContent |
24 | 25 | from Products.Archetypes.interfaces import IBaseObject |
25 | 26 | from Products.CMFCore.interfaces import ISiteRoot |
@@ -225,6 +226,38 @@ def __init__(self, context): |
225 | 226 | self.keys = schema.keys() |
226 | 227 |
|
227 | 228 |
|
| 229 | +class AnalysisDataProvider(Base): |
| 230 | + """Data provider for Analysis content types. |
| 231 | +
|
| 232 | + Supplements the standard ATDataProvider with computed fields that are |
| 233 | + implemented as methods rather than AT schema fields and therefore not |
| 234 | + picked up automatically. |
| 235 | + """ |
| 236 | + interface.implements(IInfo) |
| 237 | + component.adapts(IAnalysis) |
| 238 | + |
| 239 | + def __init__(self, context): |
| 240 | + super(AnalysisDataProvider, self).__init__(context) |
| 241 | + # No schema keys – this provider only adds computed fields via |
| 242 | + # the attributes mapping below. |
| 243 | + self.keys = [] |
| 244 | + self.attributes = {} |
| 245 | + |
| 246 | + def to_dict(self): |
| 247 | + """Return computed analysis fields.""" |
| 248 | + out = {} |
| 249 | + |
| 250 | + get_formatted = getattr(self.context, "getFormattedResult", None) |
| 251 | + if callable(get_formatted): |
| 252 | + out["getFormattedResult"] = get_formatted(html=False) |
| 253 | + |
| 254 | + is_retest = getattr(self.context, "isRetest", None) |
| 255 | + if callable(is_retest): |
| 256 | + out["isRetest"] = is_retest() |
| 257 | + |
| 258 | + return out |
| 259 | + |
| 260 | + |
228 | 261 | class SiteRootDataProvider(Base): |
229 | 262 | """ Site Root Adapter |
230 | 263 | """ |
|
0 commit comments