def post(self): subject=self.get_argument('subject') student=self.get_argument('student',default="") s=Subject.objects(id=ObjectId(subject)).first() if not s: return self.write({'err':'课题不存在'}) if s.professor.username!=self.current_user.username: return self.write({'err':'不是你的课题'}) if s.selected_by==[]: return self.write({'err':'不可改选上阶段选好的课题'}) # Clear previous approvement if s.applied_to: u=Student.objects(username=s.applied_to.username).first() u.applied_to=None u.save() s.applied_to=None if student: for u_embedded in s.selected_by: u=Student.objects(username=u_embedded.username).first() if u.username==student: # You are the one! s.applied_to=u u.applied_to=s u.save() s.save() self.write({})
def post(self): subject=self.get_argument('subject') student=self.get_argument('student') s=Subject.objects(id=ObjectId(subject)).first() if not s: return self.write({'err':'课题不存在'}) if s.applied_to: return self.write({'err':'课题已被分配给'+s.applied_to.realname.encode('utf-8')}) u=Student.objects(username=student).first() if not u: return self.write({'err':'学生不存在'}) if u.applied_to: return self.write({'err':'学生已被分配'+u.applied_to.name.encode('utf-8')+'课题'}) # Match Straightly s.selected_by=[] s.applied_to=u u.selected=None u.applied_to=s s.save() u.save() self.write({})
def get(self): student=self.get_argument('student',"") u=Student.objects(username=student).first() if not u or not u.resume: raise HTTPError(404) # Guess browser and write Content-Disposition # FIXME: an ugly hack here due to a MongoEngine bug # must use `u.resume.name' for filename while write using `filename' # FIXME: filename will break on android with its internal browser e=quote(u.resume.name.encode('utf-8')).replace('+','%20') ua=self.request.headers['User-Agent'].lower() if "msie" in ua: cd='filename="%s"'%e elif "firefox" in ua: cd="filename*=UTF-8''%s"%e else: cd='filename="%s"'%u.resume.name self.set_header('Content-Disposition','attachment;'+cd) self.set_header('Content-Type','application/octet-stream') self.write(u.resume.read())