Exemple #1
0
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'),
        })
Exemple #2
0
def create():
    instance = Post.create({
        'title': request.form.get('postTitle'),
        'content': request.form.get('postContent'),
        'cate': 'notice',
        'uid': User.current().id,
    })
    return redirect("/notice/")
Exemple #3
0
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))
Exemple #4
0
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))
Exemple #5
0
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)
Exemple #6
0
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)
Exemple #7
0
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/')
Exemple #8
0
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/")
Exemple #9
0
def logout():
    User.logout()
    return redirect('/login/')
Exemple #10
0
def destroy(uid):
    instance = User.destroy(uid)
    return redirect(user)
Exemple #11
0
def create():
    instance = User.create(request.get_json())
    return redirect(user)
Exemple #12
0
def destroy(nid):
    instance = Post.delete(nid)
    return redirect('/')
Exemple #13
0
def destroy(sid):
    instance = Submission.delete(sid)
    return redirect('/')
Exemple #14
0
def destroy(cid):
    instance = Challenge.delete(cid)
    return redirect('/challenge/')