def save_new_dashboard(request): """ Ajax call to save the dashboard and the positioning and width of the tables on it. Called from the dashboard.html """ data = json.loads(request.POST.get('data', '')) userId = request.POST.get('userId', None) dashboardWidth = request.POST.get('dashboardWidth', None) dashId = request.POST.get('dashId', None) user = request.user clone = False if not dashId: return respondWithError( "Error finding dashboard. Please refresh and try again.", True) else: dashboard = Dashboard.objects(id=dashId).first() if dashboard.isPublic and dashboard.analystId != user.id: dashboard = cloneDashboard(userId, dashboard) if not dashboard: return respondWithError( "You already have a dashboard with that name.", True) clone = True if not user.defaultDashboard: setDefaultDashboard(user, dashboard.id) elif dashboard.isPublic: updateChildren(dashboard.id) for table in data: tableId = "" if "id" in table: tableId = table['id'] isDefault = False if table['isDefault'] == "True": isDefault = True left = "" if 'left' in table: left = table['left'].replace('px', '') top = "" if 'top' in table: top = table['top'].replace('px', '') sortBy = None if 'sortDirection' in table and 'sortField' in table: sortBy = { 'field': table['sortField'], 'direction': table['sortDirection'] } response = save_data(userId, table['columns'], table['tableName'], tableId=tableId, left=left, top=top, width=table['width'], isDefaultOnDashboard=isDefault, dashboardWidth=dashboardWidth, sortBy=sortBy, dashboard=dashboard, clone=clone) if not response['success']: return httpResponse(response) return respondWithSuccess("Dashboard saved successfully!")
def save_new_dashboard(request): """ Ajax call to save the dashboard and the positioning and width of the tables on it. Called from the dashboard.html """ data = json.loads(request.POST.get('data', '')) userId = request.POST.get('userId', None) dashId = request.POST.get('dashId', None) user = request.user clone = False if not dashId: return respondWithError( "Error finding dashboard. Please refresh and try again.", True) else: dashboard = Dashboard.objects(id=dashId).first() if dashboard.isPublic and dashboard.analystId != user.id: dashboard = cloneDashboard(userId, dashboard) if not dashboard: return respondWithError( "You already have a dashboard with that name.", True) clone = True if not user.defaultDashboard: setDefaultDashboard(user, dashboard.id) elif dashboard.isPublic: updateChildren(dashboard.id) for table in data: isDefault = False if table['isDefault'].lower() == "true": isDefault = True sortBy = None if 'sortDirection' in table and 'sortField' in table: sortBy = { 'field': table['sortField'], 'direction': table['sortDirection'] } response = save_data(userId, table['columns'], table['tableName'], tableId=table['id'], isDefaultOnDashboard=isDefault, sortBy=sortBy, dashboard=dashboard, clone=clone, row=table['row'], grid_col=table['col'], sizex=table['sizex'], sizey=table['sizey']) if not response['success']: return httpResponse(response) return httpResponse({ "success": True, "clone": clone, "dashId": str(dashboard.id), "message": "Dashboard saved successfully!" })
def save_new_dashboard(request): """ Ajax call to save the dashboard and the positioning and width of the tables on it. Called from the dashboard.html """ data = json.loads(request.POST.get("data", "")) userId = request.POST.get("userId", None) dashId = request.POST.get("dashId", None) user = request.user clone = False if not dashId: return respondWithError("Error finding dashboard. Please refresh and try again.", True) else: dashboard = Dashboard.objects(id=dashId).first() if dashboard.isPublic and dashboard.analystId != user.id: dashboard = cloneDashboard(userId, dashboard) if not dashboard: return respondWithError("You already have a dashboard with that name.", True) clone = True if not user.defaultDashboard: setDefaultDashboard(user, dashboard.id) elif dashboard.isPublic: updateChildren(dashboard.id) for table in data: isDefault = False if table["isDefault"].lower() == "true": isDefault = True sortBy = None if "sortDirection" in table and "sortField" in table: sortBy = {"field": table["sortField"], "direction": table["sortDirection"]} response = save_data( userId, table["columns"], table["tableName"], tableId=table["id"], isDefaultOnDashboard=isDefault, sortBy=sortBy, dashboard=dashboard, clone=clone, row=table["row"], grid_col=table["col"], sizex=table["sizex"], sizey=table["sizey"], ) if not response["success"]: return httpResponse(response) return httpResponse( {"success": True, "clone": clone, "dashId": str(dashboard.id), "message": "Dashboard saved successfully!"} )
def save_new_dashboard(request): """ Ajax call to save the dashboard and the positioning and width of the tables on it. Called from the dashboard.html """ data = json.loads(request.POST.get('data', '')) userId = request.POST.get('userId', None) dashboardWidth = request.POST.get('dashboardWidth', None) dashId = request.POST.get('dashId', None) user = request.user clone = False if not dashId: return respondWithError("Error finding dashboard. Please refresh and try again.", True) else: dashboard = Dashboard.objects(id=dashId).first() if dashboard.isPublic and dashboard.analystId != user.id: dashboard = cloneDashboard(userId, dashboard) if not dashboard: return respondWithError("You already have a dashboard with that name.", True) clone = True if not user.defaultDashboard: setDefaultDashboard(user, dashboard.id) elif dashboard.isPublic: updateChildren(dashboard.id) for table in data: tableId = "" if "id" in table: tableId = table['id'] isDefault = False if table['isDefault'] == "True": isDefault = True left = "" if 'left' in table: left = table['left'].replace('px','') top = "" if 'top' in table: top = table['top'].replace('px','') sortBy = None if 'sortDirection' in table and 'sortField' in table: sortBy = {'field':table['sortField'],'direction':table['sortDirection']} response = save_data(userId, table['columns'], table['tableName'], tableId=tableId, left=left, top=top, width=table['width'], isDefaultOnDashboard=isDefault, dashboardWidth=dashboardWidth, sortBy=sortBy, dashboard=dashboard, clone=clone) if not response['success']: return httpResponse(response) return respondWithSuccess("Dashboard saved successfully!")
def set_default_dashboard(request): """ Ajax call to set the users default dashboard. Called from saved_searches_list.html """ id = request.GET.get('id', None) dashName = setDefaultDashboard(request.user, id) if not dashName: respondWithError("An error occurred while updating dashboard. Please try again later.", True) return respondWithSuccess(dashName + " is now your default dashboard.")