def get(self, hid, *args, **kwargs): gp, uid = is_loged(self) if gp == 's': # 仅学生可以删除自己的作业..? homework = get_homework(hid) if not homework: self.render('error.html', title=None, content="作业不存在", icon='ion-sad', active='dsh', id=uid) else: try: if homework['type'] == 'pic': # 作业是图片类型 from submitAssignment import delete_updated from models.security import clean delete_updated(clean(hid)) delete_homework(hid, uid) else: delete_homework(hid, uid) self.redirect('/dash/myHomework') except Exception as e: print e else: self.redirect('/404')
def post(self): gp, uid = is_loged(self) if gp == 't': Iid = infoIdState(self) fname = self.request.files['upload'][0].filename import os dirpath = os.path.dirname(__file__)[:-8] + 'static/notif/' # 生成pic文件名 import random filename = Iid + str(random.randint(99, 1000)) +'.'+ fname.split('.')[-1] while True: cmd = 'find %s -name "%s"' % (dirpath,clean(filename)) if not commands.getstatusoutput(cmd)[1]: break filename = Iid + str(random.randint(99, 1000)) + fname.split('.')[-1] f = self.request.files['upload'][0].body savefile = open(dirpath+filename,'w') savefile.write(f) savefile.close() callback = self.get_argument('CKEditorFuncNum') self.write(''' <script type="text/javascript"> window.parent.CKEDITOR.tools.callFunction("%s","%s",''); </script> ''' % (callback,'/static/notif/'+filename))
def get(self, hid, *args, **kwargs): gp, uid = is_loged(self) if gp == 's': # 仅学生可以删除自己的作业..? homework = get_homework(hid) if not homework: self.render('error.html', title=None, content="作业不存在", icon='ion-sad', active='dsh', id=uid) else: try: if homework['type'] == 'pic': # 作业是图片类型 from submitAssignment import delete_updated from models.security import clean delete_updated(clean(hid)) delete_homework(hid,uid) else: delete_homework(hid,uid) self.redirect('/dash/myHomework') except Exception as e: print e else: self.redirect('/404')
def delete_updated(path, hid): """删除同id的文件""" dirpath = os.path.dirname(__file__)[:-8] + 'static/' + path cmd = 'find %s -name "%s*" | xargs rm' % (dirpath, clean(hid)) # 若没有相同id文件,则命令行会打印奇怪的东西。不是报错 os.system(cmd)
def get_file_path(hid): """获取提交的三视图文件路径""" dirpath = os.path.dirname(__file__)[:-8] + 'static/homework/' comm = "find %s -name '%s*'" % (dirpath, clean(hid)) return commands.getstatusoutput(comm)[1].split('\n')