Example #1
0
File: pages.py Project: tsg-ut/CTFd
def pages_preview():
    # We only care about content.
    # Loading other attributes improperly will cause Marshmallow to incorrectly return a dict
    data = {"content": request.form.get("content")}
    schema = PageSchema()
    page = schema.load(data)
    return render_template("page.html", content=page.data.html)
Example #2
0
    def post(self):
        req = request.get_json()
        schema = PageSchema()
        response = schema.load(req)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        return {'success': True, 'data': response.data}
Example #3
0
    def patch(self, page_id):
        page = Pages.query.filter_by(id=page_id).first_or_404()
        req = request.get_json()

        schema = PageSchema(partial=True)
        response = schema.load(req, instance=page, partial=True)

        if response.errors:
            return {'success': False, 'errors': response.errors}, 400

        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        return {'success': True, 'data': response.data}
Example #4
0
    def post(self, json_args):
        req = json_args
        schema = PageSchema()
        response = schema.load(req)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        clear_pages()

        return {"success": True, "data": response.data}
Example #5
0
def pages_preview():
    data = request.form.to_dict()
    schema = PageSchema()
    page = schema.load(data)
    return render_template('page.html', content=markdown(page.data.content))
Example #6
0
def pages_preview():
    data = request.form.to_dict()
    schema = PageSchema()
    page = schema.load(data)
    return render_template("page.html", content=build_html(page.data.content))