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)
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)