Beispiel #1
0
def newuser_view(request):
    if not request.user.is_staff:
        return main_view(request)

    if 'username' in request.POST:

        username = request.POST.get('username')
        password = request.POST.get('password')
        newuserqs = User.objects.filter(username=username)
        if newuserqs.exists():
            alertstr = _('username exists.')
            temp = loader.get_template('runscript.html')
            url = 'index'
            context = Context({
                'alertstr': alertstr, 'url': url
            })
            return HttpResponse(temp.render(context))

        newuser = User.objects.create_user(username=username, password=password)
        newuser.is_active = True
        newuser.save()

        cname = request.POST.get('cname')
        info = CommonInfo(user=newuser)
        info.cname = cname
        info.ename = ""
        info.birthday = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        info.sex = ""
        info.bloodtype = ""
        info.cellphone = ""
        info.email = "*****@*****.**"
        info.mailbox = ""
        info.homeaddr = ""
        info.currentaddr = "Mars"
        info.save()
        return main_view(request)

    user = request.user
    userinfo = CommonInfo.objects.get(user=user)

    return render_to_response('newuser.html', {'user': user, 'userinfo': userinfo},
                              context_instance=RequestContext(request))
Beispiel #2
0
def main_view(request):
    # 所有用户列表
    infolist = CommonInfo.objects.all()
    # 当前用户
    user = request.user
    # 当前用户信息
    #info = None
    try:
        info = CommonInfo.objects.get(user=user)
    except CommonInfo.DoesNotExist:
        # info未找到,新建一个信息
        info = CommonInfo(user=user)
        info.cname = "匿名的小伙伴"
        info.ename = ""
        info.birthday = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        info.sex = ""
        info.bloodtype = ""
        info.cellphone = ""
        info.email = "*****@*****.**"
        info.mailbox = ""
        info.homeaddr = ""
        info.currentaddr = "Mars"
        info.save()

    try:
        temp = loader.get_template("main.html")
    except TemplateDoesNotExist:
        return render_to_response('404.html', context=RequestContext(request))
    # main页面渲染参数
    context = Context({
        'infolist': infolist,
        'user': user,
        'userinfo': info,
        'info': info,
        'SEX_TYPE': CommonInfo.SEX_TYPE,
        'BLOOD_TYPE': CommonInfo.BLOOD_TYPE
    })

    return HttpResponse(temp.render(context))