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,13 +246,14 @@ 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"]
user_profile.mood = data["mood"] else:
user_profile.hduoj_username = data["hduoj_username"] user_profile.mood = data["mood"]
user_profile.bestcoder_username = data["bestcoder_username"] user_profile.hduoj_username = data["hduoj_username"]
user_profile.codeforces_username = data["codeforces_username"] user_profile.bestcoder_username = data["bestcoder_username"]
user_profile.blog = data["blog"] user_profile.codeforces_username = data["codeforces_username"]
user_profile.school = data["school"] user_profile.blog = data["blog"]
user_profile.phone_number = data["phone_number"] user_profile.school = data["school"]
user_profile.phone_number = data["phone_number"]
user_profile.save() user_profile.save()
return success_response(u"修改成功") return success_response(u"修改成功")
else: else:

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

@ -1,40 +1,50 @@
{% extends "oj_base.html" %} {% extends "oj_base.html" %}
{% block title %} {% block title %}
更换头像 更换头像
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<div class="container main"> <div class="container main">
<div class="col-lg-2"> <div class="col-lg-2">
<ul class="list-group"> <ul class="list-group">
<li class="list-group-header">通用设置</li> <li class="list-group-header">通用设置</li>
<li class="list-group-item"><a href="/account/settings/">个人信息</a></li> <li class="list-group-item"><a href="/account/settings/">个人信息</a></li>
<li class="list-group-item active"><a href="/account/settings/avatar/">更换头像</a></li> <li class="list-group-item active"><a href="/account/settings/avatar/">更换头像</a></li>
<li class="list-group-item"><a href="/change_password/">修改密码</a></li> <li class="list-group-item"><a href="/change_password/">修改密码</a></li>
</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>
<div class="row"> <div class="row">
{% for i in "aaaaaaaaaaaaaaaaaaaa" %} {% for i in "aaaaaaaaaaaaaaaaaaaa" %}
<div class="col-lg-2 avatar-item"> <div class="col-lg-2 avatar-item">
<div style="border: 1px solid red;" > <div style="border: 1px solid red;">
<img src="/static/img/avatar/avatar-{{ forloop.counter }}.png"> <img src="/static/img/avatar/avatar-{{ forloop.counter }}.png">
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<div title="Coding.net 是深圳市扣钉网络科技有限公司打造的国内最大的一站式云端开发平台提供包括代码托管项目管理产品演示WebIDE 等工具。">
<img src="https://coding.net/static/d0aa9dd75e2500930b9e6ef61d9bcfa0.jpg" style="height: 100px;width: 150px"> <div title="Coding.net 是深圳市扣钉网络科技有限公司打造的国内最大的一站式云端开发平台提供包括代码托管项目管理产品演示WebIDE 等工具。">
水果头像由<a href="https://coding.net">coding.net</a>提供。 <img src="https://coding.net/static/d0aa9dd75e2500930b9e6ef61d9bcfa0.jpg"
style="height: 100px;width: 150px">
水果头像由<a href="https://coding.net">coding.net</a>提供。
</div> </div>
</form> </form>
</div> </div>
</div> </div>
{% endblock %}
{% block js_block %}
<script src="/static/js/app/oj/account/avatar.js"></script>
{% endblock %} {% 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">