当前位置: 首页>>代码示例>>Python>>正文


Python dashboard.Dashboard类代码示例

本文整理汇总了Python中crits.dashboards.dashboard.Dashboard的典型用法代码示例。如果您正苦于以下问题:Python Dashboard类的具体用法?Python Dashboard怎么用?Python Dashboard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dashboard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: updateChildren

def updateChildren(parentId, deletingParent=False):
    """
    Sets field 'hasParentChanged' to true on all dashboards that are clones of 
    the changing dashboard.
    If the dashboard is being deleted(or private) then it unsets the parent field.
    """
    Dashboard.objects(parent=parentId).update(set__hasParentChanged=True)
    if deletingParent:
        Dashboard.objects(parent=parentId).update(unset__parent=1)
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:9,代码来源:handlers.py

示例2: renameDashboard

def renameDashboard(id, name, userId):
    """
    Renames the given dashboard
    """
    if not name:
        return "You must give a name to the dashboard."
    if Dashboard.objects(name=name, analystId=userId):
        return "You already have a dashboard with that name."
    Dashboard.objects(id=id).update(set__name=name)
    return True
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:10,代码来源:handlers.py

示例3: ignore_parent

def ignore_parent(request, id):
    """
    Ajax call to ignore that the parent of the dashboard has been changed.
    Called from dashboard.html
    """
    try:
        Dashboard.objects(id=id).update(set__hasParentChanged=False)
    except:
        return respondWithError("An error occured while updating dashboard. Please try again later.", True)
    return respondWithSuccess("success")
开发者ID:brlogan,项目名称:crits,代码行数:10,代码来源:views.py

示例4: get_dashboard

def get_dashboard(user,dashId=None):
    """
    Gets a specific dashbaord for the user. If dashId is provided it looks it up.
    If dashId is not provided or the dashboard does not exist, it gets the user's
    default dashboard. If that dashboard does not exist, it first looks for a
    user-modified child of the public Default dashboard. Finally it will retrieve
    the public default dashboard if no others exist.
    """
    dashboard = None
    if dashId:
        dashboard = Dashboard.objects(id=dashId).first()
        if not dashboard:
            return {'success': False,
                'message': "The dashboard you selected no longer exists."}
    elif user.defaultDashboard:
        try:
            dashboard = Dashboard.objects(id=user.defaultDashboard).first()
        except:
            user.defaultDashboard = None
            user.save()
    if not dashboard:
        dashboard = Dashboard.objects(name="Default", analystId__not__exists=1, isPublic=True).first()
        if dashboard:
            cloneOfDefault = Dashboard.objects(parent=dashboard.id, analystId=user.id).first()
            if cloneOfDefault:
                dashboard = cloneOfDefault
        else:
            return {'success': False,
                'message': "No Default Dashboard. Run 'manage.py create_default_dashboard' to create."}
    dashId = dashboard.id
    tables = []
    savedTables = SavedSearch.objects(dashboard=dashId, isPinned=True)
    for table in savedTables:
        tables.append(createTableObject(user, table=table))
    otherDashboardIds = []
    otherDashboards = {}
    for dash in Dashboard.objects(id__ne=dashId, analystId=user.id):
        otherDashboardIds.append(dash.id)
        otherDashboards[dash.id] = dash.name
    otherSearches = []
    for search in SavedSearch.objects(dashboard__in=otherDashboardIds, isPinned=True) :
        otherSearches.append({
                        "id":search.id,
                        "dash":otherDashboards[search.dashboard],
                        "name":search.name
                        })
    return {"success": True,
            "tables": tables,
            "dashboards": getDashboardsForUser(user),
            "currentDash": str(dashId),
            'parentHasChanged':dashboard.hasParentChanged,
            'parent':dashboard.parent,
            'dashTheme':dashboard.theme,
            "otherSearches":otherSearches,
            "userId": dashboard.analystId}
开发者ID:armtash,项目名称:crits,代码行数:55,代码来源:handlers.py

示例5: changeTheme

def changeTheme(id, theme):
    """
    Changes theme of the dashboard. 
    CURRENTLY UNUSED.
    """
    try:
        Dashboard.objects(id=id).update(set__theme=theme)
    except Exception as e:
        print e
        return False
    return "Dashboard updated successfully."
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:11,代码来源:handlers.py

示例6: create_dashboard

def create_dashboard(drop=False):
    from crits.dashboards.dashboard import SavedSearch, Dashboard
    if drop:
        Dashboard.drop_collection()
        SavedSearch.drop_collection()
    defaultDashboard = Dashboard.objects(name="Default", analystId__not__exists=1 , isPublic=True).first()
    if not defaultDashboard:
        defaultDashboard = Dashboard()
        defaultDashboard.name = "Default"
        defaultDashboard.isPublic = True
        defaultDashboard.save()
        for title in ["Counts", "Top Campaigns","Recent Indicators",
                  "Recent Emails", "Recent Samples"]:
            savedSearch = SavedSearch()
            savedSearch.name = title
            savedSearch.dashboard = defaultDashboard.id
            savedSearch.isDefaultOnDashboard = True
            savedSearch.tableColumns = getColumnsForTable(title)
            if title == "Counts":
                savedSearch.sizex = 10
            elif title == "Top Campaigns":
                savedSearch.sizex = 25
            elif title == "Counts":
                savedSearch.sizey = 13
            elif title == "Recent Indicators":
                savedSearch.row = 15
            elif title == "Recent Emails":
                savedSearch.row = 23
            elif title == "Recent Samples":
                savedSearch.row = 31
                
            savedSearch.save()
        print "Default Dashboard Created."
    else:
        print "Default Dashboard already exists."
开发者ID:armtash,项目名称:crits,代码行数:35,代码来源:create_default_dashboard.py

示例7: delete_table

def delete_table(userId, id):
    """
    Deletes a table from the db. Only can be called via the saved_search.html
    """
    try:
        savedSearch = SavedSearch.objects(id=id).first()
        tableName = savedSearch.name
        doDelete = True
        message = tableName+" deleted successfully!"
        if savedSearch.isDefaultOnDashboard:
            dashboards = []
            for dash in Dashboard.objects(analystId=userId):
                dashboards.append(dash.id)
            if SavedSearch.objects(dashboard__in=dashboards, isDefaultOnDashboard=True, name=tableName).count() == 1:
                savedSearch.col = 1
                savedSearch.row = 1
                savedSearch.isPinned = False
                savedSearch.save()
                doDelete = False
                message = tableName+" is now hidden."
        if doDelete:
            dashId = savedSearch.dashboard
            savedSearch.delete()
            deleteDashboardIfEmpty(dashId)
    except Exception as e:
        print e
        return {'success': False,
                'message': "Search could not be found. Please refresh and try again."}
    return {'success': True,'message': message, 'wasDeleted': doDelete}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:29,代码来源:handlers.py

示例8: deleteDashboard

def deleteDashboard(id):
    """
    Deletes the dashboard with the given id and updates clones of it.
    Also deletes all saved searches affiliated with it
    """
    try:
        dashboard = Dashboard.objects(id=id).first()
        name = dashboard.name
        if dashboard.isPublic:
            updateChildren(id, deletingParent=True)
        SavedSearch.objects(dashboard=id).delete()
        Dashboard.objects(id=id).delete()
    except Exception as e:
        print e
        return False
    return name
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:16,代码来源:handlers.py

示例9: generate_search_for_saved_table

def generate_search_for_saved_table(user, id=None,request=None):
    """
    Called by edit_save_search in views.py. This is for editing a previously
    saved table or one of the default dashboard tables
    """
    from crits.core.handlers import data_query
    response = {}
    savedSearch = None
    try:
        savedSearch = SavedSearch.objects(id=id).first()
        if not savedSearch:
            response['Result'] = "ERROR"
            response['Message'] = "Error finding table, please try again later."
            return response
    except:
        savedSearch = SavedSearch()
        savedSearch.isDefaultOnDashboard = True
        savedSearch.name = id.replace("_", " ")
        id = None
    results = []
    records = []
    term = ""
    url = ""
    if not savedSearch.isDefaultOnDashboard:
        objType = get_obj_type_from_string(savedSearch.objType)
        resp = get_query_without_request(objType, user, savedSearch.searchTerm, "global")
        if resp['Result'] == "ERROR":
            return resp
        formatted_query = resp['query']
        term = resp['term']
        resp = data_query(objType, user, query=formatted_query, count=True)
        results.append({'count': resp['count'],
                                      'name': savedSearch.objType})
    else:
        results = {"name":savedSearch.name,
                   "count":str(len(records)),
                   "type":get_obj_name_from_title(savedSearch.name)}

        #special url to get the records of a default dashboard since their queries are different
        url = reverse("crits-dashboards-views-get_dashboard_table_data",
                      kwargs={"tableName":str(savedSearch.name.replace(" ", "_"))})
    args = {'term': term,
            'results': results,
            'dataUrl':url,
            'Result': "OK"
            }
    if savedSearch:
        args.update({'tableId':id,
                'tableName': savedSearch.name,
                'columns': savedSearch.tableColumns,
                'sortBy': savedSearch.sortBy,
                'sizex' : savedSearch.sizex,
                'maxRows': savedSearch.maxRows,
                'isDefaultOnDashboard': savedSearch.isDefaultOnDashboard,
                })
        if savedSearch.dashboard:
            args["currentDash"] = str(savedSearch.dashboard)
            args["dashtheme"] = Dashboard.objects(id=savedSearch.dashboard).first().theme
    return args
开发者ID:armtash,项目名称:crits,代码行数:59,代码来源:handlers.py

示例10: save_search

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("crits.dashboards.views.dashboard",
                                          kwargs={"dashId":newDash.id})
    return httpResponse(response)
开发者ID:brlogan,项目名称:crits,代码行数:57,代码来源:views.py

示例11: setDefaultDashboard

def setDefaultDashboard(user, dashId):
    """
    Sets the users default dashboard
    """
    try:
        name = Dashboard.objects(id=dashId).first().name
        user.defaultDashboard = dashId
        user.save()
        return name
    except:
        return False
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:11,代码来源:handlers.py

示例12: save_new_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!"}
    )
开发者ID:mishley,项目名称:crits,代码行数:49,代码来源:views.py

示例13: save_new_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)
    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!")
开发者ID:Lin0x,项目名称:crits,代码行数:47,代码来源:views.py

示例14: createNewDashboard

def createNewDashboard(userId, name):
    """
    Creates a new dashboard for the user
    """
    if Dashboard.objects(analystId=userId,name=name):
        return
    newDash = Dashboard()
    newDash.name = name
    newDash.analystId = userId
    newDash.save()
    return newDash
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:11,代码来源:handlers.py

示例15: getDashboardsForUser

def getDashboardsForUser(user):
    """
    Gets all the users dashboards and public dashboards. It will then remove 
    all public dashboards that have been cloned by the user
    """
    dashboards = Dashboard.objects(Q(analystId=user.id) | Q(isPublic=True))
    parents = []
    userDashboards = []
    #get all id's of parent dashboards
    for dash in dashboards:
        if dash.parent:
            parents.append(dash.parent)
    #remove any parent from the list to prevent duplicate dashboards
    for dash in dashboards:
        if not dash.id in parents:
            userDashboards.append(dash)
    return userDashboards
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:17,代码来源:handlers.py


注:本文中的crits.dashboards.dashboard.Dashboard类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。