This commit is contained in:
virusdefender 2015-11-11 20:52:52 +08:00
commit c93ca4ce9b
4 changed files with 76 additions and 27 deletions

View File

@ -246,6 +246,7 @@ class UserProfileAPIView(APIView):
user_profile = request.user.userprofile user_profile = request.user.userprofile
if data["avatar"]: if data["avatar"]:
user_profile.avatar = data["avatar"] user_profile.avatar = data["avatar"]
else:
user_profile.mood = data["mood"] user_profile.mood = data["mood"]
user_profile.hduoj_username = data["hduoj_username"] user_profile.hduoj_username = data["hduoj_username"]
user_profile.bestcoder_username = data["bestcoder_username"] user_profile.bestcoder_username = data["bestcoder_username"]

View File

@ -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("请选择一个头像");
});
});

View File

@ -14,8 +14,12 @@
</ul> </ul>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<img src="https://coding.net/static/fruit_avatar/Fruit-1.png" class="img-responsive" <img src="{{ user.userprofile.avatar }}" class="img-responsive"
style="height: 200px;width: 200px;"> style="height: 200px;width: 200px;" id="current_avatar">
<br>
<div class="form-group left">
<button id="save_avatar" type="submit" class="btn btn-primary">保存</button>
</div>
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">
<form> <form>
@ -29,8 +33,10 @@
{% endfor %} {% endfor %}
</div> </div>
<div title="Coding.net 是深圳市扣钉网络科技有限公司打造的国内最大的一站式云端开发平台提供包括代码托管项目管理产品演示WebIDE 等工具。"> <div title="Coding.net 是深圳市扣钉网络科技有限公司打造的国内最大的一站式云端开发平台提供包括代码托管项目管理产品演示WebIDE 等工具。">
<img src="https://coding.net/static/d0aa9dd75e2500930b9e6ef61d9bcfa0.jpg" style="height: 100px;width: 150px"> <img src="https://coding.net/static/d0aa9dd75e2500930b9e6ef61d9bcfa0.jpg"
style="height: 100px;width: 150px">
水果头像由<a href="https://coding.net">coding.net</a>提供。 水果头像由<a href="https://coding.net">coding.net</a>提供。
</div> </div>
@ -38,3 +44,7 @@
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block js_block %}
<script src="/static/js/app/oj/account/avatar.js"></script>
{% endblock %}

View File

@ -14,7 +14,7 @@
</ul> </ul>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<img src="https://coding.net/static/fruit_avatar/Fruit-1.png" class="img-responsive" <img src="{{ user.userprofile.avatar }}" class="img-responsive"
style="height: 200px;width: 200px;"> style="height: 200px;width: 200px;">
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">