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


Python dashboard.SavedSearch类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: clear_dashboard

def clear_dashboard(dashId):
    """
    Clears all the set positions and widths of the tables on the dashboard
    """
    try:
        SavedSearch.objects(dashboard=dashId).update(unset__left=1,unset__top=1,unset__width=1)
    except:
        return {'success': False, 
                'message': "An unexpected error occurred while resetting dash. Please refresh and try again"}
    return {'success': True, 
            'message': "Dashboard Reset"}
开发者ID:Lin0x,项目名称:crits,代码行数:11,代码来源:handlers.py

示例5: migrate_all_searches

def migrate_all_searches():
    multiplier = 2
    for search in SavedSearch.objects():
        if "left" in search and search.left > 0:
            search.col = search.left/multiplier
        elif search.isDefaultOnDashboard:
             convert_default_searches(search, "left")
        if "width" in search:
            search.sizex = search.width/multiplier
        elif search.isDefaultOnDashboard:
             convert_default_searches(search, "width")
        if search.isDefaultOnDashboard:
            convert_default_searches(search, "top")
        search.save()
    SavedSearch.objects().update(unset__left=1, unset__top=1, unset__width=1)
开发者ID:0x3a,项目名称:crits,代码行数:15,代码来源:migrate_dashboard_searches.py

示例6: 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

示例7: clear_dashboard

def clear_dashboard(dashId):
    """
    Clears all the set positions and sizes of the tables on the dashboard
    """
    default_tables = {
                        "Counts": {
                            "sizex": 10,
                            "sizey": 13,
                            "row": 1,
                            "col": 1
                        },
                        "Top Backdoors": {
                            "sizex": 10,
                            "sizey": 8,
                            "row": 1,
                            "col": 10
                        },
                        "Top Campaigns": {
                            "sizex": 25,
                            "sizey": 8,
                            "row": 1,
                            "col": 20
                        },
                        "Recent Indicators": {
                            "sizex": 50,
                            "sizey": 8,
                            "row": 15,
                            "col": 1
                        },
                        "Recent Emails": {
                            "sizex": 50,
                            "sizey": 8,
                            "row": 23,
                            "col": 1
                        },
                        "Recent Samples": {
                            "sizex": 50,
                            "sizey": 8,
                            "row": 31,
                            "col": 1
                        },
                      }
    try:
        for search in SavedSearch.objects(dashboard=dashId):
            if search.isDefaultOnDashboard:
                tempDict = default_tables[search.name]
                search.sizex = tempDict["sizex"]
                search.sizey = tempDict["sizey"]
                search.row = tempDict["row"]
                search.col = tempDict["col"]
                search.save()
            else:
                search.update(unset__col=1,unset__row=1,unset__sizex=1)
    except Exception as e:
        print e
        return {'success': False, 
                'message': "An unexpected error occurred while resetting dash. Please refresh and try again"}
    return {'success': True, 
            'message': "Dashboard Reset"}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:59,代码来源:handlers.py

示例8: add_existing_search_to_dashboard

def add_existing_search_to_dashboard(id, dashboard, user):
    search = SavedSearch.objects(id = id).first()
    if not search:
        return {"success":False,
                "message":"Could not find search. Please refresh and try again."}
    else:
        search = cloneSavedSearch(search, dashboard)
        return {"success":True,
                "message": search.name+" has been added to your dashboard.",
                "newSearch": createTableObject(user, table=search)}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:10,代码来源:handlers.py

示例9: toggleTableVisibility

def toggleTableVisibility(id, isVisible):
    """
    Changes the tables visibility to either pinned or hidden.
    """
    table = SavedSearch.objects(id=id).first()
    if not table:
        return {'success': False,
                'message': "Error finding table. Please refresh and try again"}
    message = table.name+ " is now "
    if isVisible:
        message += "visible"
    else:
        message += "hidden"
    table.isPinned = isVisible
    table.save()
    return {'success': True,'message': message}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:16,代码来源:handlers.py

示例10: 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 Backdoors", "Top Campaigns","Recent Indicators",
                  "Recent Emails", "Recent Samples"]:
            savedSearch = SavedSearch()
            savedSearch.name = title
            savedSearch.dashboard = defaultDashboard.id
            savedSearch.isDefaultOnDashboard = True
            savedSearch.tableColumns = getColumnsForTable(title)
            savedSearch.save()
        print "Default Dashboard Created."
    else:
        print "Default Dashboard already exists."
开发者ID:Lin0x,项目名称:crits,代码行数:22,代码来源:create_default_dashboard.py

示例11: cloneDashboard

def cloneDashboard(userId, dashboard, cloneSearches=False, skip=None):
    """
    Clones a public dashboard to a user-modified version of if.
    cloneSearches will clone all affiliated searches with the dashboard.
    Skip will skip a specific table if cloning searches
    """
    if Dashboard.objects(analystId=userId,name=dashboard.name):
        return
    newDash = Dashboard()
    newDash.name = dashboard.name
    newDash.theme = dashboard.theme
    newDash.analystId = userId
    newDash.parent = dashboard.id
    newDash.save()
    if cloneSearches:
        for search in SavedSearch.objects(dashboard = dashboard.id):
            if skip != str(search.id):
                cloneSavedSearch(search, newDash.id)
    return newDash
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:19,代码来源:handlers.py

示例12: get_saved_searches_list

def get_saved_searches_list(user):
    """
    Returns all user dashboards and their affiliated saved searches.
    """
    dashboards = []
    for dash in Dashboard.objects(analystId=user.id):
        tables = []
        for table in SavedSearch.objects(dashboard=dash.id):
            if table.isDefaultOnDashboard:
                table.searchTerm = ""
                table.objType = ""
            tables.append(table)
        tempDash = {
                    "name":dash.name,
                   "id": dash.id,
                   "theme":dash.theme,
                   'isPublic':dash.isPublic,
                   "tables": tables
                }
        if dash.parent:
            tempDash['isModified'] = True
        dashboards.append(tempDash)
            
    return {"dashboards": dashboards}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:24,代码来源:handlers.py

示例13: delete_table

def delete_table(id, tableHeight=0):
    """
    Deletes a table from the db. Only can be called via the saved_search.html
    """
    try:
        savedSearch = SavedSearch.objects(id=id).first()
        #if savedSearch.top > -1 and (not savedSearch.width or savedSearch.width>=97):
        #    SavedSearch.objects(dashboard=savedSearch.dashId,top__gt=savedSearch.top).update(dec__top=tableHeight)
        tableName = savedSearch.name
        if savedSearch.isDefaultOnDashboard:
            savedSearch.left = -1
            savedSearch.top = -1
            savedSearch.width = 0
            savedSearch.isPinned = False
            savedSearch.save()
        else:
            dashId = savedSearch.dashboard
            savedSearch.delete()
            deleteDashboardIfEmpty(dashId)
    except Exception as e:
        print e
        return {'success': False,
                'message': "Saved search cannot be found. Please refresh and try again."}
    return {'success': True,'message': tableName+" deleted successfully!"}
开发者ID:Lin0x,项目名称:crits,代码行数:24,代码来源:handlers.py

示例14: deleteDashboardIfEmpty

def deleteDashboardIfEmpty(dashId):
    """
    Checks if a dashboard has saved searches. Deletes it if it doesn't.
    """
    if not SavedSearch.objects(dashboard=dashId):
        Dashboard.objects(id=dashId).delete()
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:6,代码来源:handlers.py

示例15: save_data

def save_data(userId, columns, tableName, searchTerm="", objType="", sortBy=None, 
              tableId=None, isDefaultOnDashboard=False, maxRows=0,
              dashboard=None, clone=False, row=0, grid_col=0, sizex=0,
              sizey=0):
    """
    Saves the customized table in the dashboard. Called by save_search and
    save_new_dashboard via ajax in views.py.
    """
    try:
        if searchTerm:
            searchTerm = HTMLParser.HTMLParser().unescape(searchTerm)
        #if user is editing a table
        if tableId :
            newSavedSearch = SavedSearch.objects(id=tableId).first()
            if not newSavedSearch:
                raise Exception("Cannot find Table")
            elif clone:
                clonedSavedSearch = cloneSavedSearch(newSavedSearch, dashboard.id)
        else:
            newSavedSearch = SavedSearch()
        cols = []
        for col in columns:
            if "field" not in col or "caption" not in col:
                continue
            cols.append(col)
        if not cols:
            raise("There are no columns to save")
        newSavedSearch.tableColumns = cols
        newSavedSearch.name = tableName
        oldDashId = None
        if dashboard and newSavedSearch.dashboard != dashboard.id:
            newSavedSearch.dashboard= dashboard.id
        #if it is not a deault dashboard table, it must have a searchterm and objtype
        if searchTerm:
            newSavedSearch.searchTerm = searchTerm
        if objType:
            newSavedSearch.objType = objType
        #this is to identify the default tables on every user dashboard
        newSavedSearch.isDefaultOnDashboard = isDefaultOnDashboard
        if sortBy:
            newSavedSearch.sortBy = sortBy
        if sizex:
            newSavedSearch.sizex = sizex
        elif not newSavedSearch.sizex:
            newSavedSearch.sizex = 50
        if sizey:
            newSavedSearch.sizey = sizey
        elif maxRows and maxRows != newSavedSearch.maxRows:
            newSavedSearch.sizey = int(maxRows)+1
        elif not newSavedSearch.sizey:
            newSavedSearch.sizey = 7
        if row:
            newSavedSearch.row = row
        elif not newSavedSearch.row:
            newSavedSearch.row = 1
        if grid_col:
            newSavedSearch.col = grid_col
        elif not newSavedSearch.col:
            newSavedSearch.col = 1
        if maxRows:
            newSavedSearch.maxRows = maxRows;
        newSavedSearch.save()
        #if the old dashboard is empty, delete it
        if oldDashId:
            deleteDashboardIfEmpty(oldDashId)
    except Exception as e:
        print "ERROR: "
        print e
        return {'success': False,
                'message': "An unexpected error occurred while saving table. Please refresh and try again"}
    return {'success': True,'message': tableName+" Saved Successfully!"}
开发者ID:Abdullah-Mughal,项目名称:crits,代码行数:71,代码来源:handlers.py


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