Created
April 6, 2017 09:11
-
-
Save dogewzy/4f6d942ef00bd37a1611519c23fe3d7d to your computer and use it in GitHub Desktop.
graduation design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="ProjectDictionaryState"> | |
<dictionary name="wzy"> | |
<words> | |
<w>lucai</w> | |
<w>tablename</w> | |
</words> | |
</dictionary> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from handlers.auth import IndexHandler | |
from handlers.waiter import * | |
from handlers.test import TestHandler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, '???') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from model.models import People, Menu, Food | |
__all__ = [ | |
'People', 'Menu', 'Food' | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from model.db import Base, engine | |
Base.metadata.reflect(engine) # 将数据映射绑定到引擎 | |
Base.metadata.create_all(engine) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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:[email protected]: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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tornado | |
PyMySQL==0.7.4 | |
requests==2.10.0 | |
redis==2.10.5 | |
# Docs | |
Jinja2==2.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Admin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<p>chief</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>flase</title> | |
</head> | |
<body> | |
<p>false</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<p>waiter</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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