对之前发的那个程序的小修改

本来觉得凑合凑合交差,但是被说完全不行,要考虑用户的感受,写一个让人愿意使用的有用的系统,不是随便就行了。所以还是得继续改吧。先加入时间筛选函数。

from mysite.dishorder.models import Restaurant
from mysite.dishorder.models import User
from mysite.dishorder.models import Dash
from mysite.dishorder.models import recodrd
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
import datetime
import time
 

def index (request):
    return render_to_response('dish.html',{'dash':dash})

def login (request):

    username=request.POST.get('username',None)
    passw=request.POST.get('password',None)
   
    if username:
        user=User.objects.get(username=username)
       
        if user:
            if passw==user.password:
                request.session['user']=user
                if user.username=='yoyo':
                    return render_to_response('mainmanage.html')
                else:
                    return render_to_response('usermain.html',{'user':user})
            else:
                meg="you password is wrong please login again"
            return render_to_response ("login.html",{'message':meg})
               
        else :
            meg="your id didn't exist"
            return render_to_response ("login.html",{'message':meg})
    else:
        return render_to_response ("login.html")
   
def register (request):

    username=request.POST.get('username',None)
    passw=request.POST.get('password',None)
    config=request.POST.get('conpass',None)

    if username:
        pwd=User.objects.filter(username=username)
        if pwd:
            meg="The id has exist"
            return render_to_response  ("message.html",{'message':meg})
        else:
            if passw!=config:
                meg="The twice password is not the same"
                return render_to_response ("message.html",{'message':meg})
            else:
                us=User(username=username,password=passw,account=0)
                us.save()
                meg="register successful"
                return render_to_response ("message.html",{'message':meg})
           
           
    else:
        return render_to_response ("register.html")
   
def order (request):
    restaut=Restaurant.objects.all()
   
    return render_to_response ("order.html",{'restaurant': restaut})

def menu (request):

    res=request.POST.get('restaurant',None)

    if res:
        r = Restaurant.objects.get(id=res)
        menus=Dash.objects.filter (restaurant=r)
        #menu=Dash.filter()
        return render_to_response('menu.html',{'menu':menus, 'restaurant':r})
    else :
        meg="You didn't choose any restanrant"
        return render_to_response('message.html', {'message':meg})
   
def usermain (request):
    user=request.session.get ('user',None)
    return render_to_response('usermain.html',{'user':user})
    
def userorder (request):

    dashid=request.POST.getlist('dashid')
    restaurantid=request.POST.get('restaurantid',None)
    times=datetime.datetime(time.localtime()[0],time.localtime()[1],time.localtime()[2],time.localtime()[3],time.localtime()[4],time.localtime()[5],time.localtime()[6])

    if dashid:
        dashs=list ()
        count=0
        for daid in dashid:
            user=request.session.get('user',None)
            user1=User.objects.get(id=user.id)
           
            dash1=Dash.objects.get(id= (daid))
           
            dashs.append(dash1)
            count+=dash1.price
            restaurant1=Restaurant.objects.get(id=restaurantid)
            recodrd1=recodrd(user=user1,dash=dash1,dates=times)
            recodrd1.save()
        if count>10:
            user1.account+=count-10
            user1.save()
        return render_to_response ('userorder.html',{'user':user1,'restaurant':restaurant1,'dashs':dashs,'time':times,'count':count})
      

    else:
        meg=dashid
        return render_to_response('message.html', {'message':meg})
   
def query (request):
    userid=request.POST.get("userid",None) 
    nowtime=time.localtime()
    if userid:
        records=recodrd.objects.filter(user=userid,dates__month=nowtime[1],dates__year=nowtime[0])
        count=0
        for res in records:
            count+=res.dash.price
           
        return render_to_response ('query.html',{'record':records,'count':count } )
       
    else :
        meg="You did't have any record"
        return render_to_response('message.html', {'message':meg})
   
def manage (request):
    nowtime=time.localtime()
    records=recodrd.objects.filter(dates__day=nowtime[2],dates__month=nowtime[1],dates__year=nowtime[0])
    count=0
    for res in records:
        count+=res.dash.price
           
    return render_to_response ('manage.html',{'record':records,'count':count } )
def queryperson (request):
    return render_to_response ('queryperson.html')

def personaccount (request):
    userid=request.POST.get('userid',None)
    user=User.objects.get(id=userid)
    return render_to_response ('account.html',{'account':user.account})

def result (request):
    username=request.POST.get('username',None)
    if username:
        user=User.objects.get(username=username)
        if user:
            return render_to_response ('result.html',{'user':user})
        else:
            meg="The id doesn't exist"
            return render_to_response('message.html', {'message':meg})
       
def mainmanage(request):
    return render_to_response('mainmanage.html')

def delaccount (request):
    userid=request.POST.get('userid',None)
    if userid:
        user=User.objects.get(id=userid)
        user.account=0
        user.save()
    meg="The count has been maked zero"
    return render_to_response('message.html', {'message':meg})
   
 

 

query.htm

 

{% extends "myorder/base.htm" %}
{% block content1 %}
<form action="/query/" method="get">
<table  border="1">
  <tr>
    <td width="300">&nbsp;起始年
      <input name="qyear" type="text" size="4" maxlength="4">
      月
      <input name="qmonth" type="text" size="2" maxlength="2">
      日
      <input name="qday" type="text" size="2" maxlength="2"> </td>
    <td width="300">&nbsp;结束年
      <input name="qyear2" type="text" size="4" maxlength="4">
      月
      <input name="qmonth2" type="text" size="2" maxlength="2">
      日
      <input name="qday2" type="text" size="2" maxlength="2"></td>

    </tr>

  <tr>
    <td> &nbsp;姓名
      <input name="wName" type="text" size="8" maxlength="8"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input type="submit" name="Submit" value="提交"></td>
    <td>&nbsp;</td>

 

 
    </tr>

</table>

</form>
<table  border="1">
  <tr>
    <td width="150">员工</td>
    <td width="150">个人总价</td>
  </tr>
 
  {%for item in toShowList %}
  <tr>
    <td>&nbsp;{{item.workerName}}</td>
    <td>&nbsp;{{item.total}}</td>
  </tr>
  {%    endfor  %}
 
</table>
<table border="1">
  <tr>
    <td width="150">&nbsp;</td>
    <td width="150">公司总价</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;{{all}}</td>
  </tr>
</table>

<table border="1">
  <tr>
    <td width="50" >&nbsp;ID</td>
    <td width="100" >&nbsp;员工</td>
    <td width="200" >&nbsp;菜名</td>
    <td width="50" >&nbsp;价格</td>
    <td width="100" >&nbsp;餐厅</td>
    <td width="100" >&nbsp;时间</td>
  </tr>
  {% for orderItem in orderItems %}
  <tr>
    <td width="50" >&nbsp;{{ orderItem.id }}</td>
    <td width="100" >&nbsp;{{ orderItem.workerName }}</td>
    <td width="200" >&nbsp;{{ orderItem.dishName }}</td>
    <td width="50" >&nbsp;{{ orderItem.dishPrice }}</td>
    <td width="100" >&nbsp;{{ orderItem.orderRest.restName }}</td>
    <td width="100" >&nbsp;{{ orderItem.orderTime }}</td>
  </tr>
 {% endfor %}
</table>

{% endblock %} 

 

base.htm也改了下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>定餐</title>
</head>
<body>
<a href="/inputorder/">手工输入订单</a>
<a href="/selectlist/">从菜单选择</a>
<a href="/statistic/">统计今日总价</a>
<a href="/editorder/">编辑今日订单</a>
<a href="/query/">查询订单和总价</a>


 {% block content1 %}
 {% endblock %} 


</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值