From 05d9fb52adc51cd3217a617dd0606235e75c6db9 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 25 Oct 2015 15:30:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=BB=E9=A1=B5=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/migrations/0013_userprofile.py | 37 ++++++++ account/models.py | 23 +++++ account/views.py | 12 ++- oj/urls.py | 2 +- static/src/css/global.css | 21 +++++ template/src/oj/account/user_index.html | 115 ++++++++++-------------- 6 files changed, 140 insertions(+), 70 deletions(-) create mode 100644 account/migrations/0013_userprofile.py diff --git a/account/migrations/0013_userprofile.py b/account/migrations/0013_userprofile.py new file mode 100644 index 00000000..02689e3d --- /dev/null +++ b/account/migrations/0013_userprofile.py @@ -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', + }, + ), + ] diff --git a/account/models.py b/account/models.py index 4c6bfca3..0fb78589 100644 --- a/account/models.py +++ b/account/models.py @@ -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" diff --git a/account/views.py b/account/views.py index 5a43e9cb..5b75ce90 100644 --- a/account/views.py +++ b/account/views.py @@ -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): diff --git a/oj/urls.py b/oj/urls.py index 2b6047d5..dfbe669f 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -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\w+)/$', "account.views.user_index_page"), + url(r'^user/(?P.+)/$', "account.views.user_index_page"), url(r'^api/reset_password/$', ApplyResetPasswordAPIView.as_view(), name="apply_reset_password_api"), diff --git a/static/src/css/global.css b/static/src/css/global.css index 339c0d60..d43735e8 100644 --- a/static/src/css/global.css +++ b/static/src/css/global.css @@ -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; +} \ No newline at end of file diff --git a/template/src/oj/account/user_index.html b/template/src/oj/account/user_index.html index 2b2041d5..d8ce651a 100644 --- a/template/src/oj/account/user_index.html +++ b/template/src/oj/account/user_index.html @@ -6,85 +6,64 @@
- +
-

virusdefender

+

+ {{ user.username }} + {% ifequal user.admin_type 2 %} + + {% endifequal %} + {% ifequal user.admin_type 1 %} + + {% endifequal %} + +

+

{{ user.userprofile.mood }}

-
+
+ + {% if user.userprofile.blog %}

- https://virusdefender.net + {{ blog_link }}

+ {% endif %} + + {% if user.userprofile.hduoj_username %} +

+ + + {{ user.userprofile.hduoj_username }} + +

+ {% endif %} + + {% if user.userprofile.bestcoder_username %} +

+ + + {{ user.userprofile.bestcoder_username }} + +

+ {% endif %} + + {% if user.userprofile.codeforces_username %} +

+ + + {{ user.userprofile.codeforces_username }} + +

+ {% endif %}

- - https://virusdefender.net + + {{ user.create_time }}

- -

- - https://virusdefender.net -

- -

- - https://virusdefender.net -

- - -

2015-9-10

- - - -
-
-

正在做的题

- -
-

- problem title - 3 / 10 - Accepted -

- -

- problem title - 3 / 10 - Accepted -

- -

- problem title - 3 / 10 - Accepted -

- -

- problem title - 3 / 10 - Accepted -

- -
- -
-
-
-
-

分享的代码

-
Panel content
-
-
+ TODO
-{% endblock %} -{% block js_block %} - {% endblock %} \ No newline at end of file