def show(cid): content = Challenge.show(cid) if not content: return redirect('/') if 'raw' in request.args: cate = request.args.get('raw') if cate == 'description': response = make_response( File(Challenge.model.directory, content.desc).read('rb')) response.headers['Content-Type'] = 'application/pdf' response.headers[ 'Content-Disposition'] = 'inline; filename=%s.pdf' % content.desc return response else: file = File(Challenge.model.directory, getattr(content, cate)) return send_file(join('..', str(file)),\ as_attachment=True, attachment_filename='{}.{}'.format(cate, file.ext)) content = Challenge.package(content) return render( 'challenge.html', **{ 'challenge': Challenge.formatter(content, target=lambda k, v: isinstance(v, datetime), format=lambda v: str(v)[:10]), 'ranking': Challenge.get_rankings(cid, not User.current().TA), 'train': content.get('train'), 'test': content.get('test'), })
def create(): instance = Post.create({ 'title': request.form.get('postTitle'), 'content': request.form.get('postContent'), 'cate': 'notice', 'uid': User.current().id, }) return redirect("/notice/")
def index(): if User.current() == None: flash("Notice: Login Required") return redirect("/") return render('posts.html', uri=str(notice), post_create=User.current().TA, posts=Post.index(cate='notice', pack=False))
def index(): if User.current() == None: flash("QnA: Login Required") return redirect("/") return render('posts.html', uri='qna', post_create=User.current(), posts=Post.index(cate='qna', pack=False))
def submit(cid): try: instance = Submission.create({ 'desc': request.form.get('description'), 'file': request.files.get('file'), 'cid': Challenge.show(cid).id, 'uid': User.current().id, }) except Exception as e: flash(str(e)) return redirect('/challenge/' + cid)
def index(): if User.current() == None: flash("Challenge: Login Required") return redirect("/") return render('challenges.html', challenges=Challenge.formatter( Challenge.index(sort_by=Challenge.model.id, reverse=True), target=lambda k, v: isinstance(v, datetime), format=lambda v: str(v)[:10]), categories=Challenge.model.categories)
def login(): if request.method == 'GET': return render('login.html', user=User.current()) elif request.method == 'POST': studentid = request.form.get('studentid') password = request.form.get('password') try: instance = User.login(studentid, password) except Exception as e: flash(str(e)) return render('login.html') return redirect('/user/')
def create(): try: if request.form.get('challengeTitle') == '': raise Exception("Title can't be blank") instance = Challenge.create({ 'title': request.form.get('challengeTitle'), 'cate': request.form.get('challengeType'), 'start': request.form.get('date-from'), 'due': request.form.get('date-to'), 'desc': request.files.get('desc', ''), 'label': request.files.get('label', ''), 'train': request.files.get('train', ''), 'test': request.files.get('test', ''), }) except Exception as e: flash(str(e)) finally: return redirect("/challenge/")
def logout(): User.logout() return redirect('/login/')
def destroy(uid): instance = User.destroy(uid) return redirect(user)
def create(): instance = User.create(request.get_json()) return redirect(user)
def destroy(nid): instance = Post.delete(nid) return redirect('/')
def destroy(sid): instance = Submission.delete(sid) return redirect('/')
def destroy(cid): instance = Challenge.delete(cid) return redirect('/challenge/')