diff --git a/account/views.py b/account/views.py index 8cc6e3d8..b7a84788 100644 --- a/account/views.py +++ b/account/views.py @@ -246,13 +246,14 @@ class UserProfileAPIView(APIView): user_profile = request.user.userprofile if data["avatar"]: user_profile.avatar = data["avatar"] - user_profile.mood = data["mood"] - user_profile.hduoj_username = data["hduoj_username"] - user_profile.bestcoder_username = data["bestcoder_username"] - user_profile.codeforces_username = data["codeforces_username"] - user_profile.blog = data["blog"] - user_profile.school = data["school"] - user_profile.phone_number = data["phone_number"] + else: + user_profile.mood = data["mood"] + user_profile.hduoj_username = data["hduoj_username"] + user_profile.bestcoder_username = data["bestcoder_username"] + user_profile.codeforces_username = data["codeforces_username"] + user_profile.blog = data["blog"] + user_profile.school = data["school"] + user_profile.phone_number = data["phone_number"] user_profile.save() return success_response(u"修改成功") else: diff --git a/static/src/js/app/oj/account/avatar.js b/static/src/js/app/oj/account/avatar.js new file mode 100644 index 00000000..04368b52 --- /dev/null +++ b/static/src/js/app/oj/account/avatar.js @@ -0,0 +1,38 @@ +require(["jquery", "bsAlert", "csrfToken"], function ($, bsAlert, csrfTokenHeader) { + var avatar=""; + function changeAvatar(event) { + avatar = $(event.target).attr('src'); + $('#current_avatar').attr('src', avatar); + } + + $('.avatar-item').click(changeAvatar); + + $('#save_avatar').click(function(){ + if (avatar) + $.ajax({ + beforeSend: csrfTokenHeader, + url: "/api/account/userprofile/", + data: { + avatar: avatar + }, + dataType: "json", + method: "put", + success: function (data) { + if (!data.code) { + bsAlert("已保存!"); + } + else{ + bsAlert(data.data); + } + }, + error: function () { + bsAlert("额 好像出错了,请刷新页面重试。如还有问题,请填写页面导航栏上的反馈。") + } + + }); + else + bsAlert("请选择一个头像"); + + }); +}); + diff --git a/template/src/oj/account/avatar.html b/template/src/oj/account/avatar.html index e51d1c03..39daa513 100644 --- a/template/src/oj/account/avatar.html +++ b/template/src/oj/account/avatar.html @@ -1,40 +1,50 @@ {% extends "oj_base.html" %} {% block title %} - 更换头像 +更换头像 {% endblock %} {% block body %} -
+
-
- -
+
+ +
- + +
+
+ +
{% for i in "aaaaaaaaaaaaaaaaaaaa" %}
-
- -
+
+ +
{% endfor %}
-
- - 水果头像由coding.net提供。 + +
+ + 水果头像由coding.net提供。
-
+
+{% endblock %} + +{% block js_block %} + {% endblock %} diff --git a/template/src/oj/account/change_password.html b/template/src/oj/account/change_password.html index 29be4561..3f346e2b 100644 --- a/template/src/oj/account/change_password.html +++ b/template/src/oj/account/change_password.html @@ -14,7 +14,7 @@
-