Projet

Général

Profil

0001-workflows-add-action-to-disable-a-formdef-6973.patch

Frédéric Péters, 17 avril 2015 15:18

Télécharger (2,88 ko)

Voir les différences:

Subject: [PATCH] workflows: add action to disable a formdef (#6973)

 tests/test_workflows.py   | 17 +++++++++++++++++
 wcs/wf/disable_formdef.py | 27 +++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 wcs/wf/disable_formdef.py
tests/test_workflows.py
12 12
from wcs.workflows import (Workflow, WorkflowStatusItem,
13 13
        SendmailWorkflowStatusItem, SendSMSWorkflowStatusItem)
14 14
from wcs.wf.anonymise import AnonymiseWorkflowStatusItem
15
from wcs.wf.disable_formdef import DisableFormdefStatusItem
15 16
from wcs.wf.dispatch import DispatchWorkflowStatusItem
16 17
from wcs.wf.jump import JumpWorkflowStatusItem, _apply_timeouts
17 18
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
......
490 491
    item.perform(formdata) # nothing
491 492
    assert sms_mocking.sms[-1]['destinations'] == ['000']
492 493
    assert sms_mocking.sms[-1]['text'] == 'XXX'
494

  
495
def test_disable_formdef():
496
    formdef = FormDef()
497
    formdef.name = 'baz'
498
    formdef.fields = []
499
    formdef.store()
500

  
501
    formdata = formdef.data_class()()
502
    formdata.just_created()
503
    formdata.user_id = '1'
504
    formdata.store()
505

  
506
    item = DisableFormdefStatusItem()
507
    assert not FormDef.get(formdef.id).is_disabled()
508
    item.perform(formdata)
509
    assert FormDef.get(formdef.id).is_disabled()
wcs/wf/disable_formdef.py
1
# w.c.s. - web application for online forms
2
# Copyright (C) 2005-2015  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
from wcs.workflows import WorkflowStatusItem, register_item_class
18

  
19
class DisableFormdefStatusItem(WorkflowStatusItem):
20
    description = N_('Disable Form')
21
    key = 'disable_form'
22

  
23
    def perform(self, formdata):
24
        formdata.formdef.disabled = True
25
        formdata.formdef.store()
26

  
27
register_item_class(DisableFormdefStatusItem)
0
-