Пример #1
0
    def get_component(self, request: Request):
        component_name = request.query_params.get('component', None)
        component_instance = PluginUtils.get_component(
            config_type=self.config_type,
            plugin_label=self.plugin_label,
            component_name=component_name,
        )
        if component_instance:
            component_data, found = component_instance.get_javascript()

            if found:
                return Response(data={
                    'data': component_data
                })
            else:
                LOG.error('Component javascript not found for plugin {}:{}'.format(self.config_type, self.plugin_label))
                return HttpResponse(status=204)
        else:
            LOG.error('Component not registered for plugin {}:{}'.format(self.config_type, self.plugin_label))
            return HttpResponse(status=204)
Пример #2
0
    def get_components(self, request: Request):
        component_names = request.query_params.get('components', None)  # type: str

        if not component_names:
            return HttpResponse(status=204)

        component_names_list = component_names.split(',')
        component_names_list = list(set(component_names_list))
        components_data = {}

        for component_name in component_names_list:
            component_instance = PluginUtils.get_component(
                config_type=self.config_type,
                plugin_label=self.plugin_label,
                component_name=component_name,
            )
            if component_instance:
                component_data, found = component_instance.get_javascript()

                if found:
                    components_data[component_instance.component_name] = component_data
                else:
                    LOG.error('Component {} javascript not found for plugin {}:{}'.format(
                        component_name,
                        self.config_type,
                        self.plugin_label,
                    ))
            else:
                LOG.error('Component {} not registered for plugin {}:{}'.format(
                    component_name,
                    self.config_type,
                    self.plugin_label,
                ))

        if len(components_data) > 0:
            return Response(data={
                'components': components_data
            })
        else:
            return HttpResponse(status=204)