def ajax_table(self): search = self._prepare(int(env.request.parameters.get("page", 1)), int(env.request.parameters.get("rows", 30))) results = search.get_result() resrows = [] extradata = list(self._trigger_datasearch_hook("EXTRA_DATA", results)) extracol = list( filter(None, self._trigger_datasearch_hook("EXTRA_COLUMN"))) for i, obj in enumerate(results): cells = self._get_default_cells(obj, search) for prop, finfo, func in extracol: if isinstance(obj, ResultObject): ret = func(obj, extradata) else: ret = func( { env.dataprovider.format_path(f.split("/")[0], type=self.type): v for f, v in zip(search.get_paths(), obj) }, extradata) if finfo: cells[prop.name] = self._formatter.format(finfo, obj, ret) else: cells[prop.name] = ret resrows.append({"id": text_type(i), "cell": cells}) return utils.viewhelpers.GridAjaxResponse( resrows, results.total, criteria=search.all_criteria).add_html_content( mainmenu.HTMLMainMenu(update=True))
def draw(self): dataset = self.view_template.dataset() data = self.setup(dataset) if data: return data return view.ViewResponse( dataset.render(), menu=mainmenu.HTMLMainMenu(**self._mainmenu_options))
def mainmenu(self, datatype=None): kwargs = {} if datatype: kwargs["criteria_type"] = datatype return response.PrewikkaResponse({ "type": "content", "target": "#main_menu_ng", "content": mainmenu.HTMLMainMenu(**kwargs) })
def ajax_groupby(self): limit = int(env.request.parameters["limit"]) page = int(env.request.parameters.get("page", 1)) search = self._prepare(page, limit) step = search.get_step() results = search.get_result() resrows = [] # We need to reorder results according to what is expected permutation = [ search.get_index(f) for f in ["_aggregation"] + search.groupby ] for i, result in enumerate(results): values = [result[permutation[idx]] for idx in range(len(result))] cells = {} for idx, group in enumerate(search.groupby): label = values[idx + 1] if isinstance(label, datetime.datetime): label = label.strftime(step.unit_format) elif isinstance(label, datetime.timedelta): label = format_timedelta(label) link = search.get_groupby_link([group], [values[idx + 1]], step, cview='.forensic') cells[group] = resource.HTMLNode("a", label, href=link) link = search.get_groupby_link(search.groupby, values[1:], step, cview='.forensic') cells["_aggregation"] = resource.HTMLNode("a", values[0], href=link) resrows.append({"id": text_type(i), "cell": cells}) total = (page if len(resrows) < limit else page + 1) * limit return utils.viewhelpers.GridAjaxResponse( resrows, total).add_html_content(mainmenu.HTMLMainMenu(update=True))
def __init__(self, data, **kwargs): response.PrewikkaResponse.__init__(self, { "type": "content", "content": data }) menu = kwargs.get( "menu", mainmenu.HTMLMainMenu() if env.request.has_menu else None) if menu: self.add_ext_content("menu", menu) view_help = env.request.view.view_help if view_help: if view_help.startswith(("http://", "https://")): self.add_ext_content("help", view_help) elif env.config.general.get("help_location"): self.add_ext_content("help", url_for("baseview.help", path=view_help))
def agents(self): analyzer_data = list(self._get_analyzers(env.request.parameters.getlist("status"))) list(hookmanager.trigger("HOOK_AGENTS_EXTRA_CONTENT", analyzer_data)) extra_columns = filter(None, hookmanager.trigger("HOOK_AGENTS_EXTRA_COLUMN")) return view.ViewResponse(template.PrewikkaTemplate(__name__, "templates/agents.mak").render(data=analyzer_data, extra_columns=extra_columns), menu=mainmenu.HTMLMainMenu())