-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpossible_theme_change.py
47 lines (38 loc) · 1.92 KB
/
possible_theme_change.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from iris_masters.models import Parameter, RecordState
from record_cards.permissions import RECARD_COORDINATOR_VALIDATION_DAYS
from themes.actions.group_tree import GroupThemeTree
from themes.models import ElementDetail
class PossibleThemeChange:
def __init__(self, record_card, group) -> None:
super().__init__()
self.record_card = record_card
self.user_group = group
def themes_to_change(self) -> list:
query_kwargs = ElementDetail.ENABLED_ELEMENTDETAIL_FILTERS.copy()
if self.only_ambit_themes():
qs = GroupThemeTree(self.group).themes_for_record(self.record_card)
else:
qs = ElementDetail.objects.all()
return qs.filter(**query_kwargs)
@property
def group(self):
return self.record_card.responsible_profile
def only_ambit_themes(self) -> bool:
"""
Check if only can be retrieved ambit themes or not.
Record card theme can only be changed to one inside group ambit:
- If group is dair, follow the ambit rules (in fact, all themes)
- If the record has been validated
- If record card has overcome the period of reassign the record outsite its ambit
:return: True if only ambit themes can be retrieved, else False
"""
if self.record_card.is_validated and not self.record_card.record_state_id == RecordState.CLOSED:
return True
if RECARD_COORDINATOR_VALIDATION_DAYS in self.group.group_permissions_codes:
max_reasign_days_outsite_ambit = int(Parameter.get_parameter_by_key("DIES_CANVI_TEMATICA_FORA_AREA_COORD",
10))
else:
max_reasign_days_outsite_ambit = int(Parameter.get_parameter_by_key("DIES_CANVI_TEMATICA_FORA_AREA", 8))
if self.record_card.days_in_ambit > max_reasign_days_outsite_ambit:
return True
return False