Total Complexity | 7 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | |||
3 | from AccessControl import Unauthorized |
||
4 | from bika.lims import api |
||
5 | from bika.lims.api.security import check_permission |
||
6 | from Products.CMFCore.permissions import ModifyPortalContent |
||
7 | from Products.CMFCore.permissions import View |
||
8 | from senaite.core.interfaces.datamanager import IDataManager |
||
9 | from zope.interface import implementer |
||
10 | |||
11 | |||
12 | @implementer(IDataManager) |
||
13 | class DataManager(object): |
||
14 | """Data manager base class.""" |
||
15 | |||
16 | def __init__(self, context): |
||
17 | self.context = context |
||
18 | |||
19 | def get(self, name): |
||
20 | raise NotImplementedError("Must be implemented by subclass") |
||
21 | |||
22 | def query(self, name, default=None): |
||
23 | try: |
||
24 | return self.get(name) |
||
25 | except AttributeError: |
||
26 | return default |
||
27 | |||
28 | def set(self, name, value): |
||
29 | raise NotImplementedError("Must be implemented by subclass") |
||
30 | |||
31 | def can_access(self): |
||
32 | return check_permission(View, self.context) |
||
33 | |||
34 | def can_write(self): |
||
35 | return check_permission(ModifyPortalContent, self.context) |
||
36 |