def post(self, request, *args, **kwargs):
"""
Take the user object from the request and call the 'save' method on it to persist to the DB. If this succeeds
then we can report a success.
:param request:
:param args:
:param kwargs:
:return: Serialised JSON Response Object to indicate the resource has been created
"""
stdlogger.debug("Hitting HTTP POST account view")
# Try and persist the user to the DB. Remember this could fail a data integrity check if some other system has
# saved this user before we run this line of code!
try:
request.user.save()
except (IntegrityError, InternalError, DataError, DatabaseError):
# The chances of this happening are slim to none! And this line of code should never happen. So we really
# need to tell the other system we are not capable of creating the resource.
raise DatabaseFailureException
context = {'account': request.user.email, 'created': 'success'}
json_context = JSONRenderer().render(context)
return Response(data=json_context, status=status.HTTP_201_CREATED,)
评论列表
文章目录