def create_app():
    instance = Flask(__name__)
    instance.config.from_object(Config)

    Swagger(template=TEMPLATE).init_app(instance)
    Router().init_app(instance)
    Mongo().init_app(instance)

    return instance
def create_app(config: Config):
    app_ = Flask(__name__)
    app_.config.from_object(config)

    db.init_app(app_)
    jwt.init_app(app_)
    cors.init_app(app_)

    with app_.app_context():
        from app import model
        db.create_all()

    from app.view import Router
    Swagger(template=TEMPLATE).init_app(app_)
    Router().init_app(app_)

    return app_
Beispiel #3
0
from app import app
from app.view import Router
from app.view import request, render, redirect, flash, jsonify
from app.controller import User
from app.controller import Submission

user = Router('user')


@User.require_login
@user.route('/', methods=['GET'])
def profile():
    instance = User.current()
    return render('user.html', submissions=User.submissions())


@User.require_permission
@user.route('/', methods=['POST'])
def create():
    instance = User.create(request.get_json())
    return redirect(user)


@user.route('/', methods=['PUT'])
def change():
    response = {'status': 'ok'}
    try:
        User.update(**request.get_json())
    except Exception as e:
        response.update({'status': 'failed', 'error': str(e)})
    return jsonify(response)
Beispiel #4
0
from datetime import datetime

from app import app
from app.view import Router
from app.view import request, render, redirect, flash, Markup
from app.controller import Post
from app.controller import User

notice = Router('notice', template_folder='../templates/post')


@notice.route('/', methods=['GET'])
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))


@User.require_permission
@notice.route('/', methods=['POST'])
def create():
    instance = Post.create({
        'title': request.form.get('postTitle'),
        'content': request.form.get('postContent'),
        'cate': 'notice',
        'uid': User.current().id,
    })
Beispiel #5
0
from app import app
from app.view import Router
from app.view import request, render, redirect, flash
from app.controller import Submission

submission = Router('submission')

@submission.route('/<sid>', methods=['GET'])
def show(sid):
    return render('submission.html', submission=Submission.show(sid))


@submission.route('/<sid>', methods=['DELETE'])
def destroy(sid):
    instance = Submission.delete(sid)
    return redirect('/')

Beispiel #6
0
from datetime import datetime

from app import app
from app.view import Router
from app.view import request, render, redirect, flash, Markup
from app.controller import Post
from app.controller import User

qna = Router('qna', template_folder='../templates/post')


@qna.route('/', methods=['GET'])
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))


@User.require_login
@qna.route('/', methods=['POST'])
def create():
    instance = Post.create({
        'title': request.form.get('postTitle'),
        'content': request.form.get('postContent'),
        'cate': 'qna',
        'uid': User.current().id,
    })
Beispiel #7
0
from os.path import join
from datetime import datetime

from flask import make_response, send_file

from app import app
from app.lib.file import File
from app.view import Router
from app.view import request, render, redirect, flash, jsonify
from app.controller import User
from app.controller import Submission
from app.controller import Challenge

challenge = Router('challenge')


@challenge.route('/', methods=['GET'])
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)


@User.require_permission