Esempio n. 1
0
def create_blank_dashboard(request):
    """
    """
    name = request.GET.get('name', None)
    if not name:
        respondWithError("The dashboard must have a name.", True)
    if not createNewDashboard(request.user.id, name):
        respondWithError("You already have a dashboard with that name.", True)
    return respondWithSuccess(name + " created successfully.")
Esempio n. 2
0
def create_blank_dashboard(request):
    """
    """
    name = request.GET.get('name', None)
    if not name:
        respondWithError("The dashboard must have a name.", True)
    if not createNewDashboard(request.user.id, name):
        respondWithError("You already have a dashboard with that name.", True)
    return respondWithSuccess(name + " created successfully.")
Esempio n. 3
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)
Esempio n. 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)