инициализация ограничений AAA

 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
class InitObjectActions:
"""инициализация базовых значений и ограничителей объекта"""
def __init__(self,user, object):
self.basic_object = self._get_basic_object(object.__class__.__name__)
def _get_basic_action(self, basic_action_name):
"""создание/извлечение базовых действий"""
actions_set = [ BasicAction.objects.get_or_create(name = action[0], description = action[1]) for action in BASIC_ACTIONS if action[0] == basic_action_name ]
actions = [ item[0] for item in actions_set ]
return actions[0]
def _get_basic_object(self, basic_object_name):
"""извлечение/создание базового объекта"""
basic_object, created = BasicObject.objects.get_or_create(name = basic_object_name)
return basic_object
def _get_object_action(self, basic_action_name):
"""создание/извлечение действий для объектов"""
object_action, created = ObjectAction.objects.get_or_create(object = self.basic_object, action = _get_basic_action(basic_action_name))
return object_action
def set_delimiters(self, basic_object_names, basic_action_name):
"""создание ограничителей для действия над объектом"""
objects = [ self._get_basic_object(name) for name in basic_object_names]
action = self._get_object_action(basic_action_name)
delimiters_set = [ Delimiter.objects.get_or_create(object_action = action, object = object) for object in objects]
delimiters = [item[0] for item in delimiters_set ]
return delimiters