示例#1
0
def account_properties_view(request):
    try:
        account = request.user
        serializer = AccountPropertiesSerializer(account)
        return Response(serializer.data)
    except Account.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)
示例#2
0
def api_account_properties_view(request):
    try:
        account = request.user
    except Account.DoesNotExist:
        Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = AccountPropertiesSerializer(account)
        return Response(serializer.data)
示例#3
0
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)
示例#4
0
 def get(self, request):
     try:
         user_activity_list = UserProfile.objects.get(
             user_id=request.user.id)
         data = {}
         print(request.user, type(request.user))
         serialzer = UserProfileSerializer(user_activity_list)
         data['userprofile'] = serialzer.data
         data['user'] = AccountPropertiesSerializer(request.user).data
         return Response(data)
     except UserProfile.DoesNotExist:
         return Response(
             {'message': 'User profile is not created. Kindly login first'})
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)
示例#7
0
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)