mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 17:26:38 +00:00
add account view for preview
This commit is contained in:
parent
df8781b9b3
commit
8a68ad7ac9
10
account/urls/user.py
Normal file
10
account/urls/user.py
Normal file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from ..views.user import UserProfileAPI
|
||||
|
||||
urlpatterns = [
|
||||
url(r"^profile$", UserProfileAPI.as_view(), name="user_profile_api"),
|
||||
]
|
47
account/views/user.py
Normal file
47
account/views/user.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from utils.api import APIView, validate_serializer
|
||||
|
||||
from ..decorators import login_required
|
||||
from ..serializers import EditUserSerializer, UserSerializer
|
||||
|
||||
|
||||
# class UserInfoAPI(APIView):
|
||||
# @login_required
|
||||
# def get(self, request):
|
||||
# """
|
||||
# Return user info api
|
||||
# """
|
||||
# return self.success(UserSerializer(request.user).data)
|
||||
|
||||
|
||||
class UserProfileAPI(APIView):
|
||||
@login_required
|
||||
def get(self, request):
|
||||
"""
|
||||
Return user info api
|
||||
"""
|
||||
return self.success(UserSerializer(request.user).data)
|
||||
|
||||
@validate_serializer(EditUserSerializer)
|
||||
@login_required
|
||||
def put(self, request):
|
||||
data = request.data
|
||||
user_profile = request.user.userprofile
|
||||
if data["avatar"]:
|
||||
user_profile.avatar = data["avatar"]
|
||||
else:
|
||||
user_profile.mood = data["mood"]
|
||||
user_profile.blog = data["blog"]
|
||||
user_profile.school = data["school"]
|
||||
user_profile.student_id = data["student_id"]
|
||||
user_profile.phone_number = data["phone_number"]
|
||||
user_profile.major = data["major"]
|
||||
# Timezone & language 暂时不加
|
||||
user_profile.save()
|
||||
return self.success(_("Succeeded"))
|
||||
|
||||
|
@ -3,6 +3,7 @@ from django.conf.urls import include, url
|
||||
urlpatterns = [
|
||||
url(r"^api/", include("account.urls.oj")),
|
||||
url(r"^api/admin/", include("account.urls.admin")),
|
||||
url(r"^api/account/", include("account.urls.user")),
|
||||
url(r"^api/admin/", include("announcement.urls.admin")),
|
||||
url(r"^api/", include("conf.urls.oj")),
|
||||
url(r"^api/admin/", include("conf.urls.admin")),
|
||||
|
Loading…
x
Reference in New Issue
Block a user