Exemple #1
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 #2
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 #3
0
def show(nid):
    return render('post.html',
                  post_edit=User.current().TA,
                  post=Post.formatter(
                      Post.show(nid, pack=True),
                      target=lambda k, v: k == 'content',
                      format=lambda v: Markup(Post.render_md(v))))
Exemple #4
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 #5
0
def show(nid):
    instance = Post.show(nid)
    return render('post.html',
                  post_edit=instance.user.id == User.current().id,
                  post=Post.formatter(
                      Post.package(instance),
                      target=lambda k, v: k == 'content',
                      format=lambda v: Markup(Post.render_md(v))))
Exemple #6
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 #7
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 #8
0
def profile():
    instance = User.current()
    return render('user.html', submissions=User.submissions())
Exemple #9
0
def show(sid):
    return render('submission.html', submission=Submission.show(sid))