|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
|
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
|
7
|
|
|
# Foundation, version 2. |
|
8
|
|
|
# |
|
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
12
|
|
|
# details. |
|
13
|
|
|
# |
|
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
|
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17
|
|
|
# |
|
18
|
|
|
# Copyright 2018-2021 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
import plone |
|
22
|
|
|
import plone.protect |
|
23
|
|
|
from Products.Archetypes.config import REFERENCE_CATALOG |
|
24
|
|
|
from Products.CMFCore.utils import getToolByName |
|
25
|
|
|
from Products.Five.browser import BrowserView |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class SetAnalyst(BrowserView): |
|
29
|
|
|
"""The Analysis dropdown sets worksheet.Analyst immediately |
|
30
|
|
|
""" |
|
31
|
|
|
|
|
32
|
|
|
def __init__(self, context, request): |
|
33
|
|
|
self.context = context |
|
34
|
|
|
self.request = request |
|
35
|
|
|
|
|
36
|
|
|
def __call__(self): |
|
37
|
|
|
mtool = getToolByName(self, 'portal_membership') |
|
38
|
|
|
plone.protect.CheckAuthenticator(self.request) |
|
39
|
|
|
plone.protect.PostOnly(self.request) |
|
40
|
|
|
value = self.request.get('value', '') |
|
41
|
|
|
if not value: |
|
42
|
|
|
return |
|
43
|
|
|
if not mtool.getMemberById(value): |
|
44
|
|
|
return |
|
45
|
|
|
self.context.setAnalyst(value) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
class SetInstrument(BrowserView): |
|
49
|
|
|
"""The Instrument dropdown sets worksheet.Instrument immediately |
|
50
|
|
|
""" |
|
51
|
|
|
|
|
52
|
|
|
def __init__(self, context, request): |
|
53
|
|
|
self.context = context |
|
54
|
|
|
self.request = request |
|
55
|
|
|
|
|
56
|
|
|
def __call__(self): |
|
57
|
|
|
rc = getToolByName(self.context, REFERENCE_CATALOG) |
|
58
|
|
|
plone.protect.CheckAuthenticator(self.request) |
|
59
|
|
|
plone.protect.PostOnly(self.request) |
|
60
|
|
|
value = self.request.get('value', '') |
|
61
|
|
|
if not value: |
|
62
|
|
|
raise Exception("Invalid instrument") |
|
63
|
|
|
instrument = rc.lookupObject(value) |
|
64
|
|
|
if not instrument: |
|
65
|
|
|
raise Exception("Unable to lookup instrument") |
|
66
|
|
|
self.context.setInstrument(instrument) |
|
67
|
|
|
|