mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
更新用户个人主页的功能
This commit is contained in:
parent
30bfe5bef2
commit
05d9fb52ad
37
account/migrations/0013_userprofile.py
Normal file
37
account/migrations/0013_userprofile.py
Normal file
@ -0,0 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import jsonfield.fields
|
||||
import account.models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0012_auto_20151012_1546'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserProfile',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('avatar', models.CharField(default=account.models._random_avatar, max_length=50)),
|
||||
('blog', models.URLField(null=True, blank=True)),
|
||||
('mood', models.CharField(max_length=200, null=True, blank=True)),
|
||||
('hduoj_username', models.CharField(max_length=30, null=True, blank=True)),
|
||||
('bestcoder_username', models.CharField(max_length=30, null=True, blank=True)),
|
||||
('codeforces_username', models.CharField(max_length=30, null=True, blank=True)),
|
||||
('rank', models.IntegerField(default=65535)),
|
||||
('accepted_number', models.IntegerField(default=0)),
|
||||
('submissions_number', models.IntegerField(default=0)),
|
||||
('problems_status', jsonfield.fields.JSONField(default={})),
|
||||
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'user_profile',
|
||||
},
|
||||
),
|
||||
]
|
@ -48,3 +48,26 @@ class User(AbstractBaseUser):
|
||||
|
||||
class Meta:
|
||||
db_table = "user"
|
||||
|
||||
|
||||
def _random_avatar():
|
||||
import random
|
||||
return "/static/img/avatar/avatar-" + str(random.randint(1, 20)) + ".png"
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.OneToOneField(User)
|
||||
avatar = models.CharField(max_length=50, default=_random_avatar)
|
||||
blog = models.URLField(blank=True, null=True)
|
||||
mood = models.CharField(max_length=200, blank=True, null=True)
|
||||
hduoj_username = models.CharField(max_length=30, blank=True, null=True)
|
||||
bestcoder_username = models.CharField(max_length=30, blank=True, null=True)
|
||||
codeforces_username = models.CharField(max_length=30, blank=True, null=True)
|
||||
rank = models.IntegerField(default=65535)
|
||||
accepted_number = models.IntegerField(default=0)
|
||||
submissions_number = models.IntegerField(default=0)
|
||||
# JSON字典用来表示该用户的问题的解决状态 1为ac,2为正在进行
|
||||
problems_status = JSONField(default={})
|
||||
|
||||
class Meta:
|
||||
db_table = "user_profile"
|
||||
|
@ -286,7 +286,17 @@ class ResetPasswordAPIView(APIView):
|
||||
|
||||
|
||||
def user_index_page(request, username):
|
||||
return render(request, "oj/account/user_index.html")
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return error_page(request, u"用户不存在")
|
||||
|
||||
blog_link = ""
|
||||
|
||||
if user.userprofile.blog:
|
||||
blog_link = user.userprofile.blog.replace("http://", "").replace("https://", "")
|
||||
|
||||
return render(request, "oj/account/user_index.html", {"user": user, "blog_link": blog_link})
|
||||
|
||||
|
||||
class SSOAPIView(APIView):
|
||||
|
@ -121,7 +121,7 @@ urlpatterns = [
|
||||
url(r'^api/contest/time/$', ContestTimeAPIView.as_view(), name="contest_time_api_view"),
|
||||
url(r'^api/admin/rejudge/$', SubmissionRejudgeAdminAPIView.as_view(), name="submission_rejudge_api"),
|
||||
|
||||
url(r'^user/(?P<username>\w+)/$', "account.views.user_index_page"),
|
||||
url(r'^user/(?P<username>.+)/$', "account.views.user_index_page"),
|
||||
|
||||
url(r'^api/reset_password/$', ApplyResetPasswordAPIView.as_view(), name="apply_reset_password_api"),
|
||||
|
||||
|
@ -62,3 +62,24 @@ pre, code {
|
||||
font-family: "source_code_pro";
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#index-avatar{
|
||||
height: 200px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
#user-mood{
|
||||
max-width: 70%;
|
||||
}
|
||||
|
||||
#oj-logo{
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.super-admin-star{
|
||||
color: #ffd700;
|
||||
}
|
||||
|
||||
.admin-star{
|
||||
color: #c0c0c0;
|
||||
}
|
@ -6,85 +6,64 @@
|
||||
<div class="container main">
|
||||
<div class="col-lg-4">
|
||||
<div class="avatar">
|
||||
<img src="https://coding.net/static/fruit_avatar/Fruit-1.png" class="img-responsive"
|
||||
style="height: 200px;width: 200px;">
|
||||
<img src="{{ user.userprofile.avatar }}" class="img-responsive" id="index-avatar">
|
||||
</div>
|
||||
<div>
|
||||
<h2>virusdefender</h2>
|
||||
<h2>
|
||||
{{ user.username }}
|
||||
{% ifequal user.admin_type 2 %}
|
||||
<span class="glyphicon glyphicon-star super-admin-star" title="超级管理员"></span>
|
||||
{% endifequal %}
|
||||
{% ifequal user.admin_type 1 %}
|
||||
<span class="glyphicon glyphicon-star admin-star"></span>
|
||||
{% endifequal %}
|
||||
|
||||
</h2>
|
||||
<p id="user-mood">{{ user.userprofile.mood }}</p>
|
||||
</div>
|
||||
<div class="list-group col-lg-10">
|
||||
<div class="list-group col-lg-8">
|
||||
|
||||
{% if user.userprofile.blog %}
|
||||
<p class="list-group-item"><span class="glyphicon glyphicon-link"></span>
|
||||
<a href="https://virusdefender.net">https://virusdefender.net</a>
|
||||
<a href="{{ user.userprofile.blog }}" target="_blank">{{ blog_link }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if user.userprofile.hduoj_username %}
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/hdu_logo.png" id="oj-logo">
|
||||
<a href="http://bestcoder.hdu.edu.cn/rating.php?user={{ user.userprofile.hduoj_username }}" target="_blank">
|
||||
{{ user.userprofile.hduoj_username }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if user.userprofile.bestcoder_username %}
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/bestcoder_logo.png" id="oj-logo">
|
||||
<a href="http://bestcoder.hdu.edu.cn/rating.php?user={{ user.userprofile.bestcoder_username }}" target="_blank">
|
||||
{{ user.userprofile.bestcoder_username }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if user.userprofile.codeforces_username %}
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/codeforces_logo.png" id="oj-logo">
|
||||
<a href="http://codeforces.com/profile/{{ user.userprofile.codeforces_username }}" target="_blank">
|
||||
{{ user.userprofile.codeforces_username }}
|
||||
</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/hdu_logo.png" style="height: 20px">
|
||||
<a href="https://virusdefender.net">https://virusdefender.net</a>
|
||||
<span class="glyphicon glyphicon-calendar"></span>
|
||||
{{ user.create_time }}
|
||||
</p>
|
||||
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/bestcoder_logo.png" style="height: 20px">
|
||||
<a href="https://virusdefender.net">https://virusdefender.net</a>
|
||||
</p>
|
||||
|
||||
<p class="list-group-item">
|
||||
<img src="/static/img/oj_logo/codeforces_logo.png" style="height: 20px">
|
||||
<a href="https://virusdefender.net">https://virusdefender.net</a>
|
||||
</p>
|
||||
|
||||
|
||||
<p class="list-group-item"><span class="glyphicon glyphicon-calendar"></span> 2015-9-10</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
<ul class="nav nav-tabs" style="margin: 10px;;">
|
||||
<li role="presentation" class="active"><a href="#">Home</a></li>
|
||||
<li role="presentation"><a href="#123">全部分享</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<div class="col-lg-6">
|
||||
<div class="panel panel-success">
|
||||
<div class="panel-heading"><h3 class="panel-title">正在做的题</h3></div>
|
||||
|
||||
<div class="list-group">
|
||||
<p class="list-group-item">
|
||||
<a href="#" style="font-size: large;">problem title</a>
|
||||
<span class="right">3 / 10</span>
|
||||
<span style="display: block;">Accepted</span>
|
||||
</p>
|
||||
|
||||
<p class="list-group-item">
|
||||
<a href="#" style="font-size: large;">problem title</a>
|
||||
<span class="right">3 / 10</span>
|
||||
<span style="display: block;">Accepted</span>
|
||||
</p>
|
||||
|
||||
<p class="list-group-item">
|
||||
<a href="#" style="font-size: large;">problem title</a>
|
||||
<span class="right">3 / 10</span>
|
||||
<span style="display: block;">Accepted</span>
|
||||
</p>
|
||||
|
||||
<p class="list-group-item">
|
||||
<a href="#" style="font-size: large;">problem title</a>
|
||||
<span class="right">3 / 10</span>
|
||||
<span style="display: block;">Accepted</span>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading"><h3 class="panel-title">分享的代码</h3></div>
|
||||
<div class="panel-body"> Panel content</div>
|
||||
</div>
|
||||
</div>
|
||||
TODO
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block js_block %}
|
||||
<script src="/static/js/app/oj/account/register.js"></script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user