Exemple #1
0
def save_search(request):
    """
    Ajax call to save the table. Only called from the saved_search.html
    """
    dashId = request.GET.get('dashId', None)
    newDashName = request.GET.get('newDashName', None)
    tableId = request.GET.get("tableId", None)
    errorMessage = None
    clone = False
    try:
        if newDashName:
            newDash = createNewDashboard(request.user.id, newDashName)
            if not newDash:
                raise(Exception, "Dashboard already exists")
            dashboard = newDash
        elif dashId:
            dashboard = Dashboard.objects(id=dashId).first()
            if dashboard.isPublic and dashboard.analystId != request.user.id:
                newDash = cloneDashboard(request.user.id, dashboard, cloneSearches = True, skip=tableId)
                dashboard = newDash
                clone = True
                newDashName = newDash.name
            elif dashboard.isPublic:
                updateChildren(dashboard.id)
        else:
            errorMessage = "Error finding dashboard. Please refresh and try again."
    except Exception as e:
        print e
        errorMessage = "You already have a dashboard with that name."
    if errorMessage:
        return respondWithError(errorMessage, True)
    userId = request.GET.get('userId', None)
    tableName = request.GET.get('tableName', None)
    searchTerm = request.GET.get('query', None)
    objType = request.GET.get('object_type', None)
    columns = json.loads(request.GET.get("columns", ""))
    sortBy = request.GET.get("sortBy", None)
    isDefault = request.GET.get("isDefaultOnDashboard", "False")
    sizex = request.GET.get("sizex", None)
    maxRows = request.GET.get("maxRows", None)
    if isDefault.lower() == "true":
        isDefault = True
    else:
        isDefault = False
    if sortBy:
        sortBy = json.loads(sortBy)
    response = save_data(userId, columns, tableName, searchTerm, objType, sortBy,
                         tableId, sizex=sizex, isDefaultOnDashboard=isDefault,
                         maxRows=maxRows,
                         dashboard=dashboard, clone=clone)
    if newDashName:
        response["newDashId"] = str(newDash.id)
        response["newDashName"] = newDash.name
        response["isClone"] = clone
        response["newDashUrl"] = reverse("cripts.dashboards.views.dashboard",
                                          kwargs={"dashId":newDash.id})
    return httpResponse(response)
Exemple #2
0
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!"
    })
Exemple #3
0
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!"})
Exemple #4
0
def save_search(request):
    """
    Ajax call to save the table. Only called from the saved_search.html
    """
    dashId = request.GET.get('dashId', None)
    newDashName = request.GET.get('newDashName', None)
    tableId = request.GET.get("tableId", None)
    errorMessage = None
    clone = False
    try:
        if newDashName:
            newDash = createNewDashboard(request.user.id, newDashName)
            if not newDash:
                raise (Exception, "Dashboard already exists")
            dashboard = newDash
        elif dashId:
            dashboard = Dashboard.objects(id=dashId).first()
            if dashboard.isPublic and dashboard.analystId != request.user.id:
                newDash = cloneDashboard(request.user.id,
                                         dashboard,
                                         cloneSearches=True,
                                         skip=tableId)
                dashboard = newDash
                clone = True
                newDashName = newDash.name
            elif dashboard.isPublic:
                updateChildren(dashboard.id)
        else:
            errorMessage = "Error finding dashboard. Please refresh and try again."
    except Exception as e:
        print e
        errorMessage = "You already have a dashboard with that name."
    if errorMessage:
        return respondWithError(errorMessage, True)
    userId = request.GET.get('userId', None)
    tableName = request.GET.get('tableName', None)
    searchTerm = request.GET.get('query', None)
    objType = request.GET.get('object_type', None)
    columns = json.loads(request.GET.get("columns", ""))
    sortBy = request.GET.get("sortBy", None)
    isDefault = request.GET.get("isDefaultOnDashboard", "False")
    sizex = request.GET.get("sizex", None)
    maxRows = request.GET.get("maxRows", None)
    if isDefault.lower() == "true":
        isDefault = True
    else:
        isDefault = False
    if sortBy:
        sortBy = json.loads(sortBy)
    response = save_data(userId,
                         columns,
                         tableName,
                         searchTerm,
                         objType,
                         sortBy,
                         tableId,
                         sizex=sizex,
                         isDefaultOnDashboard=isDefault,
                         maxRows=maxRows,
                         dashboard=dashboard,
                         clone=clone)
    if newDashName:
        response["newDashId"] = str(newDash.id)
        response["newDashName"] = newDash.name
        response["isClone"] = clone
        response["newDashUrl"] = reverse("cripts.dashboards.views.dashboard",
                                         kwargs={"dashId": newDash.id})
    return httpResponse(response)