Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@need_login
def get(self, request, ids):
user = request.user
ids = ids.split('-')
_smses = sms.objects.filter(id__in=ids, sender=user)
result = {}
for s in _smses:
result[s.id] = '%s-%s' % (s.recent, s.success)
return Response(status.HTTP_200_OK, content=result)
def _get_406_response(self):
renderer = self.renderer_classes[0]
return Response(
{
'detail': 'Could not satisfy the client\'s Accept header',
'available_types': [renderer.media_type
for renderer in self.renderer_classes]
},
status=status.HTTP_406_NOT_ACCEPTABLE,
view=self.view, request=self.request, renderer_classes=[renderer])
group_id = data['id']
groupids.append(group_id)
groups = self._query_groups_by_id(groupids)
if len(groups) != len(datalist):
raise NotFoundError('One or more of the requested groups does not exist.'.format(**vars()))
with transaction.commit_on_success():
for group in groups:
manager = GroupManager(request.user, assignment_id, group)
try:
manager.delete()
except ValidationError, e:
raise ValidationErrorResponse(e)
else:
logger.warning('User=%s deleted AssignmentGroup id=%s', self.user, group.id)
return Response(204, '')
def post(self, request, id):
deadlines = self._add_deadlines()
groups = deadlines_as_groupobjects(deadlines)
assignment_id = self.kwargs['id']
content = create_deadlinedict(assignment_id=assignment_id,
deadlines=deadlines)
return Response(status=201, content=content)
raise ErrorResponse(status.NOT_FOUND)
key = get_key(request.GET["password"])
if file.post.password == key:
file.remove()
elif is_mod(request, file.post.section_slug()):
mod_delete_post(request, file.post)
file.remove()
else:
raise ErrorResponse(status.FORBIDDEN, content={
"detail": u"{}{}. {}".format(
_("Error on deleting file #"), file.post.pid,
_("Password mismatch")
)
})
return Response(status.NO_CONTENT)
def handle_exception(self, exc):
"""
Handle any exception that occurs, by returning an appropriate response,
or re-raising the error.
"""
if isinstance(exc, exceptions.Throttled):
self.headers['X-Throttle-Wait-Seconds'] = '%d' % exc.wait
if isinstance(exc, exceptions.APIException):
return Response({'detail': exc.detail}, status=exc.status_code)
elif isinstance(exc, Http404):
return Response({'detail': 'Not found'},
status=status.HTTP_404_NOT_FOUND)
elif isinstance(exc, PermissionDenied):
return Response({'detail': 'Permission denied'},
status=status.HTTP_403_FORBIDDEN)
raise
def post(self, request, num):
"""
Handle POST requests, with form validation.
Returns a simple string indicating what content was supplied.
"""
if int(num) > 2:
return Response(status.HTTP_404_NOT_FOUND)
return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(self.CONTENT))
def get(self, request, *args, **kwargs):
return Response()