Beispiel #1
0
def create_showtime():
    movie = Movie()
    movies = movie.get_all_movies()
    showroom = Showroom()
    showrooms = showroom.get_all_showrooms()

    if request.method == 'POST':

        date = request.form['date']
        time = request.form['time']
        movie_id = request.form['movie_id']
        showroom_id = request.form['showroom_id']

        # validate all data, everything must be correct
        error = None

        movie = Movie()
        validate_movie = movie.fetch(movie_id)

        # convert date and time into a datetime object
        dtime = create_datetime(date, time)

        if dtime is None:
            error = "Time is invalid"
        elif not validate_showtime_date(dtime):
            error = "Time is in the past"
        elif not validate_movie:
            error = "The selected movie is invalid"
        elif not validate_showroom_availability(showroom_id, 0, dtime,
                                                int(movie.get_duration())):
            error = "The showroom is unavailable at that time"

        if error is None:
            # if error is None, create a showtime
            new_showtime = Showtime()
            showroom = Showroom()
            showroom.fetch(showroom_id)
            movie.set_status('active')
            movie.save()

            new_showtime.create(showroom_id=showroom_id,
                                time=dtime,
                                movie_id=movie_id,
                                available_seats=showroom.get_num_seats())

            # then return to add showtime
            return redirect(url_for('AdminShowtimeController.manage_showtime'))

        flash(error)

    return render_template('make_showtime.html',
                           movies=movies,
                           showrooms=showrooms)
Beispiel #2
0
def manage_movies():
    movie = Movie()

    if request.method == 'POST':
        delete_movie_id = request.form.get('delete_movie_id')
        edit_movie_id = request.form.get('edit_movie_id')

        if delete_movie_id is not None and movie.fetch(delete_movie_id):
            # logic for cancelling tickets will go here?
            if not safe_delete(movie):
                flash(
                    "Movie cannot be deleted when there are bookings for it")
        elif edit_movie_id is not None and movie.fetch(edit_movie_id):
            return redirect(
                url_for('AdminMoviesController.edit_movie', mid=edit_movie_id))

    # get a list of all movies
    movies = movie.get_all_movies()

    return render_template('manage_movies.html', movies=movies)
Beispiel #3
0
def edit_showtime(sid):
    showtime_id = sid
    showtime = Showtime()
    if not showtime.fetch(showtime_id):
        print("Error fetching showtime??")

    movie = Movie()
    movies = movie.get_all_movies()
    movie.fetch(showtime.get_movie_id())
    showroom = Showroom()
    showrooms = showroom.get_all_showrooms()
    showroom.fetch(showtime.get_showroom_id())

    if request.method == 'POST':
        date = request.form.get('date')
        time = request.form.get('time')
        available_seats = request.form.get('available_seats')
        movie_id = request.form.get('movie_id')
        showroom_id = request.form.get('showroom_id')

        print(date)
        print(time)
        print(available_seats)
        print(movie_id)
        print(showroom_id)
        error = None

        dtime = create_datetime(date, time)

        if not validate_showtime_date(dtime):
            error = "The selected showroom is unavailable at that time"
        elif not validate_showroom_availability(showroom.get_id(),
                                                showtime_id, dtime,
                                                int(movie.get_duration())):
            error = "The selected showroom is unavailable at that time"
        else:
            showtime.set_time(dtime)

        if movie_id is not None and not validate_movie(movie_id):
            error = "There was an error processing the movie"
        elif movie_id is not None:
            showtime.set_movie_id(movie_id)

        if showroom_id is not None and not validate_showroom(showroom_id):
            error = "There was an error processing the showroom"
        elif showroom_id is not None:
            showtime.set_showroom_id(showroom_id)

        showtime.save()

        if error is not None:
            flash(error)
        else:
            return redirect(url_for('AdminShowtimeController.manage_showtime'))

    info = showtime.obj_as_dict(showtime_id)
    print("show_dtime")
    print(info['time'])
    show_dtime = create_datetime_from_sql(info['time'])
    return render_template('edit_showtime.html',
                           showtime=info,
                           movie_title=movie.get_title(),
                           showroom_name=showroom.get_showroom_name(),
                           show_dtime=show_dtime,
                           movies=movies,
                           showrooms=showrooms)