2017-02-21 09:34:24 +01:00
|
|
|
from django.apps import apps
|
2013-03-11 21:32:09 +01:00
|
|
|
|
2018-11-01 17:30:18 +01:00
|
|
|
from .models import State, Workflow
|
2013-01-26 16:33:55 +01:00
|
|
|
|
2013-02-02 10:24:28 +01:00
|
|
|
|
2013-03-11 21:32:09 +01:00
|
|
|
def create_builtin_workflows(sender, **kwargs):
|
|
|
|
"""
|
2014-11-13 22:23:16 +01:00
|
|
|
Receiver function to create a simple and a complex workflow. It is
|
2016-09-03 21:43:11 +02:00
|
|
|
connected to the signal django.db.models.signals.post_migrate during
|
|
|
|
app loading.
|
2013-03-11 21:32:09 +01:00
|
|
|
"""
|
2015-01-16 14:18:34 +01:00
|
|
|
if Workflow.objects.exists():
|
|
|
|
# If there is at least one workflow, then do nothing.
|
|
|
|
return
|
2013-03-11 21:32:09 +01:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow_1 = Workflow(name="Simple Workflow")
|
2018-11-04 14:02:30 +01:00
|
|
|
workflow_1.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_1_1 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="submitted",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_1,
|
|
|
|
allow_create_poll=True,
|
|
|
|
allow_support=True,
|
|
|
|
allow_submitter_edit=True,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_1_1.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_1_2 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="accepted",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_1,
|
|
|
|
recommendation_label="Acceptance",
|
|
|
|
css_class="success",
|
|
|
|
merge_amendment_into_final=1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_1_2.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_1_3 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="rejected",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_1,
|
|
|
|
recommendation_label="Rejection",
|
|
|
|
css_class="danger",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_1_3.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_1_4 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="not decided",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_1,
|
|
|
|
recommendation_label="No decision",
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_1_4.save(skip_autoupdate=True)
|
2015-01-16 14:18:34 +01:00
|
|
|
state_1_1.next_states.add(state_1_2, state_1_3, state_1_4)
|
|
|
|
workflow_1.first_state = state_1_1
|
2018-11-04 14:02:30 +01:00
|
|
|
workflow_1.save(skip_autoupdate=True)
|
2015-01-16 14:18:34 +01:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow_2 = Workflow(name="Complex Workflow")
|
2018-11-04 14:02:30 +01:00
|
|
|
workflow_2.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_1 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="published",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
allow_support=True,
|
|
|
|
allow_submitter_edit=True,
|
|
|
|
dont_set_identifier=True,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_1.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_2 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="permitted",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Permission",
|
|
|
|
allow_create_poll=True,
|
|
|
|
allow_submitter_edit=True,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_2.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_3 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="accepted",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Acceptance",
|
|
|
|
css_class="success",
|
|
|
|
merge_amendment_into_final=1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_3.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_4 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="rejected",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Rejection",
|
|
|
|
css_class="danger",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_4.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_5 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="withdrawed",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_5.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_6 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="adjourned",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Adjournment",
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_6.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_7 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="not concerned",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="No concernment",
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_7.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_8 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="refered to committee",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Referral to committee",
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_8.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_9 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="needs review",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_9.save(skip_autoupdate=True)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_10 = State(
|
2019-01-12 23:01:42 +01:00
|
|
|
name="rejected (not authorized)",
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow=workflow_2,
|
|
|
|
recommendation_label="Rejection (not authorized)",
|
|
|
|
css_class="default",
|
|
|
|
merge_amendment_into_final=-1,
|
|
|
|
)
|
2018-11-04 14:02:30 +01:00
|
|
|
state_2_10.save(skip_autoupdate=True)
|
2015-01-16 14:18:34 +01:00
|
|
|
state_2_1.next_states.add(state_2_2, state_2_5, state_2_10)
|
2019-01-06 16:22:33 +01:00
|
|
|
state_2_2.next_states.add(
|
|
|
|
state_2_3, state_2_4, state_2_5, state_2_6, state_2_7, state_2_8, state_2_9
|
|
|
|
)
|
2015-01-16 14:18:34 +01:00
|
|
|
workflow_2.first_state = state_2_1
|
2018-11-04 14:02:30 +01:00
|
|
|
workflow_2.save(skip_autoupdate=True)
|
2017-02-21 09:34:24 +01:00
|
|
|
|
|
|
|
|
2017-03-06 16:34:20 +01:00
|
|
|
def get_permission_change_data(sender, permissions, **kwargs):
|
2017-02-21 09:34:24 +01:00
|
|
|
"""
|
2017-03-06 16:34:20 +01:00
|
|
|
Yields all necessary collections if 'motions.can_see' permission changes.
|
2017-02-21 09:34:24 +01:00
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
motions_app = apps.get_app_config(app_label="motions")
|
2017-02-21 09:34:24 +01:00
|
|
|
for permission in permissions:
|
2017-03-06 16:34:20 +01:00
|
|
|
# There could be only one 'motions.can_see' and then we want to return data.
|
2019-01-06 16:22:33 +01:00
|
|
|
if (
|
|
|
|
permission.content_type.app_label == motions_app.label
|
|
|
|
and permission.codename == "can_see"
|
|
|
|
):
|
2017-03-06 16:34:20 +01:00
|
|
|
yield from motions_app.get_startup_elements()
|