Example #1
0
def userExphistory(request):
    '''用户的所有/某类活跃列表,由 profile 进入'''
    # user check
    user = util.user.getCurrentUser(request)
    if not user:
        return util.ctrl.infoMsg("您还没有登入,请先登入", title='请先登入', url='/user/signin')
    # get inputs
    context = {}
    category = request.GET.get('category')
    view = request.GET.get('view')
    if category:
        userexp = user.getUserExp(category)
        if not userexp:
            return util.ctrl.infoMsg("请求的分类({category})不存在".format(category=category), title='访问错误')
        if view == 'full':
            exphistorys = userexp.getExpHistory()
        else:
            exphistorys = userexp.getExpHistory(22)
    else:
        return util.ctrl.infoMsg("请输入请求的分类", title='访问错误')
    # render
    context['userexp'] = userexp
    context['exphistorys'] = exphistorys
    context['view'] = view
    return render(request, 'user/exphistory.html', context)
Example #2
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)
Example #3
0
def exphistory(request):
    """用户的所有/某类活跃列表,由 profile 进入"""
    # user check
    user = util.user.getCurrentUser(request)
    # get inputs
    context = {}
    category = request.GET.get('category')
    view = request.GET.get('view')
    if category:
        userexp = user.getUserExp(category)
        if not userexp:
            return util.ctrl.infoMsg(_("请求的分类({})不存在").format(category),
                                     title=_('错误'))
        if view == 'full':
            exphistorys = userexp.getExpHistory()
        else:
            exphistorys = userexp.getExpHistory(22)
    else:
        return util.ctrl.infoMsg(_("{} 参数不能为空").format("Category"),
                                 title=_('错误'))
    # render
    context['userexp'] = userexp
    context['exphistorys'] = exphistorys
    context['view'] = view
    return render(request, 'user/exphistory.html', context)
Example #4
0
def profile(request):
    """查看当前用户的个人信息,点击右上角昵称进入"""
    context = {}
    # get user exps
    exps = []
    user = util.user.getCurrentUser(request)
    userexps = user.getUserExp()
    for ue in userexps:
        explet = (ue, ue.getExpHistory(5))
        exps.append(explet)
    # 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
    util.userexp.addExp(user, 'user', 1, _('查看用户个人信息'))
    # render
    context['prgstatics'] = progress_statics.values()
    context['exps'] = exps
    return render(request, 'user/profile.html', context)