Ejemplo n.º 1
0
def create_thread(tid):
    """Create a new thread."""
    form = ThreadForm()
    form["csrf_token"].data = request.cookies["csrf_token"]

    if form.validate_on_submit():
        print("form", form.data)
        image_filename = upload_file(form["image"].data)
        thread = Thread(
            tale_id=tid,
            title=form["title"].data,
            description=form["description"].data,
            color=form["color"].data,
            icon=form["icon"].data,
            image=image_filename,
        )
        db.session.add(thread)
        db.session.commit()

        # Creates effects for thread in database
        # effects = createEffects(request.json["effects"], thread)

        # Creates choices for thread in database
        choices = createChoicesFromString(form["choices"].data, thread)

        # Create locks for choices in database
        # locks = createLocks(request.json["locks"], thread)

        return jsonify(thread=thread.to_dict(), choices=choices)
    else:
        return {"errors": validation_errors_to_messages(form.errors)}, 401
Ejemplo n.º 2
0
def create_thread_node(tid):
    """Create a new thread."""
    form = ThreadForm()
    form["csrf_token"].data = request.cookies["csrf_token"]

    if form.validate_on_submit():
        thread = Thread(
            tale_id=tid,
            title="Untitled",
            color="#f9fbefff",
            icon="feather-alt",
        )
        db.session.add(thread)
        db.session.commit()
        return thread.to_dict()
    else:
        return {"errors": validation_errors_to_messages(form.errors)}, 401
Ejemplo n.º 3
0
def create_joke():
    """
    Create new joke
    """
    form = CreateThreadForm()
    form["csrf_token"].data = request.cookies["csrf_token"]

    if form.validate_on_submit():
        new_thread = Thread(
            userId=form.data["userId"],
            jokeId=form.data["jokeId"],
            comment=form.data["comment"],
        )
        db.session.add(new_thread)
        db.session.commit()
        print("----------newthread----", new_thread)
        return new_thread.to_dict()

    errors = validation_errors_to_error_messages(form.errors)

    return {"errors": errors}