本文整理汇总了Python中crits.dashboards.dashboard.Dashboard.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Dashboard.objects方法的具体用法?Python Dashboard.objects怎么用?Python Dashboard.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crits.dashboards.dashboard.Dashboard
的用法示例。
在下文中一共展示了Dashboard.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateChildren
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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)
示例2: renameDashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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
示例3: ignore_parent
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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")
示例4: get_dashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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}
示例5: changeTheme
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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."
示例6: delete_table
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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}
示例7: create_dashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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."
示例8: deleteDashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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
示例9: generate_search_for_saved_table
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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
示例10: save_search
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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)
示例11: setDefaultDashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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
示例12: createNewDashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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
示例13: save_new_dashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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!"}
)
示例14: save_new_dashboard
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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!")
示例15: getDashboardsForUser
# 需要导入模块: from crits.dashboards.dashboard import Dashboard [as 别名]
# 或者: from crits.dashboards.dashboard.Dashboard import objects [as 别名]
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