雪-幽幽 2016-04-17 07:36
浏览 651

一个小的python作业系统,看不懂,急求大神指点

主要就是可以发布作业,查看提交作业的系统,是后台的程序
#!/usr/bin/env python

-*- coding: utf-8 -*-

import os.path
import sys
import time

import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)

reload(sys)
sys.setdefaultencoding('utf-8')

DATA = os.path.join(os.path.dirname(__file__), "static", "data.txt")
NOW = time.strftime('%Y-%m-%d %X', time.localtime(time.time()))

def timecmp(a, b):
return (time.strptime(a, '%Y-%m-%d %X') > time.strptime(b, '%Y-%m-%d %X'))

with open(DATA, 'r') as fr:
data = [line.strip().split(';') for line in fr.readlines()]

class IndexHandler(tornado.web.RequestHandler):
"""docstring for IndexHandler"""
def get(self):
search = self.get_argument('seclass', "")
global data
data_filter = [ele for ele in data if ele[1]==search]
#compare current time
data1 = [i for i in data_filter if not timecmp(NOW, i[3])]
data2 = [i for i in data_filter if timecmp(NOW, i[3])]
#sort
data1=sorted(data1, key=lambda x: time.strptime(x[3], '%Y-%m-%d %X'))
data2=sorted(data2, key=lambda x: time.strptime(x[3], '%Y-%m-%d %X'), reverse=True)
self.render('yourhomework.html', data1=data1, data2=data2, search=search)
def post(self):
cname = self.get_argument('classname', "")
cnumber = self.get_argument('classnumber', "")
detail = self.get_argument('hwdetail', "")
year = self.get_argument('year', "")
month = self.get_argument('month', "")
day = self.get_argument('day', "")
hour = self.get_argument('hour', "")
if (cname=="" or cnumber=="" or detail=="" or year=="" or month=="" or day=="" or hour==""):
self.redirect('/yourhomework.html')
else:
new_hw = [cname, cnumber, detail, year+"-"+month+"-"+day+" "+hour+":00"]
flag = True
global data
for ele in data:
if (ele==new_hw):
flag = False
if (flag):
data.append(new_hw)
data_filter = [ele for ele in data if ele[1]==cnumber]
data1 = [i for i in data_filter if not timecmp(NOW, i[3])]
data2 = [i for i in data_filter if timecmp(NOW, i[3])]
data1=sorted(data1, key=lambda x: time.strptime(x[3], '%Y-%m-%d %X'))
data2=sorted(data2, key=lambda x: time.strptime(x[3], '%Y-%m-%d %X'), reverse=True)
self.render('yourhomework.html', data1=data1, data2=data2, search=cnumber)

if name == '__main__':
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[(r"/", IndexHandler), (r"/yourhomework.html", IndexHandler)],
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True
)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()


  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料