コード例 #1
0
ファイル: views.py プロジェクト: Zeftiroth/marbles-backend
def create():

    # use @jwt_required and get_jwt_identity() to get the id of the current user. can use it to assign as an id value

    user_id = get_jwt_identity()
    file = request.files.get('image')
    file.filename = secure_filename(file.filename)

    content = request.form.get('caption')

    if not user_id or not file or not content:
        response = {
            'message': 'All field were not provided'
        }
        return jsonify(response), 400

    if not upload_file_to_s3(file):
        return jsonify({'msg': 'upload to s3 failed'}), 400

    post_thread = request.get_json()

    post_thread = Thread(user_id=user_id,
                         template=file.filename, content=content)

    post_thread.save()

    return jsonify({
        'message': 'thread made',
        'user': post_thread.user_id,
        'template': post_thread.template,
        'content': post_thread.content

    }), 200
コード例 #2
0
def create():
    params = request.form

    new_course = Course(title=params.get("course_title"),
                        teacher_id=current_user.id)

    if new_course.save():
        # print("new_course.id",new_course.id)
        new_thread = Thread(course=new_course.id)
        new_thread.save()
        # print("new thread", new_thread.id)
        flash("Successfully Created a Course!", "success")
        return redirect(
            url_for("users.show",
                    username=current_user.username,
                    user_id=current_user.id))  # then redirect to profile page
    else:
        flash(new_course.errors, "danger")
        return redirect(url_for("users.show"))