本文整理汇总了Python中sentry.utils.get_filters函数的典型用法代码示例。如果您正苦于以下问题:Python get_filters函数的具体用法?Python get_filters怎么用?Python get_filters使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_filters函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index():
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
try:
page = int(request.args.get('p', 1))
except (TypeError, ValueError):
page = 1
query = request.args.get('content')
is_search = query
if is_search:
if uuid_re.match(query):
# Forward to message if it exists
try:
message = Event.objects.get(query)
except Message.DoesNotExist:
pass
else:
return redirect(message.get_absolute_url())
message_list = self.get_search_query_set(query)
else:
message_list = Group.objects.all()
sort = request.args.get('sort')
# if sort == 'date':
# message_list = message_list.order_by('-last_seen')
# elif sort == 'new':
# message_list = message_list.order_by('-first_seen')
# else:
# sort = 'priority'
# if not is_search:
# message_list = message_list.order_by('-score', '-last_seen')
filters = []
any_filter = False
# for filter_ in filters:
# if not filter_.is_set():
# continue
# any_filter = True
# message_list = filter_.get_query_set(message_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_template('sentry/index.html', **{
'has_realtime': has_realtime,
'message_list': message_list,
'today': today,
'query': query,
'sort': sort,
'any_filter': any_filter,
'request': request,
'filters': filters,
})
示例2: register_indexes
def register_indexes():
"""
Grabs all required indexes from filters and registers them.
"""
logger = logging.getLogger("sentry.setup")
for filter_ in get_filters():
if filter_.column.startswith("data__"):
MessageIndex.objects.register_index(filter_.column, index_to="group")
logger.debug("Registered index for for %s" % filter_.column)
示例3: view_slice
def view_slice(slug):
slice_ = slices.get(slug)
filters = []
for filter_ in get_filters(slug):
filters.append(filter_(request))
try:
page = int(request.args.get('p', 1))
except (TypeError, ValueError):
page = 1
query = request.args.get('content')
is_search = query
# TODO: this needs to pull in the event list for this slice
event_list = Group.objects.all()
sort = request.args.get('sort')
if sort == 'date':
event_list = event_list.order_by('-last_seen')
elif sort == 'new':
event_list = event_list.order_by('-first_seen')
elif sort == 'count':
event_list = event_list.order_by('-count')
else:
sort = 'priority'
event_list = event_list.order_by('-score')
filters = []
any_filter = False
# for filter_ in filters:
# if not filter_.is_set():
# continue
# any_filter = True
# event_list = filter_.get_query_set(event_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_template('sentry/slice.html', **{
'slice_name': slice_['name'],
'has_realtime': has_realtime,
'event_list': event_list,
'today': today,
'query': query,
'sort': sort,
'any_filter': any_filter,
'request': request,
'filters': filters,
})
示例4: index
def index(request):
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
try:
page = int(request.GET.get("p", 1))
except (TypeError, ValueError):
page = 1
message_list = GroupedMessage.objects.all()
sort = request.GET.get("sort")
if sort == "date":
message_list = message_list.order_by("-last_seen")
elif sort == "new":
message_list = message_list.order_by("-first_seen")
elif sort == "freq":
message_list = message_list.order_by("-times_seen")
else:
sort = "priority"
message_list = message_list.order_by("-score", "-last_seen")
# Filters only apply if we're not searching
any_filter = False
for filter_ in filters:
if not filter_.is_set():
continue
any_filter = True
message_list = filter_.get_query_set(message_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_to_response(
"sentry/index.html",
{
"has_realtime": has_realtime,
"message_list": message_list,
"today": today,
"sort": sort,
"any_filter": any_filter,
"request": request,
"filters": filters,
},
)
示例5: index
def index(request):
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
try:
page = int(request.GET.get('p', 1))
except (TypeError, ValueError):
page = 1
message_list = GroupedMessage.objects.all()
sort = request.GET.get('sort')
if sort == 'date':
message_list = message_list.order_by('-last_seen')
elif sort == 'new':
message_list = message_list.order_by('-first_seen')
elif sort == 'freq':
message_list = message_list.order_by('-times_seen')
else:
sort = 'priority'
message_list = message_list.order_by('-score', '-last_seen')
# Filters only apply if we're not searching
any_filter = False
for filter_ in filters:
if not filter_.is_set():
continue
any_filter = True
message_list = filter_.get_query_set(message_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_to_response('sentry/index.html', {
'has_realtime': has_realtime,
'message_list': message_list,
'today': today,
'sort': sort,
'any_filter': any_filter,
'request': request,
'filters': filters,
'throughput': ThrottleSwitch.get_throughput_per_second(),
'throttling': ThrottleSwitch.is_throttled()
})
示例6: poll
def poll(request):
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
message_list = GroupedMessage.objects.all()
sort = request.GET.get("sort")
if sort == "date":
message_list = message_list.order_by("-last_seen")
elif sort == "new":
message_list = message_list.order_by("-first_seen")
elif sort == "freq":
message_list = message_list.order_by("-times_seen")
else:
sort = "priority"
message_list = message_list.order_by("-score", "-last_seen")
for filter_ in filters:
if not filter_.is_set():
continue
message_list = filter_.get_query_set(message_list)
data = [
(
m.pk,
{
"html": render_to_string(
"sentry/partial/_group.html", {"group": m, "priority": p, "request": request}
).strip(),
"title": m.view or m.message_top(),
"message": m.error(),
"level": m.get_level_display(),
"logger": m.logger,
"count": m.times_seen,
"priority": p,
},
)
for m, p in with_priority(message_list[0:15])
]
response = HttpResponse(json.dumps(data))
response["Content-Type"] = "application/json"
return response
示例7: index
def index():
filter_list = list(get_filters())
try:
page = int(request.args.get("p", 1))
except (TypeError, ValueError):
page = 1
event_list = Group.objects.all()
sort = request.args.get("sort")
if sort == "date":
event_list = event_list.order_by("-last_seen")
elif sort == "new":
event_list = event_list.order_by("-first_seen")
elif sort == "count":
event_list = event_list.order_by("-count")
else:
sort = "priority"
event_list = event_list.order_by("-score")
any_filter = False
# for filter_ in filters:
# if not filter_.is_set():
# continue
# any_filter = True
# event_list = filter_.get_query_set(event_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_template(
"sentry/index.html",
**{
"has_realtime": has_realtime,
"event_list": event_list,
"today": today,
"sort": sort,
"any_filter": any_filter,
"request": request,
"filter_list": filter_list,
}
)
示例8: poll
def poll(request):
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
message_list = GroupedMessage.objects.all()
sort = request.GET.get('sort')
if sort == 'date':
message_list = message_list.order_by('-last_seen')
elif sort == 'new':
message_list = message_list.order_by('-first_seen')
elif sort == 'freq':
message_list = message_list.order_by('-times_seen')
else:
sort = 'priority'
message_list = message_list.order_by('-score', '-last_seen')
for filter_ in filters:
if not filter_.is_set():
continue
message_list = filter_.get_query_set(message_list)
data = [
(m.pk, {
'html': render_to_string('sentry/partial/_group.html', {
'group': m,
'priority': p,
'request': request,
}).strip(),
'title': m.view or m.message_top(),
'message': m.error(),
'level': m.get_level_display(),
'logger': m.logger,
'count': m.times_seen,
'priority': p,
}) for m, p in with_priority(message_list[0:15])]
response = HttpResponse(json.dumps(data))
response['Content-Type'] = 'application/json'
return response
示例9: index
def index():
filter_list = list(get_filters())
try:
page = int(request.args.get('p', 1))
except (TypeError, ValueError):
page = 1
event_list = Group.objects.all()
sort = request.args.get('sort')
if sort == 'date':
event_list = event_list.order_by('-last_seen')
elif sort == 'new':
event_list = event_list.order_by('-first_seen')
elif sort == 'count':
event_list = event_list.order_by('-count')
else:
sort = 'priority'
event_list = event_list.order_by('-score')
any_filter = False
# for filter_ in filters:
# if not filter_.is_set():
# continue
# any_filter = True
# event_list = filter_.get_query_set(event_list)
today = datetime.datetime.now()
has_realtime = page == 1
return render_template('sentry/index.html', **{
'has_realtime': has_realtime,
'event_list': event_list,
'today': today,
'sort': sort,
'any_filter': any_filter,
'request': request,
'filter_list': filter_list,
})
示例10: ajax_handler
def ajax_handler():
op = request.form.get('op')
if op == 'poll':
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
query = request.args.get('content')
is_search = query
if is_search:
message_list = self.get_search_query_set(query)
else:
message_list = GroupedMessage.objects.extra(
select={
'score': GroupedMessage.get_score_clause(),
}
)
if query:
# You really shouldnt be doing this
message_list = message_list.filter(
Q(view__icontains=query) \
| Q(message__icontains=query) \
| Q(traceback__icontains=query)
)
sort = request.args.get('sort')
if sort == 'date':
message_list = message_list.order_by('-last_seen')
elif sort == 'new':
message_list = message_list.order_by('-first_seen')
else:
sort = 'priority'
if not is_search:
message_list = message_list.order_by('-score', '-last_seen')
for filter_ in filters:
if not filter_.is_set():
continue
message_list = filter_.get_query_set(message_list)
data = [
(m.pk, {
'html': self.render_to_string('sentry/partial/_group.html', {
'group': m,
'priority': p,
'request': request,
}, request),
'count': m.times_seen,
'priority': p,
}) for m, p in with_priority(message_list[0:15])]
elif op == 'resolve':
gid = request.REQUEST.get('gid')
if not gid:
abort(403)
try:
group = GroupedMessage.objects.get(pk=gid)
except GroupedMessage.DoesNotExist:
abort(403)
GroupedMessage.objects.filter(pk=group.pk).update(status=1)
group.status = 1
if not request.is_ajax():
return redirect(request.environ['HTTP_REFERER'])
data = [
(m.pk, {
'html': self.render_to_string('sentry/partial/_group.html', {
'group': m,
'request': request,
}, request),
'count': m.times_seen,
}) for m in [group]]
else:
abort(400)
return Response(simplejson.dumps(data), mimetype='application/json')
示例11: process
def process(self, **kwargs):
"Processes the message before passing it on to the server"
from sentry.utils import get_filters
if kwargs.get('data'):
# Ensure we're not changing the original data which was passed
# to Sentry
kwargs['data'] = kwargs['data'].copy()
else:
kwargs['data'] = {}
if '__sentry__' not in kwargs['data']:
kwargs['data']['__sentry__'] = {}
request = kwargs.pop('request', None)
if isinstance(request, HttpRequest):
try:
post_data = not request.POST and request.raw_post_data or request.POST
except:
post_data = request.POST
kwargs['data'].update(dict(
META=request.META,
POST=post_data,
GET=request.GET,
COOKIES=request.COOKIES,
))
if hasattr(request, 'user'):
if request.user.is_authenticated():
user_info = {
'is_authenticated': True,
'id': request.user.pk,
'username': request.user.username,
'email': request.user.email,
}
else:
user_info = {
'is_authenticated': False,
}
kwargs['data']['__sentry__']['user'] = user_info
if not kwargs.get('url'):
kwargs['url'] = request.build_absolute_uri()
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', settings.NAME)
versions = get_versions()
kwargs['data']['__sentry__']['versions'] = versions
# Shorten lists/strings
for k, v in kwargs['data'].iteritems():
if k == '__sentry__':
continue
kwargs['data'][k] = shorten(v)
# if we've passed frames, lets try to fetch the culprit
if not kwargs.get('view') and kwargs['data']['__sentry__'].get('frames'):
# This should be cached
modules = get_installed_apps()
if settings.INCLUDE_PATHS:
modules = set(list(modules) + settings.INCLUDE_PATHS)
def contains(iterator, value):
for k in iterator:
if value.startswith(k):
return True
return False
# We iterate through each frame looking for an app in INSTALLED_APPS
# When one is found, we mark it as last "best guess" (best_guess) and then
# check it against SENTRY_EXCLUDE_PATHS. If it isnt listed, then we
# use this option. If nothing is found, we use the "best guess".
best_guess = None
view = None
for frame in kwargs['data']['__sentry__']['frames']:
try:
view = '.'.join([frame['module'], frame['function']])
except:
continue
if contains(modules, view):
if not (contains(settings.EXCLUDE_PATHS, view) and best_guess):
best_guess = view
elif best_guess:
break
if best_guess:
view = best_guess
if view:
kwargs['view'] = view
# try to fetch the current version
if kwargs.get('view'):
# get list of modules from right to left
parts = kwargs['view'].split('.')
module_list = ['.'.join(parts[:idx]) for idx in xrange(1, len(parts) + 1)][::-1]
version = None
module = None
#.........这里部分代码省略.........
示例12: ajax_handler
def ajax_handler(request):
op = request.REQUEST.get('op')
if op == 'notification':
return render_to_response('sentry/partial/_notification.html', request.GET)
elif op == 'poll':
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
message_list = GroupedMessage.objects.all()
sort = request.GET.get('sort')
if sort == 'date':
message_list = message_list.order_by('-last_seen')
elif sort == 'new':
message_list = message_list.order_by('-first_seen')
elif sort == 'freq':
message_list = message_list.order_by('-times_seen')
else:
sort = 'priority'
message_list = message_list.order_by('-score', '-last_seen')
for filter_ in filters:
if not filter_.is_set():
continue
message_list = filter_.get_query_set(message_list)
data = [
(m.pk, {
'html': render_to_string('sentry/partial/_group.html', {
'group': m,
'priority': p,
'request': request,
}).strip(),
'title': m.view or m.message_top(),
'message': m.error(),
'level': m.get_level_display(),
'logger': m.logger,
'count': m.times_seen,
'priority': p,
}) for m, p in with_priority(message_list[0:15])]
elif op == 'resolve':
gid = request.REQUEST.get('gid')
if not gid:
return HttpResponseForbidden()
try:
group = GroupedMessage.objects.get(pk=gid)
except GroupedMessage.DoesNotExist:
return HttpResponseForbidden()
GroupedMessage.objects.filter(pk=group.pk).update(status=1)
group.status = 1
if not request.is_ajax():
return HttpResponseRedirect(request.META.get('HTTP_REFERER') or reverse('sentry'))
data = [
(m.pk, {
'html': render_to_string('sentry/partial/_group.html', {
'group': m,
'request': request,
}).strip(),
'count': m.times_seen,
}) for m in [group]]
else:
return HttpResponseBadRequest()
response = HttpResponse(simplejson.dumps(data))
response['Content-Type'] = 'application/json'
return response
示例13: process
def process(self, **kwargs):
"Processes the message before passing it on to the server"
from sentry.utils import get_filters
if kwargs.get("data"):
# Ensure we're not changing the original data which was passed
# to Sentry
kwargs["data"] = kwargs["data"].copy()
else:
kwargs["data"] = {}
if "__sentry__" not in kwargs["data"]:
kwargs["data"]["__sentry__"] = {}
request = kwargs.pop("request", None)
if isinstance(request, HttpRequest):
if not request.POST and request.body:
post_data = request.body
else:
post_data = request.POST
kwargs["data"].update(dict(META=request.META, POST=post_data, GET=request.GET, COOKIES=request.COOKIES))
if hasattr(request, "user"):
if request.user.is_authenticated():
user_info = {
"is_authenticated": True,
"id": request.user.pk,
"username": request.user.username,
"email": request.user.email,
}
else:
user_info = {"is_authenticated": False}
kwargs["data"]["__sentry__"]["user"] = user_info
if not kwargs.get("url"):
kwargs["url"] = request.build_absolute_uri()
kwargs.setdefault("level", logging.ERROR)
kwargs.setdefault("server_name", settings.NAME)
versions = get_versions()
kwargs["data"]["__sentry__"]["versions"] = versions
# Shorten lists/strings
for k, v in kwargs["data"].iteritems():
if k == "__sentry__":
continue
kwargs["data"][k] = shorten(v)
# if we've passed frames, lets try to fetch the culprit
if not kwargs.get("view") and kwargs["data"]["__sentry__"].get("frames"):
# This should be cached
modules = get_installed_apps()
if settings.INCLUDE_PATHS:
modules = set(list(modules) + settings.INCLUDE_PATHS)
def contains(iterator, value):
for k in iterator:
if value.startswith(k):
return True
return False
# We iterate through each frame looking for an app in INSTALLED_APPS
# When one is found, we mark it as last "best guess" (best_guess) and then
# check it against SENTRY_EXCLUDE_PATHS. If it isnt listed, then we
# use this option. If nothing is found, we use the "best guess".
best_guess = None
view = None
for frame in kwargs["data"]["__sentry__"]["frames"]:
try:
view = ".".join([frame["module"], frame["function"]])
except:
continue
if contains(modules, view):
if not (contains(settings.EXCLUDE_PATHS, view) and best_guess):
best_guess = view
elif best_guess:
break
if best_guess:
view = best_guess
if view:
kwargs["view"] = view
# try to fetch the current version
if kwargs.get("view"):
# get list of modules from right to left
parts = kwargs["view"].split(".")
module_list = [".".join(parts[:idx]) for idx in xrange(1, len(parts) + 1)][::-1]
version = None
module = None
for m in module_list:
if m in versions:
module = m
version = versions[m]
# store our "best guess" for application version
if version:
#.........这里部分代码省略.........
示例14: ajax_handler
def ajax_handler():
op = request.form.get("op")
if op == "poll":
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
event_list = Group.objects
sort = request.args.get("sort")
if sort == "date":
event_list = event_list.order_by("-last_seen")
elif sort == "new":
event_list = event_list.order_by("-first_seen")
elif sort == "count":
event_list = event_list.order_by("-count")
else:
sort = "priority"
event_list = event_list.order_by("-score")
# for filter_ in filters:
# if not filter_.is_set():
# continue
# event_list = filter_.get_query_set(event_list)
data = [
(
m.pk,
{
"html": render_template(
"sentry/partial/group.html", **{"group": m, "priority": p, "request": request}
),
"count": m.times_seen,
"priority": p,
},
)
for m, p in with_priority(event_list[0:15])
]
elif op == "resolve":
gid = request.REQUEST.get("gid")
if not gid:
abort(403)
try:
group = Group.objects.get(pk=gid)
except Group.DoesNotExist:
abort(403)
group.update(status=1)
if not request.is_ajax():
return redirect(request.environ["HTTP_REFERER"])
data = [
(
m.pk,
{
"html": render_template("sentry/partial/group.html", **{"group": m, "request": request}),
"count": m.times_seen,
},
)
for m in [group]
]
else:
abort(400)
return Response(simplejson.dumps(data), mimetype="application/json")
示例15: ajax_handler
def ajax_handler():
op = request.form.get('op')
if op == 'poll':
filters = []
for filter_ in get_filters():
filters.append(filter_(request))
event_list = Group.objects
sort = request.args.get('sort')
if sort == 'date':
event_list = event_list.order_by('-last_seen')
elif sort == 'new':
event_list = event_list.order_by('-first_seen')
elif sort == 'count':
event_list = event_list.order_by('-count')
else:
sort = 'priority'
event_list = event_list.order_by('-score')
# for filter_ in filters:
# if not filter_.is_set():
# continue
# event_list = filter_.get_query_set(event_list)
data = [
(m.pk, {
'html': render_template('sentry/partial/group.html', **{
'group': m,
'priority': p,
'request': request,
}),
'count': m.times_seen,
'priority': p,
}) for m, p in with_priority(event_list[0:15])]
elif op == 'resolve':
gid = request.REQUEST.get('gid')
if not gid:
abort(403)
try:
group = Group.objects.get(pk=gid)
except Group.DoesNotExist:
abort(403)
group.update(status=1)
if not request.is_ajax():
return redirect(request.environ['HTTP_REFERER'])
data = [
(m.pk, {
'html': render_template('sentry/partial/group.html', **{
'group': m,
'request': request,
}),
'count': m.times_seen,
}) for m in [group]]
else:
abort(400)
return Response(simplejson.dumps(data), mimetype='application/json')