BRE/webapi/portal/info_models.py

161 lines
5.4 KiB
Python
Raw Permalink Normal View History

2024-06-07 19:50:21 +03:00
'''Data models for BRE portal'''
from enum import Enum, IntEnum, unique
@unique
class InputMethod(Enum):
'''Метод ввода данных на форме'''
read_only = -1
combo_box = 0
text_input = 1
text_area = 2
date_picker = 3
combo_dialog = 4
combo_dialog_simple_list = 5 # no search required to select from list
bool_toggle = 6
def text_to_method(text: str) -> InputMethod:
'''Input method from text transformation'''
if text == 'Текстовое поле':
return InputMethod.text_input
if text == 'Тумблер':
return InputMethod.bool_toggle
if text == 'Выпад. Cписок':
return InputMethod.combo_box
if text == 'Диалог (с выбором)':
return InputMethod.combo_dialog
return InputMethod.read_only
_FIELD_DATA = [
('Тип задачи', InputMethod.combo_box),
('Статус', InputMethod.read_only),
('Название задачи', InputMethod.text_input),
('Название контента', InputMethod.text_input),
('Характер изменения текста', InputMethod.combo_dialog_simple_list),
('Название контента для библиографической записи', InputMethod.text_input),
('Краткая дефиниция', InputMethod.text_input),
('Неизменный', InputMethod.read_only),
('Тип объекта', InputMethod.combo_dialog),
('Тематический словник', InputMethod.combo_dialog),
('Метки', InputMethod.combo_dialog),
('Курирующий редактор', InputMethod.combo_box),
('Исполнитель', InputMethod.combo_box),
('Ответственный за задачу', InputMethod.combo_box),
('Ответственный', InputMethod.combo_box),
('Ответственное подразделение', InputMethod.combo_box),
('Ответственная редакция', InputMethod.combo_box),
('Срок исполнения', InputMethod.date_picker),
('Источник термина', InputMethod.combo_dialog),
('Текст из ЭВ БРЭ', InputMethod.bool_toggle),
('Отображать на главной', InputMethod.bool_toggle),
('Обобщающая статья', InputMethod.bool_toggle),
('Период актуализации', InputMethod.combo_dialog_simple_list),
('Возрастное ограничение', InputMethod.combo_dialog_simple_list),
('Приоритет', InputMethod.combo_box),
('Тип статьи', InputMethod.combo_dialog_simple_list),
('Биржа', InputMethod.date_picker),
('Срок сдачи в ЕЭС 1', InputMethod.date_picker),
('Биржа инструментов', InputMethod.date_picker),
('Срок сдачи в ЕЭС 2', InputMethod.date_picker),
('Эксперт', InputMethod.combo_box),
('Номер договора', InputMethod.combo_box),
('Комментарий', InputMethod.text_area),
('Автор (на портале)', InputMethod.combo_box),
('ID задачи', InputMethod.read_only),
('Название контента в базе', InputMethod.read_only),
]
@unique
class FieldType(IntEnum):
'''Поля ввода'''
task_type = 0
status = 1
task_name = 2
content_name = 3
change_score = 4
biblio_name = 5
definition = 6
is_immutable = 7
object_type = 8
markers = 9
tags = 10
supervisor = 11
executor = 12
task_manager = 13
responsible = 14
department = 15
editorial = 16
date_target = 17
source = 18
electron_bre = 19
main_page = 20
is_general = 21
actualize_period = 22
age_restriction = 23
priority = 24
article_type = 25
date_exchange = 26
date_ees1 = 27
date_ex_tools = 28
date_ees2 = 29
expert = 30
contract = 31
comment = 32
author = 33
task_id = 34
content_name_db = 35
skip = -1
def to_label(self) -> str:
'''Get text label for input field'''
return _FIELD_DATA[self.value][0]
def input_method(self) -> InputMethod:
'''Get input method for field'''
return _FIELD_DATA[self.value][1]
_FILTER_DATA = [
('FilterTask', 'Тип задачи'),
('FilterDepartment', 'Ответственное подразделение'),
('FilterStatus', 'Статус задачи'),
('FilterResponsible', 'Ответственный за задачу'),
('FilterSupervisor', 'Курирующий редактор'),
('FilterExecutor', 'Исполнитель'),
('FilterObserver', 'Наблюдатель'),
('FilterDateCreatedBegin', 'Дата создания'),
('FilterDateCreatedEnd', 'Дата создания'),
('FilterDateTargetBegin', 'Срок исполнения'),
('FilterDateTargetEnd', 'Срок исполнения')
]
@unique
class FilterType(IntEnum):
'''Параметры фильтрации'''
task_type = 0
department = 1
status = 2
responsible = 3
supervisor = 4
executor = 5
observer = 6
created_begin = 7
created_end = 8
target_begin = 9
target_end = 10
def to_config(self) -> str:
'''Get input method for field'''
return _FILTER_DATA[self.value][0]
def to_label(self) -> str:
'''Get input method for field'''
return _FILTER_DATA[self.value][1]