Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogewzy/4f6d942ef00bd37a1611519c23fe3d7d to your computer and use it in GitHub Desktop.
Save dogewzy/4f6d942ef00bd37a1611519c23fe3d7d to your computer and use it in GitHub Desktop.
graduation design
<component name="ProjectDictionaryState">
<dictionary name="wzy">
<words>
<w>lucai</w>
<w>tablename</w>
</words>
</dictionary>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5.2 (/usr/bin/python3.5)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyByteLiteralInspection" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.2 (/usr/bin/python3.5)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/graduation design.iml" filepath="$PROJECT_DIR$/.idea/graduation design.iml" />
</modules>
</component>
</project>
# import datetime
# s = '2017-3-20'
# p = datetime.datetime.strptime(s,'%Y-%m-%d')
# q = p.replace(hour=23, minute=59, second=59, microsecond=999999)
# print q
print 1<2<3
from handlers.auth import IndexHandler
from handlers.waiter import *
from handlers.test import TestHandler
# coding: utf-8
from tornado import web
from tornado import gen
from model import *
from model.db import db_session
class IndexHandler(web.RequestHandler):
@web.asynchronous
@gen.coroutine
def get(self):
self.render('login.html', title='login', items='no')
def post(self, *args, **kwargs):
a = self.get_argument('account')
p = self.get_argument('password')
people = db_session.query(
People
).filter_by(account=a, password=p).first()
if people:
self.render('%s.html' % people.role)
else:
self.render('login_false.html')
# coding: utf-8
from tornado import web
from tornado import gen
from model import *
from model.db import db_session, redis_connect
import json
class TestHandler(web.RequestHandler):
def get(self, *args, **kwargs):
food = db_session.query(Food).all()
food_list = [f.name for f in food]
self.render('test.html', title='food_list', items=food_list)
def post(self, *args, **kwargs):
response = self.request.body
print(response, '???')
# coding: utf-8
from tornado import web
from tornado import gen
from model import *
from model.db import db_session, redis_connect
import json
import uuid
class AddMenuHandler(web.RequestHandler):
def get(self, *args, **kwargs):
food = db_session.query(Food).all()
food_list = [f.name for f in food]
self.render('menu.html', title='food_list', items=food_list)
def post(self, *args, **kwargs):
response = json.loads(self.request.body.decode('utf-8'))
print(response, '===================')
food_list = response['food'].split(',')[0:-1]
table_num = int(response['table'])
menu_id = str(uuid.uuid4())
for i in food_list:
redis_connect.lpush(table_num, i)
Menu.create(food=response['food'], id=menu_id, table_num=table_num)
class MenuStatus(web.RequestHandler):
def get(self, *args, **kwargs):
menu_id = 0
food_list = redis_connect.lrange(menu_id)
self.render('menu_status.html')
from model.models import People, Menu, Food
__all__ = [
'People', 'Menu', 'Food'
]
from model.db import Base, engine
Base.metadata.reflect(engine) # 将数据映射绑定到引擎
Base.metadata.create_all(engine)
# coding: utf-8
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.pool import NullPool
import redis
engine = create_engine(
'mysql+pymysql://root:330625@127.0.0.1:3306/design?charset=utf8mb4',
convert_unicode=True,
echo=True,
poolclass=NullPool
)
db_session = scoped_session(sessionmaker(
autocommit=False,
autoflush=True,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
redis_connect = redis.StrictRedis()
class CRUDMixin(object):
"""Mixin that adds convenience methods for CRUD (create, read, update, delete) operations."""
@classmethod
def create(cls, **kwargs):
"""Create a new record and save it the database."""
instance = cls(**kwargs)
return instance.save()
def update(self, commit=True, **kwargs):
"""Update specific fields of a record."""
for attr, value in kwargs.items():
setattr(self, attr, value)
return commit and self.save() or self
def save(self, commit=True):
"""Save the record."""
db_session.add(self)
if commit:
db_session.commit()
return self
def delete(self, commit=True):
"""Remove the record from the database."""
db_session.delete(self)
return commit and db_session.commit()
class Model(CRUDMixin, Base):
"""Base model class that includes CRUD convenience methods."""
__abstract__ = True
# coding: utf-8
import datetime
from sqlalchemy import Column
from sqlalchemy.types import Unicode, DateTime, Integer
from .db import Model
class People(Model):
__tablename__ = 'people'
id = Column(Unicode(70), unique=True,
nullable=False, primary_key=True)
name = Column(Unicode(255))
menu_id = Column(Unicode(255), default=u'')
role = Column(Unicode(255))
password = Column(Unicode(255))
account = Column(Unicode(255))
def __repr__(self):
return str(self.name)+str(self.role)
class Menu(Model):
__tablename__ = 'menu'
id = Column(Unicode(70), unique=True,
nullable=False, primary_key=True)
table_num = Column(Integer, default=0)
create_time = Column(DateTime, default=datetime.datetime.now())
food = Column(Unicode(1500))
add_food = Column(Unicode(500), default=u'')
ret_food = Column(Unicode(255), default=u'')
def __repr__(self):
return self.table_num
class Food(Model):
__tablename__ = 'food'
id = Column(Unicode(70), unique=True,
nullable=False, primary_key=True)
name = Column(Unicode(255))
# 0:not ready, 1:ready
status = Column(Unicode(64), default=u'0')
menu_id = Column(Unicode(70), default=u'')
price = Column(Integer)
type = Column(Unicode(70))
def __repr__(self):
return str(self.name) + str(self.status)
import redis
redis_connect = redis.StrictRedis(charset='utf-8')
l = redis_connect.lrange('menu',0,-1)
for i in l:
print(i.decode('utf-8'))
tornado
PyMySQL==0.7.4
requests==2.10.0
redis==2.10.5
# Docs
Jinja2==2.8
# coding: utf-8
import sys
import getopt
import tornado
from tornado import ioloop, web
from tornado.options import options
from settings import settings
from urls import url_patterns
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
class Application(web.Application):
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
def main(argv=None):
if argv is None:
argv = sys.argv
opts, args = getopt.getopt(argv[1:], "h", ["help"])
"""Creates instance of the server and starts IOLoop."""
tornado.options.parse_command_line()
application = Application()
application.listen(options.port, address=options.address)
tornado.ioloop.IOLoop.current().start()
# except getopt.error, msg:
# raise Usage(msg)
# # more code, unchanged
# except Usage, err:
# print >>sys.stderr, err.msg
# print >>sys.stderr, "for help use --help"
# return 2
if __name__ == "__main__":
print('http://' + options.address + ':' + str(options.port))
sys.exit(main())
import os
import tornado
from tornado.options import define, options
path = lambda root, *a: os.path.join(root, *a)
ROOT = os.path.dirname(os.path.abspath(__file__))
define("debug", default=True)
define("port", default=8080, help="run on this port", type=int)
define("address", default="127.0.0.1", help="run on this port", type=str)
MEDIA_ROOT = path(ROOT, "media")
TEMPLATE_ROOT = path(ROOT, "templates")
DOCS_INDEX_ROOT = path(ROOT, "site")
settings = {
"template_path": TEMPLATE_ROOT,
"static_path": MEDIA_ROOT,
"debug": options.debug,
"autoreload": options.debug
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>王氏餐饮</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap-grid.css">
<script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
</head>
<body>
{% block login %}
{% end %}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>chief</p>
</body>
</html>
{% extends "base.html" %}
{% block login %}
<form>
<div class="form-group">
<label for="email">账号:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">密码:</label>
<input type="password" class="form-control" id="pwd">
</div>
<button type="submit" class="btn btn-default">登录</button>
</form>
{% end %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flase</title>
</head>
<body>
<p>false</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Menu</title>
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<span>桌号</span><input type="text" name="桌号" id="table">
<ul>
{% for food in items %}
<li><input type="checkbox" id="food"><span>{{ food }}</span></li>
{% end %}
</ul>
<input type="submit" id="submit" value="下单">
<script>
$(document).ready(function(){
$("#submit").click(function(){
var chkIds = "";
$("input:checkbox:checked").each(function(i){
<!--alert($(this).next().html())-->
chkIds += $(this).next().html() + ",";
});
data = {};
data['food']=chkIds;
data['table']=$("#table").val()
<!--$.post('/menu',JSON.stringify(data));-->
$.ajax({
type : "post",
dataType : "json",
data : JSON.stringify(data),
url : '/menu',
success : function(){
},
error : function() {
window.location.href='http://127.0.0.1:8080/menustatus';
}
});
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>菜单状态</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post" action="/test">
<ul>
{% for food in items %}
<li>{{ food }} </li>
<input type="checkbox" value="12" name="sada">
{% end %}
</ul>
<input type="submit">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>waiter</p>
</body>
</html>
from unittest import TestCase
import requests
class TestIndexHandler(TestCase):
def test_get(self):
rep = requests.get('localhost:8080')
if rep:
print rep
assert 1==1
assert 1==0
from handlers import *
url_patterns = [
(r"/", IndexHandler),
(r"/menu", AddMenuHandler),
(r"/menustatus", MenuStatus),
(r"/test", TestHandler),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment