当前位置:   article > 正文

基于Bootstrap+Django+Python的点菜信息管理系统_使用bootstrap实现网络点餐系统首页

使用bootstrap实现网络点餐系统首页

目 录
1 引言 1
1.1课题背景 1
1.2选题意义 1
2 系统可行性分析 1
2.1 技术可行性分析 1
2.2 经济可行性分析 1
2.3 操作可行性分析 2
3系统分析 2
3.1 系统功能分析 2
3.1.1 管理员模块 2
3.1.2 用户模块 3
3.1.3 后厨模块 4
3.2 系统业务流程分析 4
3.3 系统数据流程分析 5
3.4 数据字典 6
4 系统设计 9
4.1 功能结构设计 9
4.2 数据库设计 9
4.2.1 数据库概念结构设计 9
4.2.2 将E-R图转换为关系模型 11
4.3.3 关系模式的规范化 12
4.3.4 数据库表设计 13
4.3.5 数据库表中约束设计 15
5 系统实现 16
5.1 顾客页面实现 16
5.2 后厨页面实现 18
5.3 管理员页面实现 19
6 总结 22
参考文献 24
2 系统可行性分析
2.1 技术可行性分析
点菜信息管理系统将Sqlite作为数据库,Sqlite作为开源的关系型数据库,并且具有成本低、体积小、速度快等特点。整个系统是基于Django框架搭建的,Django框架本身就已经拥有了很多基础性的功能,不需要再去重复的完成大量的编码工作,提高了程序的规范性和代码的重用性。采用Bootstrap4 + jQuery作为前端的技术支持,后台使用Python面向对象语言。由此可见,实现点菜信息管理系统在技术上是完全可行的,并且可以完成点菜信息管理系统所需要的基本功能。
2.2 经济可行性分析
从目前的社会现状来看传统的点菜模式不仅浪费时间,效率低下,而且特别耗费成本与人力。于此不同,使用点菜信息管理系统能大大降低人力的成本这样就节省了相对应的成本开销,避免人员的冗余,并且开发系统使用的工具和技术都是开源的,投入该系统的成本并不高。所以对于餐馆来说开发一个点菜信息管理系统在当前的资金投入和使用该系统降低的成本上是可以接受的,由此来看此系统从经济上来看是可行的。
2.3 操作可行性分析
该系统使用的技术都是目前大众普遍使用的,并且操作简单,业务逻辑流程条例清晰,使用方便,并且用户使用起来上手快,容易理解,不需要理解太深的东西。由此来看,该系统从操作上来看是可行的。
3系统分析
3.1 系统功能分析
该系统为点菜管理信息系统。网上点菜系统是一种可以自主选择、个性化、便捷化、特色化的点餐模式,它的大力推广使用为餐厅节约了成本,同时也解决了消费者在传统点菜时存在的不少麻烦。通过对系统的需求进行分析得出,该系统的功能模块分为三种,分别是管理员模块、用户模块、后厨模块,并且各个用户模块下对应着各自的功能实现。
3.1.1 管理员模块
(1)管理员登录:对于已经存在管理员可进行登录。
(2)订单信息查询:管理员可以查询系统内所有存在订单。
(3)职工信息管理:管理员可以登录该系统对已经注册的职工个人信息进行增加、删除、改动、查找等操作。
(4)餐桌信息管理:管理员可以对该系统对已经存在的餐桌信息进行增加、删除、改动、查找等操作。本文转载自http://www.biyezuopin.vip/onews.asp?id=15595
(5)菜品信息管理:管理员可以对该系统对已经存在的菜品信息进行增加、删除、改动、查找等操作。

from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Food, Foodtype, Order, OrderItem, Staff, Staff_Table
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.db import connection
from . import forms
import json
import datetime

#
@csrf_exempt
def OrderHome(request):
    if request.method == "GET":
        foodList = Food.objects.all()
        foodTypeList = Foodtype.objects.all()
        tableList = Staff_Table.objects.all()
        return render(
            request,
            'OrderHome.html',
            {
                'foodList': foodList,
                'foodTypeList': foodTypeList,
                'tableList': tableList,
            }
        )
    elif request.method == "POST":
        foodList = json.loads(request.POST.get('foodList'))
        table_id = request.POST.get('table')

        # 创建订单 填写基本信息
        new_order = Order(table_id=table_id, is_pay=False)
        staff_in_charge = Staff_Table.objects.get(pk=table_id).staff
        new_order.staff = staff_in_charge   # 当前桌子的负责人
        new_order.save()

        # 先 save 再获取 ID
        order_id = new_order.ID
        food_amount = 0
        total_price = 0

        for food in foodList:
            curFood = Food.objects.get(pk=food['id'])
            price = curFood.price
            sum_price = price * food['amount']
            curFood.amount -= food['amount']
            curFood.save()

            food_amount += food['amount']
            total_price += sum_price

            OrderItem.objects.create(
                orderID=new_order,
                foodID=curFood,
                amount=food['amount'],
                sum_price=sum_price
            )
        # 订单的物品总数、总价
        new_order.food_amount = food_amount
        new_order.total_price = total_price
        new_order.save()

        return HttpResponse(json.dumps({
            'order_id': order_id
        }))


# 账单详情页
def QueryOrder(request, order_id):
    try:
        order = Order.objects.get(pk=order_id)
    except:
        return HttpResponse('无此订单!')

    foodList = Food.objects.filter(orderitem__orderID__ID=order_id)

    with connection.cursor() as cursor:
        SELECT_COL = 'OrderSystem_food.ID ID, OrderSystem_food.title title, OrderSystem_orderitem.amount amount'
        SELECT_COL += ', OrderSystem_orderitem.sum_price '
        SELECT_COL += ', OrderSystem_orderitem.start_cook_time '
        SELECT_COL += ', OrderSystem_orderitem.end_cook_time '
        SELECT_FROM = 'OrderSystem_food, OrderSystem_orderitem '
        SELECT_WHERE = 'OrderSystem_food.ID=OrderSystem_orderitem.foodID_id '
        SELECT_WHERE += ' and OrderSystem_orderitem.orderID_id={0}'.format(
            order_id)
        cursor.execute(
            f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}')
        foodJsonList = dictfetchall(cursor)#封装成字典

    return render(request, 'QueryOrder.html', {
        'order': order,
        'foodList': foodJsonList,
    })


# 待结账页面
def CheckUnpaidOrder(request):
    # 查询当前未结账订单
    orderList = []
    with connection.cursor() as cursor:
        SELECT_COL = 'ID, create_time, table_id, total_price'
        SELECT_FROM = 'OrderSystem_order'
        SELECT_WHERE = 'is_pay=0'   # 0 false
        SELECT = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
        cursor.execute(SELECT)
        orderList = dictfetchall(cursor)
        print(orderList)

    return render(request, 'CheckUnpaidOrder.html', {
        'orderList': orderList,
    })


# 结账
@csrf_exempt
def CheckOut(request):
    if request.method == "POST":
        order_list = json.loads(request.POST.get('order_list'))
        print(order_list)
        for order_data in order_list:
            print(order_data)
            order_id = order_data['order_id']
            is_pay = order_data['is_pay']

            if is_pay:
                order = Order.objects.get(pk=order_id)
                if order.is_pay == True:
                    print("已经支付!")
                    return HttpResponse(json.dumps({
                        'status': 'ALREADY_PAY'
                    }))

                order.is_pay = True
                order.pay_time = datetime.datetime.now()
                order.save()
            else:
                return HttpResponse(json.dumps({
                    'status': 'NO_PAY'
                }))

        return HttpResponse(json.dumps({
            'status': 'OK'
        }))


@login_required
def manage(request):
    staffList = Staff.objects.all()
    # (餐桌号 + 餐桌名字 + 负责人ID + 负责人姓名)
    tableInfoList = []
    with connection.cursor() as cursor:
        SELECT_COL = ' distinct {0}_staff_table.ID table_id '#桌子id
        SELECT_COL += ', {0}_staff_table.name table_name '#桌子名字
        SELECT_COL += ', {0}_staff.ID staff_id '
        SELECT_COL += ', {0}_staff.name staff_name '
        SELECT_COL = SELECT_COL.format('OrderSystem')

        SELECT_FROM = '{0}_staff_table, {0}_staff '
        SELECT_FROM = SELECT_FROM.format('OrderSystem')

        SELECT_WHERE = '{0}_staff.ID = {0}_staff_table.staff_id '
        SELECT_WHERE = SELECT_WHERE.format('OrderSystem')

        SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
        cursor.execute(SELECT_SQL)

        tableInfoList = dictfetchall(cursor)

    return render(request, 'manage.html', {
        'tableInfoList': tableInfoList,
        'staffList': staffList,
        'user':request.user,
    })


@csrf_exempt
def getServingTableList(request):
     # (餐桌号 + 餐桌名字 + 负责人ID + 负责人姓名)
    servingTableList = []
    with connection.cursor() as cursor:
        SELECT_COL = 'distinct {0}_order.table_id table_id '
        SELECT_COL = SELECT_COL.format('OrderSystem')

        SELECT_FROM = '{0}_order '
        SELECT_FROM = SELECT_FROM.format('OrderSystem')

        SELECT_WHERE = '{0}_order.is_pay = 0 '  # false 0
        SELECT_WHERE = SELECT_WHERE.format('OrderSystem')

        SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
        SELECT_SQL += 'order by table_id'
        cursor.execute(SELECT_SQL)

        servingTableInfoList = dictfetchall(cursor)
        for tableInfo in servingTableInfoList:
            servingTableList.append(tableInfo['table_id'])

    return HttpResponse(json.dumps({
        'servingTableList': servingTableList,
    }))


@csrf_exempt
def getOrderItemList(request):
    if request.method == "POST":
        # 没有指定 order_id 就返回所有 order_item
        order_id = request.POST.get('order_id')

        with connection.cursor() as cursor:
            SELECT_COL = '{0}orderitem.orderID_id order_id '
            SELECT_COL += ',{0}order.table_id table_id '
            SELECT_COL += ',{0}orderitem.foodID_id food_id '
            SELECT_COL += ',{0}food.title food_name '
            SELECT_COL += ',{0}orderitem.amount food_amount '
            SELECT_COL += ',{0}orderitem.status status '
            SELECT_COL = SELECT_COL.format('OrderSystem_')

            SELECT_FROM = '{0}orderitem, {0}food, {0}order '
            SELECT_FROM = SELECT_FROM.format('OrderSystem_')

            SELECT_WHERE = 'food_id = {0}food.ID '
            SELECT_WHERE += ' and {0}order.ID = order_id '
            SELECT_WHERE += ' and {0}order.is_pay = 0 '
            SELECT_WHERE += (' and order_id=' +
                             order_id) if order_id != None else ''
            SELECT_WHERE = SELECT_WHERE.format('OrderSystem_')

            SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
            SELECT_SQL += 'order by table_id'
            cursor.execute(SELECT_SQL)

            orderItemList = dictfetchall(cursor)

            return HttpResponse(json.dumps(orderItemList))


# 更新餐桌表 中的 staff
@csrf_exempt
def set_staff_charge_table(request):
    if request.method == "POST":
        table_id = request.POST.get("table_id")
        staff_id = request.POST.get("staff_id")
        try:
            Staff_Table.objects.filter(pk=table_id).update(staff_id=staff_id)
            return HttpResponse(json.dumps({
                'status': "OK"
            }))
        except:
            return HttpResponse(json.dumps({
                'status': "FAIL"
            }))


# 上菜
@csrf_exempt
def delive_food(request):
    if request.method == "POST":
        order_id = request.POST.get("order_id")
        food_id = request.POST.get("food_id")
        OrderItem.objects.filter(
            orderID_id=order_id, foodID_id=food_id).update(status=3)
        try:
            return HttpResponse(json.dumps({
                'status': "OK"
            }))
        except:
            return HttpResponse(json.dumps({
                'status': "FAIL"
            }))


# 后厨
@login_required#标识一个视图可以被跨域访问
def food_supplier(request):
    return render(request, 'FoodSupplier.html')


# 后厨接口 接单or完成
@csrf_exempt
def cook(request):
    if request.method == "POST":
        OP = request.POST.get("OP")
        order_id = request.POST.get("order_id")
        food_id = request.POST.get("food_id")

        orderItem = OrderItem.objects.filter(
            orderID_id=order_id, foodID_id=food_id)

        target_status = 1 if OP == "take_order" else 2

        if(OP == "take_order"):
            orderItem.update(status=1)
            orderItem.update(start_cook_time=datetime.datetime.now())
        else:
            orderItem.update(status=2)
            orderItem.update(end_cook_time=datetime.datetime.now())

        orderItem.save()

        return HttpResponse(json.dumps({
            'status': 'OK',
        }))


def dictfetchall(cursor):
    '''辅助函数 数据库查询结果转换成 json/dict'''
    columns = [col[0] for col in cursor.description]
    return [
        dict(zip(columns, row))
        for row in cursor.fetchall()
    ]


###############################################################
#
#    管理
#
###############################################################


def orders(request):
    orders = Order.objects.all()
    return render(request, 'manage/orders.html', {
        'orders': orders,
    })
@csrf_exempt
def staffs(request):
    if request.method=="GET":
        form = forms.StaffForm()
        staffs = Staff.objects.all()
        return render(request, 'manage/staffs.html', {
            'form': form,
            'staffs': staffs,
        })
    elif request.method == "POST":
        name=request.POST.get('name')
        SELECT_COL = '*'
        SELECT_FROM='OrderSystem_staff'
        SELECT_WHERE='OrderSystem_staff.name like'+ "'%"+name+ "%'"
        SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
        print(SELECT_SQL,"SQL")
        with connection.cursor() as cursor:
            cursor.execute(SELECT_SQL)
            staffs = dictfetchall(cursor)
        print(staffs, "SQL_res")
        form = forms.StaffForm()
        #staffs = Staff.objects.all()
        return render(request, 'manage/staffs.html', {
            'form': form,
            'staffs': staffs,
        })
        # form_back = forms.StaffForm(request.POST)
        # if form_back.is_valid():
        #     form_back.save()
        #     return HttpResponse(json.dumps({
        #         'status': 'OK',
        #     }))
        # else:
        #     print(form_back.errors.as_data())
        #     print(form_back.errors.as_json())
        #     print(form_back.errors.as_text())
        #     print(form_back.errors.as_ul())
        #     return HttpResponse(json.dumps({
        #         'status': 'FAIL',
        #     }))
@csrf_exempt
def tables(request):
    print(request.body)
    print(request.method,"method")
    if request.method == "GET":
        form = forms.Staff_TableForm()
        with connection.cursor() as cursor:
            SELECT_COL = ' distinct {0}_staff_table.ID table_id '
            SELECT_COL += ', {0}_staff_table.name table_name '
            SELECT_COL += ', {0}_staff.ID staff_id '
            SELECT_COL += ', {0}_staff.name staff_name '
            SELECT_COL = SELECT_COL.format('OrderSystem')

            SELECT_FROM = '{0}_staff_table, {0}_staff '
            SELECT_FROM = SELECT_FROM.format('OrderSystem')

            SELECT_WHERE = '{0}_staff.ID = {0}_staff_table.staff_id '
            SELECT_WHERE = SELECT_WHERE.format('OrderSystem')

            SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
            cursor.execute(SELECT_SQL)

            tables = dictfetchall(cursor)
            #print(tables,"table")
        with connection.cursor() as cursor:



            cursor.execute(
                'select ID staff_id, name staff_name from OrderSystem_staff;')
            staffs = dictfetchall(cursor)
        print('GET')
        #print(staffs,"staffs")
        return render(request, 'manage/tables.html', {
            'form': form,
            'tables': tables,
            'staffs': staffs,
        })
    else:
        name = request.POST.get('table_name')


        with connection.cursor() as cursor:
            SELECT_COL = ' distinct {0}_staff_table.ID table_id '
            SELECT_COL += ', {0}_staff_table.name table_name '
            SELECT_COL += ', {0}_staff.ID staff_id '
            SELECT_COL += ', {0}_staff.name staff_name '
            SELECT_COL = SELECT_COL.format('OrderSystem')

            SELECT_FROM = '{0}_staff_table, {0}_staff '
            SELECT_FROM = SELECT_FROM.format('OrderSystem')

            SELECT_WHERE = '{0}_staff.ID = {0}_staff_table.staff_id AND {0}_staff_table.name like '
            SELECT_WHERE +=  "'%"+name+ "%'"
            SELECT_WHERE = SELECT_WHERE.format('OrderSystem')

            SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'
            cursor.execute(SELECT_SQL)
            print(SELECT_SQL, "SQL")
            tables = dictfetchall(cursor)
        print(tables, "SQL_res")
        form = forms.Staff_TableForm()
        # staffs = Staff.objects.all()
        return render(request, 'manage/tables.html', {
            'form': form,
            'tables': tables,
           # 'staffs': staffs,
        })
@csrf_exempt
def add_tables(request):
    if request.method == 'GET':
        form = forms.Staff_TableForm()
        table=Staff_Table.objects.all()
        return render(request,'manage/add_tables.html',{
            'form': form,
        })
    else:
        form_back = forms.Staff_TableForm(request.POST)
        if form_back.is_valid():
            data = form_back.cleaned_data
            form_back.save()
            print("OK")
            return redirect('/manage/tables')
        else:
            print(form_back.errors.as_data())
            print(form_back.errors.as_json())
            print(form_back.errors.as_text())
            print(form_back.errors.as_ul())
            return HttpResponse(json.dumps({
               'Fail To Add': 'The table number already exists, please modify it',
            }),)
def update_tables(request):
    if request.method == 'GET':
        form = forms.Staff_TableForm()
        ID = request.GET.get('id')
        tables_obj = Staff_Table.objects.get(ID=ID)
        return render(request, 'manage/update_tables.html', {
            'form': form,
            'table': tables_obj
        })
    else:
        ID = request.POST.get('ID')
        print(ID,'ID')
        table_obj = Staff_Table.objects.get(ID=ID)
        table_obj_all = Staff_Table.objects.all()
        table_obj.ID = request.POST.get('ID')
        table_obj.name = request.POST.get('name')
        table_obj.staff_id = request.POST.get('staff')
        table_obj.save()
        return redirect('/manage/tables')





@csrf_exempt
def foods(request):
    if request.method == "GET":
        foods = Food.objects.all()
        food_types = Foodtype.objects.all()
        food_form = forms.FoodForm()
        food_type_form = forms.FoodtypeForm()
        return render(request, 'manage/foods.html', {
            'food_form': food_form,
            'food_type_form': food_type_form,
            'foods': foods,
            'food_types': food_types,
        })
    elif request.method == "POST":
        try:
            name = request.POST.get('foods_name')
            SELECT_COL = '*'
            SELECT_FROM = 'OrderSystem_food'
            SELECT_WHERE = 'OrderSystem_food.title like ' + "'%"+name+ "%'"

            SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'

            food_types = Foodtype.objects.all()
            print(SELECT_SQL, "SQL")

            with connection.cursor() as cursor:
                cursor.execute(SELECT_SQL)
                foods = dictfetchall(cursor)
        except:
            name=request.POST.get('foods_type_name')
            SELECT_COL = '*'
            SELECT_FROM = 'OrderSystem_foodtype'
            SELECT_WHERE = 'OrderSystem_foodtype.name like' + "'%"+name+ "%'"
            SELECT_SQL = f'select {SELECT_COL} from {SELECT_FROM} where {SELECT_WHERE}'

            foods = Food.objects.all()
            print(SELECT_SQL, "SQL")
            with connection.cursor() as cursor:
                cursor.execute(SELECT_SQL)
                food_types = dictfetchall(cursor)
        print(foods, "SQL_res")


        food_form = forms.FoodForm()
        food_type_form=forms.FoodtypeForm
        # staffs = Staff.objects.all()
        return render(request, 'manage/foods.html', {
            'food_form': food_form,
            'food_type_form': food_type_form,
            'foods': foods,
            'food_types': food_types,
        })
@csrf_exempt
def add_foodtype(request):
    if request.method == 'GET':
        food_type_form = forms.FoodtypeForm
        return render(request,'manage/add_foodtype.html',{
            'food_type_form': food_type_form,
        })
    else:

        form_foodtype = forms.FoodtypeForm(request.POST)
        if form_foodtype.is_valid():
            data = form_foodtype.cleaned_data
            form_foodtype.save()
            return redirect('/manage/foods')
def update_foodtype(request):
    if request.method == 'GET':
        food_type_form = forms.FoodtypeForm
        ID = request.GET.get('id')
        foodtype_obj = Foodtype.objects.get(ID=ID)
        return render(request,'manage/update_foodtype.html',{
            'food_type_form': food_type_form,
            'foodtype_obj':foodtype_obj
        })
    else:
        ID = request.POST.get('ID')
        foodtype_obj = Foodtype.objects.get(ID=ID)
        foodtype_obj.name=request.POST.get('name')
        foodtype_obj.save()
        return redirect('/manage/foods')

@csrf_exempt
def update_foods(request):
    if request.method == 'GET':
        ID = request.GET.get('id')
        food_form = forms.FoodForm()
        foods_obj = Food.objects.get(ID=ID)
        return render(request, 'manage/update_foods.html', {
            'foods_obj': foods_obj,
            'food_form': food_form,
        })
    else:
        ID = request.POST.get('ID')
        foods_obj = Food.objects.get(ID=ID)
        foods_obj.title = request.POST.get("title")
        foods_obj.amount = request.POST.get("amount")
        foods_obj.price = request.POST.get("price")
        foods_obj.cost_time = request.POST.get("cost_time")
        foods_obj.foodType_id = request.POST.get("foodType")
        foods_obj.save()
        return redirect('/manage/foods')
def add_foods(request):
    if request.method == 'GET':
        food_form = forms.FoodForm()
        return render(request, 'manage/add_foods.html', {
            'food_form': food_form,
        })

    else:
        form_food = forms.FoodForm(request.POST)
        if form_food.is_valid():
            data = form_food.cleaned_data
            form_food.save()
            return redirect('/manage/foods')


@csrf_exempt
#员工 增加
def add_staffs(request):
    if request.method=="GET":
        return render(request,'manage/add_staffs.html')
    elif request.method == "POST":
        form_back = forms.StaffForm(request.POST)
        import re

       # print(,"phone")
        #print(form_back,"citizenID")
        ret = re.match(r"^1[35678]\d{9}$", form_back.data['phone'])
        if ret:
            print("匹配成功")
            r = r'^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$'
            ret = re.match(r, form_back.data['citizenID'])
            if ret:
                if form_back.is_valid():
                    form_back.save()

                    form = forms.StaffForm()
                    staffs = Staff.objects.all()
                    return render(request, 'manage/staffs.html', {
                        'form': form,
                        'staffs': staffs,
                    })
                else:
                    print(form_back.errors.as_data())
                    print(form_back.errors.as_json())
                    print(form_back.errors.as_text())
                    print(form_back.errors.as_ul())
                    return HttpResponse(json.dumps({
                        'status': 'FAIL',
                    }))
            else:
                return HttpResponse(json.dumps({
                    'citizenID': 'error!',
                }))
        else:
            return HttpResponse(json.dumps({
                'phone': 'error!',
            }))




@csrf_exempt
#员工 删除
def dark(request):
    if request.method == "POST":
        target = request.POST

        table = target['table']
        SQL = ''
        if target['double'] == 'false':
            ID = target['id']
            SQL += f'delete from OrderSystem_{table} where ID={ID}'
        elif target['double'] == 'true':
            foodID_id = target['foodID_id']
            orderID_id = target['orderID_id']
            SQL += f'delete from OrderSystem_{table} where foodID_id={foodID_id} and orderID_id={orderID_id}'

        print('========================================================================')
        print(SQL)
        print('========================================================================')

        try:
            with connection.cursor() as cursor:
                cursor.execute(SQL)
                print("True")
                return HttpResponse(json.dumps({
                    'status': 'OK',
                }))
        #     return render(request, 'manage/staffs.html', {
        #     'status': json.dumps([1,1])
        # })
        except:
            print("False")
            # return render(request, 'manage/staffs.html', {
            #     'status': json.dumps([0,0])
            # })
            return HttpResponse(json.dumps({
               'status': 'FAIL',
           }))
#员工更新
@csrf_exempt
def update_staffs(request):
    if request.method=='GET':
        ID=request.GET.get('id')
        staffs_obj=Staff.objects.get(ID=ID)
        return render(request, 'manage/update_staffs.html', {
            'staffs': staffs_obj,
        })
    else :
        ID=request.POST.get('ID')
        citizenID=request.POST.get('citizenID')
        name = request.POST.get('name')
        gender = request.POST.get('gender')
        born_date = request.POST.get('born_date')
        phone = request.POST.get('phone')






        address = request.POST.get('address')
        staff_obj=Staff.objects.get(ID=ID)

        staff_obj.name=name
        staff_obj.citizenID = citizenID
        staff_obj.gender = gender
        staff_obj.born_date = born_date
        staff_obj.phone = phone
        staff_obj.address = address

        import re

        # print(,"phone")
        # print(form_back,"citizenID")
        ret = re.match(r"^1[35678]\d{9}$", phone)
        if ret:
            print("匹配成功")
            r = r'^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$'
            ret = re.match(r, citizenID)
            if ret:
               staff_obj.save()
               return redirect('/manage/staffs')
            else:
                return HttpResponse(json.dumps({
                    'citizenID': 'error!',
                }))
        else:
            return HttpResponse(json.dumps({
                'phone': 'error!',
            }))



           # staffs = dictfetchall(cursor)



    #return render(request, 'manage/update_staffs.html')
    #return render(request,'update_staffs.html')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/725139
推荐阅读
相关标签
  

闽ICP备14008679号