示例#1
0
 def run(self, request, context):
     parent_id = utils.extract_int(request, 'id')
     offset = utils.extract_int(request, 'start')
     limit = utils.extract_int(request, 'limit')
     filter = request.REQUEST.get('filter')
     result = self.parent.get_rows(
         parent_id, offset, limit, filter)
     return PreJsonResult(result)
示例#2
0
 def run(self, request, context):
     parent_id = utils.extract_int(request, 'node')
     if parent_id < 1:
         parent_id = None
     filter = request.REQUEST.get('filter')
     result = self.parent.get_nodes(parent_id, filter)
     return PreJsonResult(result)
示例#3
0
    def run(self, request, context):
        id = utils.extract_int(request, 'id')
        if not id and self.parent.add_window:
            obj = self.parent.form_to_object(request, context, self.parent.get_row, self.parent.add_window)
        else:
            obj = self.parent.form_to_object(request, context, self.parent.get_row, self.parent.edit_window)

        # Проверка корректности полей сохраняемого объекта
        result = self.parent.validate_row(obj, request)
        if result:
            assert isinstance(result, ActionResult)
            return result

        result = self.parent.save_row(obj)
        if isinstance(result, OperationResult) and result.success is True:
            # узкое место. после того, как мы переделаем работу экшенов,
            # имя параметра с идентификатором запси может уже называться не
            # id
            if 'm3_audit' in settings.INSTALLED_APPS:
                AuditManager().write(
                    'dict-changes',
                    user=request.user,
                    model_object=obj,
                    type='new' if not id else 'edit')
            context.id = obj.id
        return result
示例#4
0
    def run(self, request, context):
        offset = utils.extract_int(request, 'start')
        limit = utils.extract_int(request, 'limit')
        filter = request.REQUEST.get('filter')
        direction = request.REQUEST.get('dir')
        user_sort = request.REQUEST.get('sort')
        if direction == 'DESC':
            user_sort = '-' + user_sort
        dict_list = []
        for item in self.parent.list_columns:
            if isinstance(item, (list, tuple)):
                dict_list.append(item[0])
            elif isinstance(item, dict) and item.get('data_index'):
                dict_list.append(item['data_index'])

        rows = self.parent.get_rows(request, context, offset, limit, filter, user_sort)
        return PreJsonResult(
            rows, self.parent.secret_json, dict_list=dict_list)
示例#5
0
    def run(self, request, context):
        base = self.parent
        # Получаем объект по id
        id = utils.extract_int(request, 'id')
        is_get_data = context.isGetData
        obj = base.get_row(id)
        # Разница между новым и созданным объектов в том,
        # что у нового нет id или он пустой
        create_new = True
        if isinstance(obj, dict) and obj.get('id') is not None:
            create_new = False
        elif hasattr(obj, 'id') and getattr(obj, 'id') is not None:
            create_new = False
        if create_new and base.add_window:
            win = self.parent.object_to_form(
                request, context, base.get_row, base.add_window)
        else:
            win = self.parent.object_to_form(
                request, context, base.get_row, base.edit_window)

        if not win.title:
            win.title = base.title
        win.form.url = base.save_action.get_absolute_url()
        # укажем адрес для чтения данных
        win.data_url = base.edit_window_action.get_absolute_url()

        # проверим право редактирования
        if not self.parent.has_perm(request, self.parent.PERM_EDIT):
            exclude_list = ['close_btn', 'cancel_btn']
            win.make_read_only(True, exclude_list)

        win.orig_request = request
        win.orig_context = context

        # У окна может быть процедура доп. конфигурации
        # под конкретный справочник
        if (hasattr(win, 'configure_for_dictpack') and
                callable(win.configure_for_dictpack)):
            win.configure_for_dictpack(action=self, pack=self.parent,
                                       request=request, context=context)

        if not is_get_data:
            # если запрашивали не данные - вернем окно
            return ExtUIScriptResult(base.get_edit_window(win))
        else:
            # если просили данные, то выжмем их из окна обратно в объект,
            # т.к. в окне могли быть и другие данных (не из этого объекта)
            data_object = {}
            # т.к. мы не знаем какие поля должны быть у объекта - создадим
            # все, которые есть на форме
            all_fields = win.form._get_all_fields(win)
            for field in all_fields:
                data_object[field.name] = None
            win.form.to_object(data_object)
            return PreJsonResult({'success': True, 'data': data_object})
示例#6
0
    def run(self, request, context):
        # Создаем форму для биндинга к ней
        win = self.parent.edit_node_window()
        win.form.bind_to_request(request)
        # Получаем наш объект по id
        id = utils.extract_int(request, 'id')
        obj = self.parent.get_node(id)
        # Биндим форму к объекту
        win.form.to_object(obj)
        result = self.parent.validate_node(obj, request)
        if result:
            assert isinstance(result, ActionResult)
            return result

        return self.parent.save_node(obj)
示例#7
0
    def run(self, request, context):
        offset = utils.extract_int(request, 'start')
        limit = utils.extract_int(request, 'limit')
        filter = request.REQUEST.get('filter')
        direction = request.REQUEST.get('dir')
        user_sort = request.REQUEST.get('sort')
        if direction == 'DESC':
            user_sort = '-' + user_sort
        dict_list = []
        for item in self.parent.list_columns:
            if isinstance(item, (list, tuple)):
                dict_list.append(item[0])
            elif isinstance(item, dict) and item.get('data_index'):
                dict_list.append(item['data_index'])

        if (hasattr(self.parent, 'modify_rows_query')
                and callable(self.parent.modify_rows_query)):
            rows = self.parent.get_rows_modified(offset, limit, filter,
                                                 user_sort, request, context)
        else:
            rows = self.parent.get_rows(offset, limit, filter, user_sort)
        return PreJsonResult(rows,
                             self.parent.secret_json,
                             dict_list=dict_list)
示例#8
0
    def run(self, request, context):
        # Создаем форму для биндинга к ней
        win = self.parent.edit_node_window()
        win.form.bind_to_request(request)
        # Получаем наш объект по id
        id = utils.extract_int(request, 'id')
        obj = self.parent.get_node(id)
        # Биндим форму к объекту
        win.form.to_object(obj)
        result = self.parent.validate_node(obj, request)
        if result:
            assert isinstance(result, ActionResult)
            return result

        return self.parent.save_node(obj)
示例#9
0
    def run(self, request, context):
        base = self.parent
        # Получаем id родительской группы.
        # Если приходит не валидное значение, то создаем узел в корне
        parent_id = utils.extract_int(request, base.contextTreeIdName)
        if parent_id < 1:
            parent_id = None
        # Создаем новую группу и биндим ее к форме
        obj = base.get_node()
        obj.parent_id = parent_id
        win = base.edit_node_window(create_new=True)
        win.orig_request = request
        win.orig_context = context
        win.form.from_object(obj)
        # Донастраиваем форму
        if not win.title:
            win.title = base.title
        win.form.url = base.save_node_action.get_absolute_url()

        return ExtUIScriptResult(base.get_node_edit_window(win))
示例#10
0
    def run(self, request, context):
        base = self.parent
        # Получаем id родительской группы.
        # Если приходит не валидное значение, то создаем узел в корне
        parent_id = utils.extract_int(request, base.contextTreeIdName)
        if parent_id < 1:
            parent_id = None
        # Создаем новую группу и биндим ее к форме
        obj = base.get_node()
        obj.parent_id = parent_id
        win = base.edit_node_window(create_new=True)
        win.orig_request = request
        win.orig_context = context
        win.form.from_object(obj)
        # Донастраиваем форму
        if not win.title:
            win.title = base.title
        win.form.url = base.save_node_action.get_absolute_url()

        return ExtUIScriptResult(base.get_node_edit_window(win))
示例#11
0
    def run(self, request, context):
        base = self.parent
        # Получаем id родительской группы.
        # Если приходит не валидное значение, то создаем узел в корне
        parent_id = utils.extract_int(request, base.contextTreeIdName)
        if parent_id < 1:
            parent_id = None
        # Создаем новую группу и биндим ее к форме
        obj = base.get_node()
        obj.parent_id = parent_id
        win = base.edit_node_window(create_new=True)
        win.form.from_object(obj)
        # Донастраиваем форму
        if not win.title:
            win.title = base.title
        win.form.url = base.save_node_action.get_absolute_url()

        # У окна может быть процедура доп. конфигурации под конкретный справочник
        if hasattr(win, 'configure_for_dictpack') and callable(win.configure_for_dictpack):
            win.configure_for_dictpack(action=self, pack=self.parent,
                                       request=request, context=context)

        return ExtUIScriptResult(base.get_node_edit_window(win))
示例#12
0
 def run(self, request, context):
     id = utils.extract_int(request, 'id')
     result = self.parent.get_node(id)
     return PreJsonResult(result)
示例#13
0
 def run(self, request, context):
     id = utils.extract_int(request, 'id')
     result = self.parent.get_node(id)
     return PreJsonResult(result)
示例#14
0
 def run(self, request, context):
     id = utils.extract_int(request, self.parent.contextTreeIdName)
     obj = self.parent.get_node(id)
     return self.parent.delete_node(obj)
示例#15
0
 def run(self, request, context):
     id = utils.extract_int(request, 'id')
     dest_id = utils.extract_int(request, 'dest_id')
     return self.parent.drag_node(id, dest_id)
示例#16
0
 def run(self, request, context):
     ids = utils.extract_int_list(request, 'id')
     dest_id = utils.extract_int(request, 'dest_id')
     return self.parent.drag_item(ids, dest_id)
示例#17
0
 def run(self, request, context):
     id = utils.extract_int(request, self.parent.contextTreeIdName)
     obj = self.parent.get_node(id)
     return self.parent.delete_node(obj)