profile: rename multiple var and change to use
django rest frameword
This commit is contained in:
@ -1,21 +1,19 @@
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
from django.http import HttpResponse, HttpRequest
|
||||
from django.contrib.auth.models import User
|
||||
from django.http import JsonResponse
|
||||
from django.http import HttpRequest
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions, status
|
||||
|
||||
from .status_code import *
|
||||
from .models import Profile
|
||||
from .models import ProfileModel
|
||||
|
||||
# Create your views here.
|
||||
class ProfilePage(View):
|
||||
def get(self, request: HttpRequest, id: int):
|
||||
class ProfileView(APIView):
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
|
||||
def get(self, request: HttpRequest, pk: int):
|
||||
|
||||
query: QuerySet = Profile.objects.filter(pk=id)
|
||||
if (not query.exists()):
|
||||
return HttpResponse(PROFILE_NOT_FOUND)
|
||||
profile: ProfileModel = ProfileModel.objects.get(pk=pk)
|
||||
if (profile is None):
|
||||
return Response(status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
profile: Profile = Profile.objects.get(pk=id)
|
||||
|
||||
return JsonResponse({'username': profile.user.username,
|
||||
return Response(status=status.HTTP_200_OK, data={'name': profile.user.username,
|
||||
'title': profile.title})
|
Reference in New Issue
Block a user