Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete(self, request, auth, *args, **kwargs):
"""Deletes post."""
try:
post = self.model.objects.get(id=kwargs['id'])
except self.model.DoesNotExist:
raise ResponseException(status.NOT_FOUND)
key = tools.key(request.GET['password'])
if post.password == key:
post.remove()
elif is_mod(request, post.section_slug()):
mod_delete_post(request, post)
post.remove()
else:
return Response(status.FORBIDDEN, content={
'detail': u'{0}{1}. {2}'.format(
_('Error on deleting post #'), post.pid,
_('Password mismatch')
)
})
return Response(status.NO_CONTENT)
def metadata(self, request, *args, **kwargs):
content = {
'name': self.get_name(),
'description': self.get_description(),
'renders': self._rendered_media_types,
'parses': self._parsed_media_types,
}
# TODO: Add 'fields', from serializer info.
# form = self.get_bound_form()
# if form is not None:
# field_name_types = {}
# for name, field in form.fields.iteritems():
# field_name_types[name] = field.__class__.__name__
# content['fields'] = field_name_types
return Response(content, status=status.HTTP_200_OK)
def _permissioncheck(self, period):
if self.request.user.is_superuser:
return
if not Period.where_is_admin(self.request.user).filter(id=period.id).exists():
raise ErrorResponse(status=statuscodes.HTTP_403_FORBIDDEN)
if not created:
sibling.ip_address = sibling_data['ip_address']
sibling.port = sibling_data['port']
sibling.save()
local_node = LocalNode.get()
local_node_info = {
'ip_address': IPADDRESS,
'port': PORT,
'uuid': local_node.uuid,
'name': local_node.name,
'email': local_node.email,
'comment': local_node.comment,
}
return local_node_info
else:
return Response(status.PARTIAL_CONTENT)
def post(self, request, auth, content, *args, **kwargs):
try:
instance = validate_post(request)
except forms.ValidationError as e:
return Response(status.BAD_REQUEST, {'detail': e})
# django sends date with microseconds. We don't want it.
instance.date = instance.date.strftime('%Y-%m-%d %H:%M:%S')
url = 'http://127.0.0.1:8888/api/streamp/{0}'
data = urllib.urlencode({'html': instance.html.encode('utf-8')})
try:
urllib2.urlopen(url.format(instance.thread.id), data)
except urllib2.URLError:
raise ResponseException(status.INTERNAL_SERVER_ERROR, {
'detail': u'{0}: {1}'.format(
_('Server error'), _('can\'t refresh messages')
)
})
self.model.allowed_fields.append('html')
return Response(status.CREATED, instance)
def check_permission(self, user):
if len(self.view.args) != 1:
raise ErrorResponse(status.HTTP_403_FORBIDDEN,
{'detail': 'The IsAssignmentAdmin permission checker requires an assignmentid.'})
assignmentid = self.view.args[0]
# TODO: Should update assignmentadmin_required to raise ErrorResponse
# TODO: Only check this here, not in create and list in the DAO
try:
assignmentadmin_required(user, "i18n.permissiondenied", assignmentid)
except ForbiddenError, e:
raise ErrorResponse(status.HTTP_403_FORBIDDEN,
{'detail': 'Permission denied.'})
def __init__(self, errormsg):
super(NotFoundError, self).__init__(status.HTTP_404_NOT_FOUND,
{'detail': errormsg})
def update(self, request, *args, **kwargs):
self.object = self.get_object()
serializer = self.get_serializer(data=request.DATA, instance=self.object)
if serializer.is_valid():
self.object = serializer.object
self.object.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
'homeTeacher': homeroom_class.teacher_id
}
if homeroom_class.teacher_id:
temp['homeTeacher'] = homeroom_class.teacher_id.full_name()
classes.append(temp)
result['teaching_class'] = classes
except Exception as e:
print e
raise e
elif user_position > 3:
#TODO: return necessary information for school's admins
return Response(status=status.HTTP_404_NOT_FOUND)
return Response(status=status.HTTP_200_OK, content= result)
else:
return Response(status.HTTP_401_UNAUTHORIZED)
def destroy(self, request, *args, **kwargs):
self.object = self.get_object()
self.object.delete()
return Response(status=status.HTTP_204_NO_CONTENT)