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 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.")
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.")
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!"})