更新用户个人主页的功能

This commit is contained in:
virusdefender
2015-10-25 15:30:11 +08:00
parent 30bfe5bef2
commit 05d9fb52ad
6 changed files with 140 additions and 70 deletions

View 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',
},
),
]

View File

@@ -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为ac2为正在进行
problems_status = JSONField(default={})
class Meta:
db_table = "user_profile"

View File

@@ -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):