def dashboard_ajax_post_view(): data = json.loads(request.forms['data']) for column in ['deactivated', 'left', 'middle', 'right']: order = 0 for identifier in data.get(column, []): config = WidgetConfiguration.get(WidgetConfiguration.identifier == identifier) config.column = column config.order = order order += 1 config.save() return HTTPResponse('OK')
def get_dashboard(): """ Get all widgets in the correct columns. """ dashboard = {"deactivated": [], "left": [], "middle": [], "right": []} for module in Configuration.get().get_activated_modules(): for identifier, widget in module.get_module().widgets.items(): config = WidgetConfiguration.get_or_create(identifier=identifier)[0] widget.update({"config": config, "identifier": identifier}) if config.column in ["left", "middle", "right"]: dashboard[config.column].append(widget) else: dashboard["deactivated"].append(widget) for column, widgets_list in dashboard.items(): dashboard[column] = sorted(widgets_list, key=lambda d: d["config"].order) return dashboard