|
1 |
# w.c.s. - web application for online forms
|
|
2 |
# Copyright (C) 2005-2013 Entr'ouvert
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
|
17 |
import json
|
|
18 |
import sys
|
|
19 |
|
|
20 |
from quixote import get_publisher, get_request, redirect
|
|
21 |
|
|
22 |
from quixote.directory import Directory
|
|
23 |
from qommon.form import *
|
|
24 |
from qommon import errors
|
|
25 |
|
|
26 |
from wcs.roles import get_user_roles
|
|
27 |
from wcs.workflows import WorkflowStatusItem, register_item_class
|
|
28 |
from wcs.api import get_user_from_api_query_string
|
|
29 |
|
|
30 |
|
|
31 |
class DataDirectory(Directory):
|
|
32 |
_q_exports = ['']
|
|
33 |
|
|
34 |
def __init__(self, formdata, wfstatusitem, wfstatus):
|
|
35 |
self.formdata = formdata
|
|
36 |
self.wfstatusitem = wfstatusitem
|
|
37 |
|
|
38 |
def _q_index(self):
|
|
39 |
if not get_request().is_json():
|
|
40 |
raise errors.AccessForbiddenError()
|
|
41 |
if not get_request().get_method() == 'POST':
|
|
42 |
raise errors.AccessForbiddenError()
|
|
43 |
|
|
44 |
user = get_user_from_api_query_string() or get_request().user
|
|
45 |
if not self.wfstatusitem.check_auth(self.formdata, user):
|
|
46 |
raise errors.AccessForbiddenError()
|
|
47 |
|
|
48 |
if hasattr(get_request(), 'json'):
|
|
49 |
self.formdata.update_workflow_data(get_request().json)
|
|
50 |
self.formdata.store()
|
|
51 |
|
|
52 |
|
|
53 |
class AcceptDataWorkflowStatusItem(WorkflowStatusItem):
|
|
54 |
description = N_('Accept Data')
|
|
55 |
key = 'accept-data'
|
|
56 |
waitpoint = False
|
|
57 |
by = []
|
|
58 |
|
|
59 |
directory_name = 'data'
|
|
60 |
directory_class = DataDirectory
|
|
61 |
|
|
62 |
def render_as_line(self):
|
|
63 |
if self.by:
|
|
64 |
return _('Accept Data by %s') % self.render_list_of_roles(self.by)
|
|
65 |
else:
|
|
66 |
return _('Accept Data (not completed)')
|
|
67 |
|
|
68 |
def get_parameters(self):
|
|
69 |
return ('by',)
|
|
70 |
|
|
71 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
|
|
72 |
if 'by' in parameters:
|
|
73 |
form.add(WidgetList, '%sby' % prefix, title = _('By'),
|
|
74 |
element_type = SingleSelectWidget,
|
|
75 |
value = self.by,
|
|
76 |
add_element_label = _('Add Role'),
|
|
77 |
element_kwargs={'render_br': False,
|
|
78 |
'options': [(None, '---')] + self.get_list_of_roles()})
|
|
79 |
|
|
80 |
register_item_class(AcceptDataWorkflowStatusItem)
|