Esempio n. 1
0
def refund_booking(bid):
    # clean up
    # delete all tickets, reset showtime incrementer
    booking = Booking()
    if not booking.fetch(bid):
        return redirect(url_for('IndexController.index'))
    total = booking.get_total_price()

    movie = Movie()
    movie.fetch(booking.get_movie_id())
    movie_title = movie.get_title()

    tickets = booking.get_tickets()
    ticket_count = len(tickets)

    # delete individual ticket objects
    ticket_obj = Ticket()
    for ticket in tickets:
        ticket_obj.delete(ticket['ticket_id'])

    # delete the actual booking object
    showtime = booking.get_showtime_id()
    booking.delete(bid)

    # reset showtime seats
    showtime_obj = Showtime()
    showtime_obj.fetch(showtime)
    showtime_obj.increment_available_seats(ticket_count)
    time = showtime_obj.get_time().strftime('%I:%M %p  :  %B %d, %Y')
    showtime_obj.save()

    # send an email!
    customer = create_user('customer')
    customer.fetch(g.user['username'])
    customer.send_refund_email(movie_title, time, format_price(total))
Esempio n. 2
0
def create_movie():
    if request.method == 'POST':
        title = request.form['title']
        director = request.form['director']
        producer = request.form['producer']
        cast = request.form['cast']
        duration = request.form['duration']
        synopsis = request.form['synopsis']
        rating = request.form['rating']
        category = request.form['category']
        video = request.form['video']
        picture = request.form['picture']

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

        db = get_db()
        if db.execute(
            'SELECT * FROM movie WHERE title = ? ',
            (title,)
        ).fetchone() is not None:
            error = "Movie already exists"
        elif not validate_name(title):
            error = "Movie title is too short or too long"
        elif not validate_name(director):
            error = "Director name is too short or too long"
        elif not validate_name(producer):
            error = "Producer name is too short or too long"
        elif not validate_name(cast):
            error = "Cast name is too short or too long"
        elif not validate_duration(duration):
            error = "Duration must be a whole number"
        elif not validate_text(synopsis):
            error = "Synopsis is too long"
        elif not validate_rating(rating):
            error = "Invalid rating"
        elif not validate_category(category):
            error = "Invalid category"
        elif video.isspace():
            error = "Video link is required"
        elif picture.isspace():
            error = "Picture link is required"

        if error is None:
            # if error is None, create a movie
            new_movie = Movie()
            new_movie.create(title=title, director=director,
                             producer=producer, cast=cast,
                             synopsis=synopsis, picture=picture,
                             video=video,
                             duration_as_minutes=int(duration),
                             rating=rating, category=category)

            # then return to add movie
            return redirect(url_for('AdminMoviesController.manage_movies'))

        flash(error)

    return render_template('make_movie.html')
Esempio n. 3
0
def index():
    movie = Movie()
    current_movies = movie.get_current_movies()
    coming_soon = movie.get_coming_movies()

    return render_template('index.html',
                           current_movies=current_movies,
                           coming_movies=coming_soon)
Esempio n. 4
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)
Esempio n. 5
0
    def check_availability(self, dtime: datetime, timeID, myduration) -> bool:
        showtimes = self.__data_access.get_all_showtimes(self.get_id())
        myID = self.get_id()

        for time in showtimes:
            if (time is not None and time['showroom_id'] == myID
                    and time['showtime_id'] != timeID):

                othermovie = Movie()
                othermovie.fetch(time['movie_id'])

                duration = int(othermovie.get_duration())
                start_time = self.__convert_sql_time(time['time'])
                finish_time = start_time + timedelta(minutes=duration)

                my_start_time = dtime
                my_finish_time = my_start_time + timedelta(minutes=myduration)

                if my_start_time <= finish_time and start_time <= my_finish_time:
                    return False

        return True
def payment_confirmation(bid):

    confirm = False
    if bid[-1] == 'c':
        bid = bid[0:-1]
        confirm = True

    fees = []

    booking = Booking()
    if not booking.fetch(bid):
        return redirect(url_for('IndexController.index'))

    movie = Movie()
    movie = movie.obj_as_dict(booking.get_movie_id())
    showtime = Showtime()
    showtime.fetch(booking.get_showtime_id())
    showroom = Showroom()
    showroom.fetch(showtime.get_showroom_id())

    tkts = booking.get_tickets()
    tickets = []
    for t in tkts:
        t = dict(t)
        t['seat_number'] = format_seat(t['seat_number'])
        tickets.append(t)

    booking = dict(booking.obj_as_dict(bid))
    booking['order_date'] = create_datetime_from_sql(booking['order_date'])
    booking['total_price'] = format_price(booking['total_price'])
    return render_template('confirmation.html',
                           tickets=tickets,
                           fees=fees,
                           movie=movie,
                           showtime=showtime.get_time(),
                           booking=booking,
                           confirm=confirm,
                           showroom=showroom.get_showroom_name())
Esempio n. 7
0
def create_review(mid):
    # tell them what movie it is for
    movie = Movie()
    movie = movie.obj_as_dict(mid)

    if request.method == 'POST':
        rating = request.form['rating']
        title = request.form['title']
        review = request.form['review']

        error = None
        if not validate_duration(rating):
            error = "Rating is invalid"
        elif not validate_name(title):
            error = "Title is invalid"
        elif not validate_text(review):
            error = "Review is invalid"

        if error is None:
            # write it to the db
            customer = create_user('customer')
            # customer login required ensures this will work
            customer.fetch(g.user['username'])
            review_model = Review()
            review_model.create(customer_id=customer.get_id(),
                                movie_id=movie['movie_id'],
                                rating=int(rating),
                                subject=title,
                                review=review)

            return redirect(
                url_for('MovieController.movie_details',
                        mid=movie['movie_id']))

        flash(error)

    return render_template('create_review.html', movie=movie)
Esempio n. 8
0
def process_bookings(bookings):
    refund_info = {}
    refunds = []

    for booking in bookings:
        refund_info['order_no'] = booking['order_id']
        refund_info['total'] = format_price(booking['total_price'])
        refund_info['bid'] = booking['booking_id']

        # get tickets
        booking_obj = Booking()
        booking_obj.fetch(booking['booking_id'])
        tickets = booking_obj.get_tickets()
        refund_info['tickets'] = process_tickets(tickets)

        movie = Movie()
        movie.fetch(booking['movie_id'])
        refund_info['movie_title'] = movie.get_title()

        showtime = Showtime()
        print(showtime.fetch(booking['showtime_id']))
        print(booking['showtime_id'])
        refund_info['date'] = showtime.get_time()
        print(showtime.get_time())

        now = datetime.datetime.now()
        hour = datetime.timedelta(hours=1)
        if now + hour > showtime.get_time():
            refund_info['is_refundable'] = False
        else:
            refund_info['is_refundable'] = True

        refunds.append(dict(refund_info))

    # sort here
    refunds = sorted(refunds, key=lambda k: k['date'], reverse=True)
    return refunds
def search():

    movie = Movie()

    sinput = ''
    dinput = ''
    catinput = ''
    search_args = []
    movies = []


    if request.method == 'POST':
        search_input = request.form.get('search_input')
        category = request.form.get('category')
        if category == 'Any':
            category = ''
        date = request.form.get('date')
        print(search_input)
        search = Search()
        sinput = search_input
        search.set_term(search_input)

        if category is not None:
            search.set_category(category)
            catinput = category.title()

        dinput = date
        search.set_date(date)

        # execute a search
        movies, error = search.execute()

        if error is not None and error != "COMINGSOON":
            flash(error)

    return render_template('search.html',
                           movies=movies,
                           search_input=sinput,
                           date_input=dinput,
                           category_in=catinput)
Esempio n. 10
0
def manage_showtime():
    showtime = Showtime()

    if request.method == 'POST':
        delete_showtime_id = request.form.get('delete_showtime_id')
        edit_showtime_id = request.form.get('edit_showtime_id')

        if delete_showtime_id is not None and showtime.fetch(
                delete_showtime_id):
            # logic for cancelling tickets will go here?
            if not safe_delete(showtime):
                flash("Cannot delete showtime, it has associated bookings")
        elif edit_showtime_id is not None and showtime.fetch(edit_showtime_id):
            return redirect(
                url_for('AdminShowtimeController.edit_showtime',
                        sid=edit_showtime_id))

    # get a list of all showtimes
    showtimes = showtime.get_all_showtimes()
    new_times = []

    for time in showtimes:
        time = dict(time)
        movie = Movie()
        movie.fetch(time['movie_id'])

        showroom = Showroom()
        showroom.fetch(time['showroom_id'])

        time['time'] = create_datetime_from_sql(time['time'])
        time['movie_title'] = movie.get_title()
        time['duration'] = movie.get_duration()
        time['showroom_name'] = showroom.get_showroom_name()

        new_times.append(time)

    # show newest times first
    new_times = sorted(new_times, key=lambda k: k['time'])

    return render_template('manage_showtime.html', showtimes=new_times)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
def validate_movie(movie_id):
    movie = Movie()
    return movie.fetch(movie_id)
Esempio n. 14
0
def edit_movie(mid):
    movie_id = mid
    movie = Movie()
    print(movie.fetch(movie_id))

    if request.method == 'POST':
        title = request.form.get('title')
        director = request.form.get('director')
        producer = request.form.get('producer')
        cast = request.form.get('cast')
        duration = request.form.get('duration')
        synopsis = request.form.get('synopsis')
        rating = request.form.get('rating')
        category = request.form.get('category')
        video = request.form.get('video')
        picture = request.form.get('picture')

        error = None
        print(title)
        if title != '' and not validate_name(title):
            error = "Movie title is too short or too long"
        elif title != '':
            movie.set_title(title)

        if director != '' and not validate_name(director):
            error = "Director name is too short or too long"
        elif director != '':
            movie.set_director(director)

        if producer != '' and not validate_name(producer):
            error = "Producer name is too short or too long"
        elif producer != '':
            movie.set_producer(producer)

        if cast != '' and not validate_name(cast):
            error = "Cast name is too short or too long"
        elif cast != '':
            movie.set_cast(cast)

        if duration != '' and not validate_duration(duration):
            error = "Duration must be a whole number"
        elif duration != '':
            movie.set_duration(int(duration))

        if synopsis != '' and not validate_text(synopsis):
            error = "Synopsis is too long"
        elif synopsis != '':
            movie.set_synopsis(synopsis)

        if rating is not None and not validate_rating(rating):
            error = "Invalid rating"
        elif rating is not None:
            movie.set_rating(rating)

        if category is not None and not validate_category(category):
            error = "Invalid category"
        elif category is not None:
            movie.set_category(category)

        if video != '' and video.isspace():
            error = "Video link is required"
        elif video != '':
            movie.set_video(video)

        if picture != '' and picture.isspace():
            error = "Picture link is required"
        elif picture != '':
            movie.set_picture(picture)

        movie.save()

        if error is not None:
            flash(error)

    info = movie.obj_as_dict(movie_id)
    return render_template('edit_movie.html', movie=info)
Esempio n. 15
0
def movie_details(mid):
    print(mid)

    clear_all_booking()

    movie = Movie()
    movie_dict = {}
    if movie.fetch(mid):
        movie_dict = movie.obj_as_dict(mid)
        movie_dict = dict(movie_dict)

        showtimes = movie.get_all_showtimes()
    else:
        return render_template('index.html')

    showtimes_list = []
    for showtime in showtimes:
        showtime = dict(showtime)
        showtime['time'] = create_datetime_from_sql(showtime['time'])
        if validate_showtime(showtime['available_seats'], showtime['time']):
            showtimes_list.append(showtime)

    showtimes_list = sorted(showtimes_list, key=lambda k: k['time'])

    # for each review
    review_model = Review()

    if request.method == 'POST':
        review_id = request.form.get('review_id')
        if review_id != '':
            review_model.delete(review_id)

        showtime_id = request.form.get('showtime')
        if showtime_id != '':
            session['showtime'] = showtime_id
            print("showtime")
            print(showtime_id)
            return redirect(url_for('SeatSelectionController.select_seat'))

    reviews = review_model.get_all_reviews_by_movie(mid)
    display_reviews = []
    ratings = []
    average = None
    if len(reviews) > 0:
        for review in reviews:
            rvw = dict(review)
            rvw['name'] = review_model.get_customer_name(rvw['customer_id'])
            ratings.append(int(rvw['rating']))
            print(rvw['name'])
            display_reviews.append(rvw)
        average = sum(ratings) / len(ratings)
    else:
        rev = {
            'title':
            "There's no reviews yet?",
            'name':
            "E-Cinema Booking Team",
            'rating':
            5,
            'review':
            "There are no reviews for this movie yet. You can click on the review movie button below to be the first!"
        }
        display_reviews.append(rev)

    return render_template('single-product.html',
                           movie=movie_dict,
                           showtimes=showtimes_list,
                           is_current=len(showtimes) > 0,
                           reviews=display_reviews,
                           average=average)
Esempio n. 16
0
def checkout():

    if (not session.get('showtime') or
        not session.get('tickets') or
            not g.user.get('username')):
        return redirect(url_for('IndexController.index'))

    if request.method == 'POST':
        delete_id = request.form.get('delete_ticket')

        if request.form.get('coupon'):
            promo = Promo()
            session['promo'], error = apply_promo(promo)
            if error is not None:
                flash(error)
        elif delete_id:
            if not delete_ticket(delete_id):
                return redirect(url_for('BookingController.cancel_booking'))
        elif request.form.get('add_payment'):
            session['checkout'] = True
            return redirect(url_for('AccountController.make_payment'))
        elif request.form.get('checkout'):
            if request.form.get('card_id'):
                bid = create_booking_objects()
                clear_booking_info()
                return redirect(
                    url_for('BookingController.payment_confirmation', bid=bid))
            else:
                flash("Please choose a payment card to proceed with checkout")
        elif request.form.get('cancel'):
            clear_booking_info()
            return redirect(url_for('IndexController.index'))

    customer = create_user('customer')
    customer.fetch(g.user['username'])
    cards = customer.get_all_cards()

    showtime = Showtime()
    showtime.fetch(session['showtime'])

    movie = Movie()
    movie.fetch(showtime.get_movie_id())

    tickets, subtotal = clean_tickets(session['tickets'])

    # Returns a 2D array of tickets
    # each list is a different type
    all_tickets = get_ticket_type_lists(tickets)

    fees, total = calculate_fees_and_total(subtotal)
    session['total'] = total

    total = format_price(total)
    subtotal = format_price(subtotal)

    return render_template('checkout.html',
                           showtime=showtime.get_time(),
                           movie=movie.obj_as_dict(movie.get_id()),
                           tickets=all_tickets,
                           subtotal=subtotal,
                           total=total,
                           fees=fees,
                           cards=cards)
Esempio n. 17
0
def get_movie_by_showtime(sid):
    movie = Movie()
    showtime = Showtime()
    showtime.fetch(sid)
    movie.fetch(showtime.get_movie_id())
    return movie