Beispiel #1
0
def userProfile(request):
    '''查看当前用户的个人信息,点击右上角昵称进入'''
    context = {}
    user = util.user.getCurrentUser(request)
    if not user:
        return util.user.loginToContinue(request)
    # get user exps
    exps = []
    lv_notice = []
    userexps = user.getUserExp()
    for ue in userexps:
        explet = (ue, ue.getExpHistory(5))
        exps.append(explet)
        cache_key = 'userexp:{ue.id}:{ue.category}:level'.format(ue=ue)
        cache_timeout = 60 * 60 * 24 * 7 * 2  # 2 weeks
        cached_lv = cache.get(cache_key)
        if cached_lv:  # has cached category:level
            new_lv = ue.level
            if new_lv > cached_lv:
                lv_noticelet = (ue.category_zh(), cached_lv, new_lv)
                lv_notice.append(lv_noticelet)
        cache.set(cache_key, ue.level, cache_timeout)
    # get user progress counts
    progress_statics = user.getProgressStatics()
    done_prg_count = Progress.objects.filter(status='done').count()
    if done_prg_count >= 25:
        user.setUserpermission('wellread', True)
    # add exp
    userexp, created = UserExp.objects.get_or_create(userid=user.id, category='user')
    userexp.addExp(1, '查看用户个人信息')
    # render
    context['prgstatics'] = progress_statics.values()
    context['exps'] = exps
    context['lvnotice'] = lv_notice
    return render(request, 'user/profile.html', context)
Beispiel #2
0
def userPublic(request):  # public
    '''通过 email/id/nickname 查看用户公开信息'''
    context = {}
    nickname = request.GET.get('nickname')
    if not nickname:
        return util.ctrl.infoMsg("被查看用户的昵称不在参数中", title='参数错误')
    try:
        user = User.objects.get(nickname=nickname)
    except User.DoesNotExist:
        return util.ctrl.infoMsg("用户 @{nickname} 不存在".format(nickname=nickname), title='找不到用户')
    # get user progress counts
    progress_statics = user.getProgressStatics()
    progress_statics_group = []
    for (k, v) in progress_statics.items():
        item = (Progress.objects.getStatusName(k), v['count'])
        progress_statics_group.append(item)
    # add exp to 被查看人
    userexp, created = UserExp.objects.get_or_create(userid=user.id, category='user')
    _by = request.META.get('REMOTE_HOST') or request.META.get('REMOTE_ADDR')
    userexp.addExp(1, '{} 访问了你的「公开页」'.format(_by))
    # render
    context['user'] = user
    context['prgcounts'] = progress_statics_group
    return render(request, 'user/public.html', context)