本文整理汇总了Python中sentry.db.models.query.create_or_update函数的典型用法代码示例。如果您正苦于以下问题:Python create_or_update函数的具体用法?Python create_or_update怎么用?Python create_or_update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_or_update函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set
def set(self, key, value):
"""
Set the value for an option. If the cache is unavailable the action will
still suceeed.
>>> from sentry import options
>>> options.set('option', 'value')
"""
opt = self.lookup_key(key)
# If an option isn't able to exist in the store, we can't set it at runtime
assert not (opt.flags & self.FLAG_NOSTORE), '%r cannot be changed at runtime' % key
# Enforce immutability on key
assert not (opt.flags & self.FLAG_IMMUTABLE), '%r cannot be changed at runtime' % key
if not isinstance(value, opt.type):
raise TypeError('got %r, expected %r' % (_type(value), opt.type))
create_or_update(
model=Option,
key=key,
values={
'value': value,
'last_updated': timezone.now(),
}
)
try:
self.update_cached_value(opt.cache_key, value)
return True
except Exception:
self.logger.warn(CACHE_UPDATE_ERR, key, exc_info=True)
return False
开发者ID:cloudrifles,项目名称:sentry,代码行数:33,代码来源:manager.py
示例2: set_store
def set_store(self, key, value):
create_or_update(
model=self.model,
key=key.name,
values={
'value': value,
'last_updated': timezone.now(),
}
)
开发者ID:daevaorn,项目名称:sentry,代码行数:9,代码来源:store.py
示例3: set
def set(self, key, value):
"""
Set the value for an option. If the cache is unavailable the action will
still suceeed.
>>> from sentry import options
>>> options.set('option', 'value')
"""
create_or_update(
model=Option,
key=key,
values={
'value': value,
'last_updated': timezone.now(),
}
)
try:
self.update_cached_value(key, value)
except Exception:
self.logger.warn(CACHE_UPDATE_ERR, key, exc_info=True)
开发者ID:noah-lee,项目名称:sentry,代码行数:21,代码来源:manager.py
示例4: put
#.........这里部分代码省略.........
GroupResolution.objects.filter(
group__in=group_ids,
).delete()
if new_status == GroupStatus.IGNORED:
metrics.incr('group.ignored', skip_internal=True)
ignore_duration = (
statusDetails.pop('ignoreDuration', None) or
statusDetails.pop('snoozeDuration', None)
) or None
ignore_count = statusDetails.pop(
'ignoreCount', None) or None
ignore_window = statusDetails.pop(
'ignoreWindow', None) or None
ignore_user_count = statusDetails.pop(
'ignoreUserCount', None) or None
ignore_user_window = statusDetails.pop(
'ignoreUserWindow', None) or None
if ignore_duration or ignore_count or ignore_user_count:
if ignore_duration:
ignore_until = timezone.now() + timedelta(
minutes=ignore_duration,
)
else:
ignore_until = None
for group in group_list:
state = {}
if ignore_count and not ignore_window:
state['times_seen'] = group.times_seen
if ignore_user_count and not ignore_user_window:
state['users_seen'] = group.count_users_seen()
GroupSnooze.objects.create_or_update(
group=group,
values={
'until':
ignore_until,
'count':
ignore_count,
'window':
ignore_window,
'user_count':
ignore_user_count,
'user_window':
ignore_user_window,
'state':
state,
'actor_id':
request.user.id if request.user.is_authenticated() else None,
}
)
result['statusDetails'] = {
'ignoreCount': ignore_count,
'ignoreUntil': ignore_until,
'ignoreUserCount': ignore_user_count,
'ignoreUserWindow': ignore_user_window,
'ignoreWindow': ignore_window,
'actor': serialize(extract_lazy_object(request.user), request.user),
}
else:
GroupSnooze.objects.filter(
group__in=group_ids,
).delete()
ignore_until = None
result['statusDetails'] = {}
开发者ID:Kayle009,项目名称:sentry,代码行数:67,代码来源:project_group_index.py
示例5: put
def put(self, request, project_id):
"""
Bulk mutate a list of aggregates
Bulk mutate various attributes on aggregates.
{method} {path}?id=1&id=2&id=3
{{
"status": "resolved",
"isBookmarked": true
}}
- For non-status updates, only queries by 'id' are accepted.
- For status updates, the 'id' parameter may be omitted for a batch
"update all" query.
Attributes:
- status: resolved, unresolved, muted
- isBookmarked: true, false
- merge: true, false
If any ids are out of scope this operation will succeed without any data
mutation.
"""
project = Project.objects.get_from_cache(
id=project_id,
)
assert_perm(project, request.user, request.auth)
group_ids = request.GET.getlist('id')
if group_ids:
group_list = Group.objects.filter(project=project, id__in=group_ids)
# filter down group ids to only valid matches
group_ids = [g.id for g in group_list]
if not group_ids:
return Response(status=204)
else:
group_list = None
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(status=400)
result = serializer.object
# validate that we've passed a selector for non-status bulk operations
if not group_ids and result.get('isBookmarked') is not None:
return Response(status=400)
if group_ids:
filters = Q(id__in=group_ids)
else:
filters = Q(project=project)
if result.get('status') == 'resolved':
now = timezone.now()
happened = Group.objects.filter(filters).exclude(
status=GroupStatus.RESOLVED,
).update(
status=GroupStatus.RESOLVED,
resolved_at=now,
)
if group_list and happened:
for group in group_list:
group.status = GroupStatus.RESOLVED
group.resolved_at = now
create_or_update(
Activity,
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=request.user,
)
elif result.get('status'):
new_status = STATUS_CHOICES[result['status']]
happened = Group.objects.filter(filters).exclude(
status=new_status,
).update(
status=new_status,
)
if group_list and happened:
for group in group_list:
group.status = new_status
if result.get('isBookmarked'):
for group in group_list:
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
user=request.user,
)
elif result.get('isBookmarked') is False:
GroupBookmark.objects.filter(
group__in=group_ids,
#.........这里部分代码省略.........
开发者ID:BlueMoebius,项目名称:sentry,代码行数:101,代码来源:project_group_index.py
示例6: put
def put(self, request, group):
"""
Update an aggregate
Updates an individual aggregate's attributes.
{method} {path}
{{
"status": "resolved"
}}
Attributes:
- status: resolved, unresolved, muted
- hasSeen: true, false
- isBookmarked: true, false
- assignedTo: user
"""
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
result = serializer.object
# TODO(dcramer): we should allow assignment to anyone who has membership
# even if that membership is not SSO linked
if result.get('assignedTo') and not group.project.member_set.filter(user=result['assignedTo']).exists():
return Response({'detail': 'Cannot assign to non-team member'}, status=400)
if result.get('status') == 'resolved':
now = timezone.now()
group.resolved_at = now
group.status = GroupStatus.RESOLVED
happened = Group.objects.filter(
id=group.id,
).exclude(status=GroupStatus.RESOLVED).update(
status=GroupStatus.RESOLVED,
resolved_at=now,
)
if happened:
create_or_update(
Activity,
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=request.user,
)
elif result.get('status'):
group.status = STATUS_CHOICES[result['status']]
group.save()
if result.get('hasSeen'):
instance, created = create_or_update(
GroupSeen,
group=group,
user=request.user,
project=group.project,
values={
'last_seen': timezone.now(),
}
)
elif result.get('hasSeen') is False:
GroupSeen.objects.filter(
group=group,
user=request.user,
).delete()
if result.get('isBookmarked'):
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
user=request.user,
)
elif result.get('isBookmarked') is False:
GroupBookmark.objects.filter(
group=group,
user=request.user,
).delete()
if 'assignedTo' in result:
now = timezone.now()
if result['assignedTo']:
assignee, created = GroupAssignee.objects.get_or_create(
group=group,
defaults={
'project': group.project,
'user': result['assignedTo'],
'date_added': now,
}
)
if not created:
affected = GroupAssignee.objects.filter(
group=group,
).exclude(
#.........这里部分代码省略.........
开发者ID:CBEPX,项目名称:sentry,代码行数:101,代码来源:group_details.py
示例7: put
#.........这里部分代码省略.........
type=Activity.SET_RESOLVED,
user=acting_user,
)
# TODO(dcramer): we need a solution for activity rollups
# before sending notifications on bulk changes
if not is_bulk:
activity.send_notification()
result['statusDetails'] = {}
elif result.get('status'):
new_status = STATUS_CHOICES[result['status']]
happened = queryset.exclude(
status=new_status,
).update(
status=new_status,
)
GroupResolution.objects.filter(
group__in=group_ids,
).delete()
if new_status == GroupStatus.IGNORED:
ignore_duration = (
result.pop('ignoreDuration', None)
or result.pop('snoozeDuration', None)
)
if ignore_duration:
ignore_until = timezone.now() + timedelta(
minutes=ignore_duration,
)
for group in group_list:
GroupSnooze.objects.create_or_update(
group=group,
values={
'until': ignore_until,
}
)
result['statusDetails'] = {
'ignoreUntil': ignore_until,
}
else:
GroupSnooze.objects.filter(
group__in=group_ids,
).delete()
ignore_until = None
result['statusDetails'] = {}
else:
result['statusDetails'] = {}
if group_list and happened:
if new_status == GroupStatus.UNRESOLVED:
activity_type = Activity.SET_UNRESOLVED
activity_data = {}
elif new_status == GroupStatus.IGNORED:
activity_type = Activity.SET_IGNORED
activity_data = {
'ignoreUntil': ignore_until,
'ignoreDuration': ignore_duration,
}
for group in group_list:
group.status = new_status
activity = Activity.objects.create(
开发者ID:alexm92,项目名称:sentry,代码行数:67,代码来源:project_group_index.py
示例8: put
def put(self, request, group):
"""
Update an Issue
```````````````
Updates an individual issues's attributes. Only the attributes
submitted are modified.
:pparam string issue_id: the ID of the group to retrieve.
:param string status: the new status for the groups. Valid values
are ``"resolved"``, ``"unresolved"`` and
``"muted"``.
:param string assignedTo: the username of the user that should be
assigned to this issue.
:param boolean hasSeen: in case this API call is invoked with a user
context this allows changing of the flag
that indicates if the user has seen the
event.
:param boolean isBookmarked: in case this API call is invoked with a
user context this allows changing of
the bookmark flag.
:auth: required
"""
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
result = serializer.object
acting_user = request.user if request.user.is_authenticated() else None
# TODO(dcramer): we should allow assignment to anyone who has membership
# even if that membership is not SSO linked
if result.get('assignedTo') and not group.project.member_set.filter(user=result['assignedTo']).exists():
return Response({'detail': 'Cannot assign to non-team member'}, status=400)
if result.get('status') == 'resolved':
now = timezone.now()
group.resolved_at = now
group.status = GroupStatus.RESOLVED
happened = Group.objects.filter(
id=group.id,
).exclude(status=GroupStatus.RESOLVED).update(
status=GroupStatus.RESOLVED,
resolved_at=now,
)
if happened:
create_or_update(
Activity,
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=acting_user,
)
elif result.get('status'):
new_status = STATUS_CHOICES[result['status']]
if new_status == GroupStatus.MUTED:
if result.get('snoozeDuration'):
snooze_until = timezone.now() + timedelta(
minutes=int(result['snoozeDuration']),
)
GroupSnooze.objects.create_or_update(
group=group,
values={
'until': snooze_until,
}
)
result['snoozeUntil'] = snooze_until
else:
GroupSnooze.objects.filter(
group=group,
).delete()
result['snoozeUntil'] = None
group.update(status=new_status)
if result.get('hasSeen') and group.project.member_set.filter(user=request.user).exists():
instance, created = create_or_update(
GroupSeen,
group=group,
user=request.user,
project=group.project,
values={
'last_seen': timezone.now(),
}
)
elif result.get('hasSeen') is False:
GroupSeen.objects.filter(
group=group,
user=request.user,
).delete()
if result.get('isBookmarked'):
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
#.........这里部分代码省略.........
开发者ID:Akashguharoy,项目名称:sentry,代码行数:101,代码来源:group_details.py
示例9: put
#.........这里部分代码省略.........
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=request.user,
)
activity.send_notification()
elif result.get('status'):
new_status = STATUS_CHOICES[result['status']]
happened = Group.objects.filter(*filters).exclude(
status=new_status,
).update(
status=new_status,
)
if group_list and happened:
if new_status == GroupStatus.UNRESOLVED:
activity_type = Activity.SET_UNRESOLVED
elif new_status == GroupStatus.MUTED:
activity_type = Activity.SET_MUTED
for group in group_list:
group.status = new_status
activity = Activity.objects.create(
project=group.project,
group=group,
type=activity_type,
user=request.user,
)
activity.send_notification()
if result.get('hasSeen'):
for group in group_list:
instance, created = create_or_update(
GroupSeen,
group=group,
user=request.user,
project=group.project,
values={
'last_seen': timezone.now(),
}
)
elif result.get('hasSeen') is False:
GroupSeen.objects.filter(
group__in=group_ids,
user=request.user,
).delete()
if result.get('isBookmarked'):
for group in group_list:
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
user=request.user,
)
elif result.get('isBookmarked') is False:
GroupBookmark.objects.filter(
group__in=group_ids,
user=request.user,
).delete()
if result.get('isPublic'):
Group.objects.filter(
id__in=group_ids,
).update(is_public=True)
for group in group_list:
开发者ID:hyserver,项目名称:sentry,代码行数:67,代码来源:project_group_index.py
示例10: put
def put(self, request, group_id):
"""
Update an aggregate
Updates an individual aggregate's attributes.
{method} {path}
{{
"status": "resolved"
}}
Attributes:
- status: resolved, unresolved, muted
- isBookmarked: true, false
- assignedTo: user
"""
group = Group.objects.get(
id=group_id,
)
assert_perm(group, request.user, request.auth)
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
result = serializer.object
if result.get('assignedTo') and not group.project.has_access(result['assignedTo']):
return Response(status=400)
if result.get('status') == 'resolved':
now = timezone.now()
group.resolved_at = now
group.status = GroupStatus.RESOLVED
happened = Group.objects.filter(
id=group.id,
).exclude(status=GroupStatus.RESOLVED).update(
status=GroupStatus.RESOLVED,
resolved_at=now,
)
if happened:
create_or_update(
Activity,
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=request.user,
)
elif result.get('status'):
group.status = STATUS_CHOICES[result['status']]
group.save()
if result.get('isBookmarked'):
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
user=request.user,
)
elif result.get('isBookmarked') is False:
GroupBookmark.objects.filter(
group=group,
user=request.user,
).delete()
if 'assignedTo' in result:
now = timezone.now()
if result['assignedTo']:
assignee, created = GroupAssignee.objects.get_or_create(
group=group,
defaults={
'project': group.project,
'user': result['assignedTo'],
'date_added': now,
}
)
if not created:
affected = GroupAssignee.objects.filter(
group=group,
).exclude(
user=result['assignedTo'],
).update(
user=result['assignedTo'],
date_added=now
)
else:
affected = True
if affected:
create_or_update(
Activity,
project=group.project,
#.........这里部分代码省略.........
开发者ID:brettlangdon,项目名称:sentry,代码行数:101,代码来源:group_details.py
示例11: put
#.........这里部分代码省略.........
for group in group_list:
group.status = GroupStatus.RESOLVED
group.resolved_at = now
activity = Activity.objects.create(
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=acting_user,
)
activity.send_notification()
result['statusDetails'] = {}
elif result.get('status'):
new_status = STATUS_CHOICES[result['status']]
happened = Group.objects.filter(*filters).exclude(
status=new_status,
).update(
status=new_status,
)
GroupResolution.objects.filter(
group__in=Group.objects.filter(*filters),
).delete()
if new_status == GroupStatus.MUTED:
snooze_duration = result.pop('snoozeDuration', None)
if snooze_duration:
snooze_until = timezone.now() + timedelta(
minutes=snooze_duration,
)
for group in group_list:
GroupSnooze.objects.create_or_update(
group=group,
values={
'until': snooze_until,
}
)
result['statusDetails'] = {
'snoozeUntil': snooze_until,
}
else:
GroupSnooze.objects.filter(
group__in=group_list,
).delete()
snooze_until = None
result['statusDetails'] = {}
else:
result['statusDetails'] = {}
if group_list and happened:
if new_status == GroupStatus.UNRESOLVED:
activity_type = Activity.SET_UNRESOLVED
activity_data = {}
elif new_status == GroupStatus.MUTED:
activity_type = Activity.SET_MUTED
activity_data = {
'snoozeUntil': snooze_until,
'snoozeDuration': snooze_duration,
}
for group in group_list:
group.status = new_status
activity = Activity.objects.create(
project=group.project,
开发者ID:WilliamRen,项目名称:sentry,代码行数:67,代码来源:project_group_index.py
示例12: put
#.........这里部分代码省略.........
with transaction.atomic():
happened = queryset.exclude(
status=new_status,
).update(
status=new_status,
)
GroupResolution.objects.filter(
group__in=group_ids,
).delete()
if new_status == GroupStatus.IGNORED:
ignore_duration = (
statusDetails.pop('ignoreDuration', None)
or statusDetails.pop('snoozeDuration', None)
) or None
ignore_count = statusDetails.pop('ignoreCount', None) or None
ignore_window = statusDetails.pop('ignoreWindow', None) or None
ignore_user_count = statusDetails.pop('ignoreUserCount', None) or None
ignore_user_window = statusDetails.pop('ignoreUserWindow', None) or None
if ignore_duration or ignore_count or ignore_user_count:
if ignore_duration:
ignore_until = timezone.now() + timedelta(
minutes=ignore_duration,
)
else:
ignore_until = None
for group in group_list:
state = {}
if ignore_count and not ignore_window:
state['times_seen'] = group.times_seen
if ignore_user_count and not ignore_user_window:
state['users_seen'] = group.count_users_seen()
GroupSnooze.objects.create_or_update(
group=group,
values={
'until': ignore_until,
'count': ignore_count,
'window': ignore_window,
'user_count': ignore_user_count,
'user_window': ignore_user_window,
'state': state,
'actor_id': request.user.id if request.user.is_authenticated() else None,
}
)
result['statusDetails'] = {
'ignoreCount': ignore_count,
'ignoreUntil': ignore_until,
'ignoreUserCount': ignore_user_count,
'ignoreUserWindow': ignore_user_window,
'ignoreWindow': ignore_window,
'actor': serialize(extract_lazy_object(request.user), request.user),
}
else:
GroupSnooze.objects.filter(
group__in=group_ids,
).delete()
ignore_until = None
result['statusDetails'] = {}
else:
result['statusDetails'] = {}
if group_list and happened:
if new_status == GroupStatus.UNRESOLVED:
activity_type = Activity.SET_UNRESOLVED
activity_data = {}
开发者ID:duanshuaimin,项目名称:sentry,代码行数:67,代码来源:project_group_index.py
示例13: set_store
def set_store(self, key, value):
create_or_update(model=self.model, key=key.name, values={"value": value, "last_updated": timezone.now()})
开发者ID:ForkRepo,项目名称:sentry,代码行数:2,代码来源:store.py
示例14: update_groups
#.........这里部分代码省略.........
GroupResolution.objects.filter(
group__in=group_ids,
).delete()
if new_status == GroupStatus.IGNORED:
metrics.incr('group.ignored', skip_internal=True)
ignore_duration = (
statusDetails.pop('ignoreDuration', None) or
statusDetails.pop('snoozeDuration', None)
) or None
ignore_count = statusDetails.pop(
'ignoreCount', None) or None
ignore_window = statusDetails.pop(
'ignoreWindow', None) or None
ignore_user_count = statusDetails.pop(
'ignoreUserCount', None) or None
ignore_user_window = statusDetails.pop(
'ignoreUserWindow', None) or None
if ignore_duration or ignore_count or ignore_user_count:
if ignore_duration:
ignore_until = timezone.now() + timedelta(
minutes=ignore_duration,
)
else:
ignore_until = None
for group in group_list:
state = {}
if ignore_count and not ignore_window:
state['times_seen'] = group.times_seen
if ignore_user_count and not ignore_user_window:
state['users_seen'] = group.count_users_seen()
GroupSnooze.objects.create_or_update(
group=group,
values={
'until':
ignore_until,
'count':
ignore_count,
'window':
ignore_window,
'user_count':
ignore_user_count,
'user_window':
ignore_user_window,
'state':
state,
'actor_id':
request.user.id if request.user.is_authenticated() else None,
}
)
result['statusDetails'] = {
'ignoreCount': ignore_count,
'ignoreUntil': ignore_until,
'ignoreUserCount': ignore_user_count,
'ignoreUserWindow': ignore_user_window,
'ignoreWindow': ignore_window,
'actor': serialize(extract_lazy_object(request.user), request.user),
}
else:
GroupSnooze.objects.filter(
group__in=group_ids,
).delete()
ignore_until = None
result['statusDetails'] = {}
开发者ID:getsentry,项目名称:sentry,代码行数:67,代码来源:group_index.py
示例15: put
def put(self, request, group):
"""
Update an aggregate
Updates an individual aggregate's attributes.
{method} {path}
{{
"status": "resolved"
}}
Attributes:
- status: resolved, unresolved, muted
- hasSeen: true, false
- isBookmarked: true, false
- assignedTo: user
"""
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
result = serializer.object
# TODO(dcramer): we should allow assignment to anyone who has membership
# even if that membership is not SSO linked
if result.get("assignedTo") and not group.project.has_access(result["assignedTo"]):
return Response({"detail": "Cannot assign to non-team member"}, status=400)
if result.get("status") == "resolved":
now = timezone.now()
group.resolved_at = now
group.status = GroupStatus.RESOLVED
happened = (
Group.objects.filter(id=group.id)
.exclude(status=GroupStatus.RESOLVED)
.update(status=GroupStatus.RESOLVED, resolved_at=now)
)
if happened:
create_or_update(
Activity, project=group.project, group=group, type=Activity.SET_RESOLVED, user=request.user
)
elif result.get("status"):
group.status = STATUS_CHOICES[result["status"]]
group.save()
if result.get("hasSeen"):
instance, created = create_or_update(
GroupSeen, group=group, user=request.user, project=group.project, defaults={"last_seen": timezone.now()}
)
elif result.get("hasSeen") is False:
GroupSeen.objects.filter(group=group, user=request.user).delete()
if result.get("isBookmarked"):
GroupBookmark.objects.get_or_create(project=group.project, group=group, user=request.user)
elif result.get("isBookmarked") is False:
GroupBookmark.objects.filter(group=group, user=request.user).delete()
if "assignedTo" in result:
now = timezone.now()
if result["assignedTo"]:
assignee, created = GroupAssignee.objects.get_or_create(
group=group, defaults={"project": group.project, "user": result["assignedTo"], "date_added": now}
)
if not created:
affected = (
GroupAssignee.objects.filter(group=group)
.exclude(user=result["assignedTo"])
.update(user=result["assignedTo"], date_added=now)
)
else:
affected = True
if affected:
activity = Activity.objects.create(
project=group.project,
group=group,
type=Activity.ASSIGNED,
user=request.user,
data={"assignee": result["assignedTo"].id},
)
activity.send_notification()
else:
affected = GroupAssignee.objects.filter(group=group).delete()
if affected:
activity = Activity.objects.create(
project=group.project, group=group, type=Activity.UNASSIGNED, user=request.user
)
activity.send_notification()
return Response(serialize(group, request.user))
开发者ID:Juraldinio,项目名称:sentry,代码行数:99,代码来源:group_details.py
示例16: put
def put(self, request, group):
"""
Update an Aggregate
```````````````````
Updates an individual aggregate's attributes. Only the attributes
submitted are modified.
:pparam string group_id: the ID of the group to retrieve.
:param string status: the new status for the groups. Valid values
are ``"resolved"``, ``"unresolved"`` and
``"muted"``.
:param int assignedTo: the user ID of the user that should be
assigned to this group.
:param boolean hasSeen: in case this API call is invoked with a user
context this allows changing of the flag
that indicates if the user has seen the
event.
:param boolean isBookmarked: in case this API call is invoked with a
user context this allows changing of
the bookmark flag.
:auth: required
"""
serializer = GroupSerializer(data=request.DATA, partial=True)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
result = serializer.object
# TODO(dcramer): we should allow assignment to anyone who has membership
# even if that membership is not SSO linked
if result.get('assignedTo') and not group.project.member_set.filter(user=result['assignedTo']).exists():
return Response({'detail': 'Cannot assign to non-team member'}, status=400)
if result.get('status') == 'resolved':
now = timezone.now()
group.resolved_at = now
group.status = GroupStatus.RESOLVED
happened = Group.objects.filter(
id=group.id,
).exclude(status=GroupStatus.RESOLVED).update(
status=GroupStatus.RESOLVED,
resolved_at=now,
)
if happened:
create_or_update(
Activity,
project=group.project,
group=group,
type=Activity.SET_RESOLVED,
user=request.user,
)
elif result.get('status'):
group.status = STATUS_CHOICES[result['status']]
group.save()
if result.get('hasSeen') and group.project.member_set.filter(user=request.user).exists():
instance, created = create_or_update(
GroupSeen,
group=group,
user=request.user,
project=group.project,
values={
'last_seen': timezone.now(),
}
)
elif result.get('hasSeen') is False:
GroupSeen.objects.filter(
group=group,
user=request.user,
).delete()
if result.get('isBookmarked'):
GroupBookmark.objects.get_or_create(
project=group.project,
group=group,
user=request.user,
)
elif result.get('isBookmarked') is False:
GroupBookmark.objects.filter(
group=group,
user=request.user,
).delete()
if 'assignedTo' in result:
now = timezone.now()
if result['assignedTo']:
assignee, created = GroupAssignee.objects.get_or_create(
group=group,
defaults={
'project': group.project,
'user': result['assignedTo'],
'date_added': now,
}
)
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:sentry-1,代码行数:101,代码来源:group_details.py
注:本文中的sentry.db.models.query.create_or_update函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论