def update_account_view(request): try: account = request.user except Account.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = AccountPropertiesSerializer(account, data=request.data) data = {} if serializer.is_valid(): serializer.save() data['response'] = "account updated successfully" return Response(data=data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def account_update_view(request): try: account = request.user except Account.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'PUT': serializer = AccountPropertiesSerializer(account, data=request.data) data = {} if serializer.is_valid(): serializer.save() data['response'] = "Account Update Success" return Response(data=data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def profile_update(request): try: account = request.user except Account.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == "PUT": serializer = AccountPropertiesSerializer(account, data=request.data) data = {} if serializer.is_valid(): serializer.save() data["response"] = "Account update success" return Response(data=data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def update_account_properties(request): data = {} try: info = AccountPropertiesSerializer(data=request.data, fields=('first_name', 'last_name', 'description')) if info.is_valid(raise_exception=True): info = info.data user = request.user user.first_name = info.get('first_name') user.last_name = info.get('last_name') user.description = info.get('description') user.save() data['response'] = _("response.success") except Account.DoesNotExist: data['response'] = _("response.error") data['error_message'] = _("msg.account.not.found") except Exception as e: data['response'] = _("response.error") data['error_message'] = str(e) finally: return Response(data)