Exemplo n.º 1
0
def create():
    """Create a new event."""
    if request.method == 'POST':
        new_event_title = request.form.get('title')
        new_event_description = request.form.get('description')
        date = request.form.get('date')
        time = request.form.get('time')

        try:
            date_and_time = datetime.strptime(
                f'{date} {time}',
                '%Y-%m-%d %H:%M')
        except ValueError:
            print('there was an error: incorrect datetime format')

        # TODO: Create a new event with the given title, description, & 
        # datetime, then add and commit to the database
        new_event = Event(title=new_event_title, description=new_event_description, date_and_time=date_and_time)
        db.session.add(new_event)
        db.session.commit()

        flash('Event created.')
        return redirect(url_for('main.index'))
    else:
        return render_template('create.html')
Exemplo n.º 2
0
def add_event():
    """Add event to Event table."""
    try:
        new_event_title = request.form.get("title")
        new_event_description = request.form.get("description")
        new_event_date = datetime.strptime(request.form.get("date"),
                                           "%m-%d-%Y")
        new_event_time = datetime.strptime(request.form.get("time"), "%H:%M")

        event = Event(
            title=new_event_title,
            description=new_event_description,
            date=new_event_date,
            time=new_event_time,
            guests=[],
        )

        db.session.add(event)
        db.session.commit()
        return (
            jsonify({
                "msg": "Event added successfully",
                "data": event
            }),
            200,
        )
    except ValueError:
        return jsonify({
            "msg":
            """
                Something went wrong, please verify that you've entered
                everything in the correct format and try again.
                """
        })
Exemplo n.º 3
0
def create():
    """Create a new event."""
    if request.method == "POST":
        new_event_title = request.form.get("title")
        new_event_description = request.form.get("description")
        date = request.form.get("date")
        time = request.form.get("time")

        try:
            date_and_time = datetime.strptime(f"{date} {time}",
                                              "%Y-%m-%d %H:%M")
        except ValueError:
            print("there was an error: incorrect datetime format")

        new_event = Event(
            title=new_event_title,
            description=new_event_description,
            date_and_time=date_and_time,
        )
        db.session.add(new_event)
        db.session.commit()

        flash("Event created.")
        return redirect(url_for("main.index"))
    else:
        return render_template("create.html")
def add_event():
    """Add event to Event table."""
    try:
        new_event_title = request.form.get("title")
        new_event_description = request.form.get("description")
        new_event_date = datetime.strptime(request.form.get("date"),
                                           "%m-%d-%Y")
        new_event_time = datetime.strptime(request.form.get("time"), "%H:%M")

        event = Event(
            title=new_event_title,
            description=new_event_description,
            date=new_event_date,
            time=new_event_time,
            guests=[],
        )

        db.session.add(event)
        db.session.commit()
        return redirect(url_for("main.homepage"))
    except ValueError:
        return redirect(url_for("main.homepage"))
Exemplo n.º 5
0
def create():
    """Create a new event."""
    if request.method == 'GET':
        return render_template('create.html')

    title = request.form.get('title')
    description = request.form.get('description')
    date = request.form.get('date')
    time = request.form.get('time')

    try:
        date_and_time = datetime.strptime(f'{date} {time}', '%Y-%m-%d %H:%M')
    except ValueError:
        print('there was an error: incorrect datetime format')

    new_event = Event(title=title,
                      description=description,
                      date_and_time=date_and_time)
    db.session.add(new_event)
    db.session.commit()

    flash("Event created.")

    return redirect(url_for('main.index'))