图书管理系统

from django.shortcuts import *

from webs.fy import Pagination
from webs.models import User, yimian, qunzhong


def login(request):
    if request.method == 'GET':
        return render(request, 'login.html')
    username = request.POST.get('username')
    password = request.POST.get('password')
    user_info = User.objects.filter(username=username, password=password).first()
    if user_info:
        request.session['username'] = user_info.username
        request.session.set_expiry(0)
        return redirect(reverse('adindex'))
    return render(request, 'login.html', {'msg': '账号或者密码错误'})


def adindex(request):
    if request.method == 'GET':
        if request.session.get('username'):
            ym_info = yimian.objects.all()
            page_object = Pagination(
                current_page=request.GET.get('page'),
                all_count=ym_info.count(),
                base_url=request.path_info,
                query_params=request.GET
            )
            issues_object_list = ym_info[page_object.start:page_object.end]
            context = {
                'issues_object_list': issues_object_list,
                'page_html': page_object.page_html()
            }
            return render(request, 'adindex.html', context)
        return redirect(reverse('login'))

    issues_object_list = yimian.objects.all()
    name = request.POST.get('name')
    if name:
        issues_object_list = issues_object_list.filter(name=name)
    dizhi = request.POST.get('dizhi')
    if dizhi:
        issues_object_list = issues_object_list.filter(dizhi=dizhi)
    biaoji1 = request.POST.get('bj')
    if biaoji1:
        issues_object_list = issues_object_list.filter(biaoji1=biaoji1)
    return render(request, 'adindex.html', {'issues_object_list': issues_object_list})


def addzd(request):
    if request.method == 'GET':
        if request.session.get('username'):
            return render(request, 'addzd.html')
        return render(request, 'login.html')
    name = request.POST.get('name')
    xuzhi = request.POST.get('xuzhi')
    dizhi = request.POST.get('dizhi')
    tpl = request.POST.get('tpl')
    biaoji1 = request.POST.get('biaoji1')
    yimian.objects.create(name=name, xuzhi=xuzhi, dizhi=dizhi, tpl=tpl, biaoji1=biaoji1)
    return redirect(reverse('adindex'))


def upzd(request, id):
    if request.method == 'GET':
        if request.session.get('username'):
            ym_info = yimian.objects.filter(pk=id).first()
            return render(request, 'upzd.html', {'ym': ym_info})
        return render(request, 'login.html')
    name = request.POST.get('name')
    xuzhi = request.POST.get('xuzhi')
    dizhi = request.POST.get('dizhi')
    tpl = request.POST.get('tpl')
    biaoji1 = request.POST.get('biaoji1')
    yimian.objects.filter(pk=id).update(name=name, xuzhi=xuzhi, dizhi=dizhi, tpl=tpl, biaoji1=biaoji1)
    return redirect(reverse('adindex'))


def dezd(request, id):
    yimian.objects.filter(pk=id).delete()
    return redirect(reverse('adindex'))


def yuyue(request):
    if request.method == 'GET':
        if request.session.get('yonghu'):
            ym_info = yimian.objects.all()
            page_object = Pagination(
                current_page=request.GET.get('page'),
                all_count=ym_info.count(),
                base_url=request.path_info,
                query_params=request.GET
            )
            issues_object_list = ym_info[page_object.start:page_object.end]
            context = {
                'issues_object_list': issues_object_list,
                'page_html': page_object.page_html()

            }
            return render(request, 'yuyue.html', context)
        return redirect('yhlog')
def yuyues(request,id):
    opt = request.session.get('yonghu')
    a = qunzhong.objects.filter(opn=opt)
    a.update(yuye_id=id)
    return redirect(reverse('yuye'))


def yuyuezx(request):
    opt = request.session.get('yonghu')
    print(opt)
    a = qunzhong.objects.filter(opn=opt)
    return render(request,'zx.html',{'a':a})

def zhuce(request):
    if request.method == 'GET':
        return render(request, 'zhuce.html')
    opn = request.POST.get('opn')
    pwd = request.POST.get('pwd')
    sfz = request.POST.get('sfz')
    zz = request.POST.get('zz')
    dw = request.POST.get('dw')
    yonghu = qunzhong.objects.create(opn=opn,pwd=pwd,sfz=sfz,zz=zz,dw=dw)
    request.session['yonghu'] = yonghu.opn
    request.session.set_expiry(0)
    return redirect(reverse('yuye'))


def yhlog(request):
    if request.method == 'GET':
        return render(request, 'yhlog.html')
    opt = request.POST.get('opt')
    pwd = request.POST.get('pwd')
    yonghu = qunzhong.objects.filter(opn=opt,pwd=pwd).first()
    if yonghu:
        request.session['yonghu'] = yonghu.opn
        request.session.set_expiry(0)
        return redirect(reverse('yuye'))
    return render(request, 'login.html', {'msg': '账号或者密码错误'})

 

posted @ 2021-11-19 11:29  史可轩  阅读(29)  评论(0编辑  收藏  举报
3 4