From 519c3788091f763505222f543454f38152520efa Mon Sep 17 00:00:00 2001 From: esp Date: Wed, 11 Nov 2015 09:15:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8D=A2=E5=A4=B4=E5=83=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views.py | 15 ++++---- static/src/js/app/oj/account/avatar.js | 39 +++++++++++++++++++++ template/src/oj/account/avatar.html | 48 ++++++++++++++++---------- 3 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 static/src/js/app/oj/account/avatar.js 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..89e28348 --- /dev/null +++ b/static/src/js/app/oj/account/avatar.js @@ -0,0 +1,39 @@ +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(){ + alert("aaa"); + 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 %} From 0463b295eadf9da176f00bb2db55daf05194a3fa Mon Sep 17 00:00:00 2001 From: esp Date: Wed, 11 Nov 2015 09:24:17 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=A4=B4=E5=83=8Furl=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/src/oj/account/change_password.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@
-
From 02fb497a9488bd1d141d6492e21621adc3f37eff Mon Sep 17 00:00:00 2001 From: esp Date: Wed, 11 Nov 2015 09:26:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E8=AF=AD=E5=8F=A5...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/avatar.js | 1 - 1 file changed, 1 deletion(-) diff --git a/static/src/js/app/oj/account/avatar.js b/static/src/js/app/oj/account/avatar.js index 89e28348..04368b52 100644 --- a/static/src/js/app/oj/account/avatar.js +++ b/static/src/js/app/oj/account/avatar.js @@ -8,7 +8,6 @@ require(["jquery", "bsAlert", "csrfToken"], function ($, bsAlert, csrfTokenHeade $('.avatar-item').click(changeAvatar); $('#save_avatar').click(function(){ - alert("aaa"); if (avatar) $.ajax({ beforeSend: csrfTokenHeader,