def training(label=None, desc=[], log=[]): data = [] m = re.match('(\S+)_(\d+)$', label) model, signature = m.group(1), m.group(2) cmd = 'kubectl get pods -l model={},signature=s{}'.format(model, signature) output = check_output(cmd.split()).decode('ascii') if output: for line in output.split('\n'): if line and line.strip(): data.append(line.split()[:3]) data.pop(0) forms = StopForm(prefix='forms') if forms.validate_on_submit(): try: cmd = 'kubectl delete -f {}/train/{}/records/train.yaml'.format( os.environ['SHARED_HOST'], label) os.system(cmd) update_training(label, 'RUNNING') flash('Training Label {} scheduled to stop'.format(label)) except: flash('Failed to stop training label {}'.format(label)) return redirect(url_for('trainings', type='active')) formd = ShowForm(prefix='formd') if formd.validate_on_submit(): name = request.form['name'] try: cmd = 'kubectl describe pod {}'.format(name) desc = check_output(cmd.split()).decode('ascii').split('\n') except: desc = [ 'Oops, getting errors while retrieving descriptions', 'Maybe the conainer is not ready or teminated?' ] forml = ShowForm(prefix='forml') if forml.validate_on_submit(): name = request.form['name'] cmd = 'kubectl logs {}'.format(name) try: log = check_output(cmd.split()).decode('ascii').split('\n') except: log = [ 'Oops, getting error while retrieving logs', 'Maybe the job is not ready or terminated?' ] return render_template('training.html', label=label, data=data, forms=forms, formd=formd, forml=forml, desc=desc, log=log)
def create_show_submission(): form = ShowForm(request.form, meta={'csrf': False}) if form.validate_on_submit(): error = False print(form.artist_id.data.artistId()) try: show = Show(artist_id=form.artist_id.data.artistId(), ven_id=form.venue_id.data.venId(), start_time=form.start_time.data) db.session.add(show) db.session.commit() except BaseException as ee: print(ee) db.session.rollback() error = True finally: db.session.close() if error: flash('Error While Insert') else: flash('Show was successfully listed!') else: flash('Error ' + 'Missing Some Input') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead # on successful db insert, flash success show_form = ShowForm() artist_id = show_form.artist_id.data venue_id = show_form.venue_id.data start_time = show_form.start_time.data show = Shows.insert().values(artist_id=artist_id, venue_id=venue_id, start_time=start_time) try: db.session.execute(show) db.session.commit() flash("Show was successfully listed!") except Exception as e: flash("An error occurred. Show could not be listed.") db.session.rollback() db.session.flush() print(e) # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return render_template("pages/home.html")
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ form = ShowForm(request.form, meta = {'csrf': False}) if form.validate(): try: show = Show() form.populate_obj(show) db.session.add(show) db.session.commit() flash('Show was successfully listed!') except ValueError as e: print(e) flash('Error in listing show. Please try again.') db.session.rollback() finally: db.session.close() else: err_msg = [] for field, err in form.errors.items(): err_msg.append(field + '-' + '|'.join(err)) flash('Errors: ' + str(err_msg)) return render_template('pages/home.html')
def create_show_submission(): error = False form = ShowForm() try: if form.validate_on_submit(): v_id = int(form.venue_id.data) show = Show(date_time=form.start_time.data, venue_id=v_id) db.session.add(show) db.session.commit() artist = Artist.query.get(form.artist_id.data) venue = Venue.query.get(v_id) show.artists.append(artist) venue.shows.append(show) db.session.add(venue) db.session.commit() flash('Show was successfully listed on {}!'.format( form.start_time.data)) return redirect(url_for('index')) flash('An error occurred. Show could not be listed. {}'.format( form.errors)) except (): db.session.rollback() error = True print(sys.exc_info()) finally: db.session.close() if error: abort(500) flash('There was an error, please try again.') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm() error = False try: if form.validate_on_submit(): show = Show(start_time=form.start_time.data, venue_id=form.venue_id.data, artist_id=form.artist_id.data) db.session.add(show) db.session.commit() except Exception as e: print('create_show_submission: ', e) db.session.rollback() print(sys.exc_info()) error = True finally: db.session.close() if error: flash('Oh!, an error occurred. Show could not be listed.') return render_template('forms/new_show.html', form=form) else: flash('Yaaay, Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) error = False print("About to go into Show creation") try: print("Instantiating Show") data = Show( name=form.name.data, venue_id=form.venue_id.data, artist_id=form.artist_id.data, start_time=form.start_time.data ) print("Adding to database") db.session.add(data) print("Committing data") db.session.commit() print("Persisted data") # TODO: modify data to be the data object returned from db insertion flash('Show ' + request.form['name'] + ' was successfully listed!') except Exception as e: print(("Rolling back transaction")) print(e) print(e.args) error = True db.session.rollback() # TODO: on unsuccessful db insert, flash an error instead. flash('An error occurred. Show ' + data.name + ' could not be listed.') return render_template('pages/home.html') print(sys.exc_info()) finally: print("Closing session") db.session.close() return render_template('pages/home.html')
def create_show_submission(): # validate form form = ShowForm(request.form) if not form.validate(): return render_template('forms/new_show.html', form=form) # create show error = False try: show = Show() show.venue_id = request.form.get('venue_id', '') show.artist_id = request.form.get('artist_id', '') show.start_time = request.form.get('start_time', '') db.session.add(show) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash('Show could not be listed.') else: flash('Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): show_data = ShowForm(request.form) error = False try: # Create new db Show record new_show = Show( artist_id=show_data.artist_id.data, venue_id=show_data.venue_id.data, start_time=show_data.start_time.data ) db.session.add(new_show) db.session.commit() except: error = True db.session.rollback() print(sys.exc_info()) finally: if not error: flash("Show was successfully listed!") else: flash("An error occurred. Show could not be listed.") db.session.close() return redirect(url_for('index'))
def create_shows(): data = { 'venue_id': request.args.get('venue_id', ''), 'artist_id': request.args.get('artist_id', '') } form = ShowForm(data=data) return render_template('forms/new_show.html', form=form)
def show_venue(venue_id): # get by id venue = Venue.query.get(venue_id) # venue data data = venue.get_data() # show to dict def get_show_dict(show): return { "artist_id": show.artist.id, "artist_name": show.artist.name, "artist_image_link": show.artist.image_link, "start_time": show.start_time.strftime("%Y-%m-%d %H:%M:%S") } # past_shows past_shows = venue.get_past_shows() data['past_shows_count'] = len(past_shows) data['past_shows'] = [] for show in past_shows: data['past_shows'].append(get_show_dict(show)) # upcoming shows upcoming_shows = venue.get_upcoming_shows() data['upcoming_shows_count'] = len(upcoming_shows) data['upcoming_shows'] = [] for show in upcoming_shows: data['upcoming_shows'].append(get_show_dict(show)) showForm = ShowForm() return render_template('pages/show_venue.html', venue=data, showForm=showForm)
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead form = ShowForm() created = False if form.validate_on_submit(): try: new_show = Show(start_time=form.start_time.data) new_show.venue = form.venue.data new_show.artist = form.artist.data db.session.add(new_show) db.session.commit() # on successful db insert, flash success created = True flash("Show was successfully listed!") except: print(sys.exc_info()) finally: db.session.close() if created: return redirect(url_for("index")) # TODO: on unsuccessful db insert, flash an error instead. flash("An error occurred. Show could not be listed.") return render_template("forms/new_show.html", form=form)
def create_show_submission(): form = ShowForm() error = False try: if form.validate_on_submit(): show = Show( artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data ) db.session.add(show) db.session.commit() except Exception as e: print('create_show_submission: ', e) db.session.rollback() print(sys.exc_info()) error = True finally: db.session.close() # on successful db insert, flash success if error: # on successful db insert, flash success # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ flash('An error occurred. Show could not be listed.') return render_template('forms/new_show.html', form=form) else: flash('Show was successfully listed!') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form error = False data = {} form = ShowForm() # if form.validate_on_submit(): try: artist_id = request.form['artist_id'] venue_id = request.form['venue_id'] start_time = request.form['start_time'] # TODO: insert form data as a new Show record in the db, instead show = Show( artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() # TODO: modify data to be the data object returned from db insertion data['artist_id'] = show.artist_id data['venue_id'] = show.venue_id data['start_time'] = show.start_time except: db.session.rollback() print(sys.exc_info()) error = True finally: db.session.close() # on successful db insert, flash success if error == False: flash('Show was successfully listed!') return render_template('pages/home.html') # TODO: on unsuccessful db insert, flash an error instead. else: flash('An error occurred. Show could not be listed.','error') return render_template('forms/new_show.html', form=form)
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # insert form data as a new Show record in the db, instead # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ form = ShowForm(request.form, meta={"csrf": False}) if form.validate_on_submit(): try: show: Show = Show() form.populate_obj(show) db.session.add(show) db.session.commit() # on successful db insert, flash success flash(f"Show {request.form['name']} was successfully listed!") except ValueError as e: print(sys.exc_info()) db.session.rollback() # on unsuccessful db insert, flash an error instead. flash(f"An error occurred: {str(e)}") finally: db.session.close() else: error_msg = [] for field, error in form.errors.items(): error_msg.append(f"{field}: {str(error)}") flash(f"Error occurred: {str(error_msg)}") return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # DONE: insert form data as a new Show record in the db, instead form = ShowForm() error = False artist_id = form.artist_id.data venue_id = form.venue_id.data start_time = form.start_time.data print(venue_id) try: show = Show(start_time=start_time, artist_id=artist_id, venue_id=venue_id) db.session.add(show) db.session.commit() except: db.session.rollback() print(sys.exc_info()) error = True finally: db.session.close() if error: flash('An error occurred. Show could not be listed.') else: flash('Show was successfully listed!') # on successful db insert, flash success # DONE: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return render_template('pages/home.html')
def create_show_submission(): error = False form = ShowForm(request.form) if not form.validate_on_submit(): flash('An error occurred. Show could not be listed.') return render_template('pages/home.html') # noinspection PyBroadException try: artist_id = request.form['artist_id'] venue_id = request.form['venue_id'] start_time = request.form['start_time'] show = Show(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() except Exception: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash('An error occurred. Show could not be listed.') if not error: flash('Show was successfully listed') return render_template('pages/home.html')
def create_show_submission(): # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead form = ShowForm(request.form) try: form.validate() show = Show( start_time=form.start_time.data, venue_id=form.venue_id.data, artist_id=form.artist_id.data, ) db.session.add(show) db.session.commit() # on successful db insert, flash success flash('Show was successfully listed!') except Exception as e: print(e) # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ db.session.rollback() flash('An error occurred. Show could not be listed.') finally: db.session.close() return render_template('pages/home.html')
def create_shows(): # renders form. do not touch. artist_choices = db.session.query( Artist.id, Artist.name).distinct().all() venue_choices = db.session.query(Venue.id, Venue.name).distinct().all() form = ShowForm(artist_choices, venue_choices) return render_template('forms/new_show.html', form=form)
def create_show_submission(): try: show = Show() form = ShowForm(request.form) show = populateObjectFromForm(show, form) if (show.end_time == None): print("Info: No end time submitted - adding default") show.end_time = show.start_time + default_booking_slot_duration print("end time: ", show.end_time) if not isShowWithinArtistAvailibility(show): raise ArtistUnavailable db.session.add(show) db.session.commit() flash('Show was successfully listed!') except ArtistUnavailable: db.session.rollback() flash( 'An error occurred. Artist is not available during requested booking slot. Show could not be listed.' ) except: print(sys.exc_info()) db.session.rollback() flash('An error occurred. Show could not be listed.') finally: db.session.close() return redirect(url_for('index'))
def create_show_form(): """Displays the form for creating a show. Returns: A html template for the show form """ form = ShowForm() return render_template("forms/new_show.html", form=form)
def create_shows(): form = ShowForm() artists = Artist.query.all() artistsSelect = [(artist.id, artist.name) for artist in artists] venues = Venue.query.all() venuesSelect = [(venue.id, venue.name) for venue in venues] form.artists.choices = artistsSelect form.venue_id.choices = venuesSelect return render_template('forms/new_show.html', form=form)
def create_show_submission(): """Creates a new show in the db from a form submission. Returns: A redirect to the shows page """ form = ShowForm() if not form.validate(): flash( list(form.errors.values())[0][0], "error", ) return redirect(url_for("create_show_form")) error = False try: venue_id = request.form.get("venue_id") artist_id = request.form.get("artist_id") start_time = request.form.get("start_time") unavailabilities = Unavailability.query.filter_by( artist_id=artist_id).all() for unavailability in unavailabilities: if (str(unavailability.start_time) > start_time < str( unavailability.end_time)): flash("Artist is unavailable at selected time") return redirect(url_for("create_show_form")) show = Show(venue_id=venue_id, artist_id=artist_id, start_time=start_time) db.session.add(show) db.session.commit() except Exception: # pylint: disable=broad-except error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: flash("Show was unable to be listed!", "error") abort(500) flash("Show was successfully listed!") return redirect(url_for("shows"))
def create_shows(): form = ShowForm() if (request.method == 'POST'): # check if artist, venue, artistxvenuxstart_time exist artist_id = form.artist_id.data existartist = Artist.query.filter_by(id=artist_id).first() if existartist is None: flash("Artist not exists.") return render_template('forms/new_show.html', form=form) venue_id = form.venue_id.data existvenue = Venue.query.filter_by(id=venue_id).first() if existvenue is None: flash("Venue not exists.") return render_template('forms/new_show.html', form=form) start_time = form.start_time.data print(start_time) existshow = Show.query.filter_by(venue_id=venue_id, artist_id=artist_id, start_time=start_time).first() if existshow is not None: flash("Show exists.") return render_template('forms/new_show.html', form=form) error = False body = {} try: artist_id = request.form.get('artist_id') venue_id = request.form.get('venue_id') start_time = request.form.get('start_time') print(start_time) show = Show(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() except Exception as e: error = True print(e) db.session.rollback() finally: db.session.close() if not error: flash('Show ' + ' was successfully listed!') return redirect(url_for('shows')) else: flash('An error occurred. Show could not be listed.') return render_template('errors/500.html') # if request method is GET then generate form return render_template('forms/new_show.html', form=form)
def create_show_submission(): """ Received POSTed form data for a new show and saves those details in the database Returns user to index.html """ # called to create new shows in the db, upon submitting new show listing form # TODO: insert form data as a new Show record in the db, instead form = ShowForm() if form.validate(): artist_id = form.artist_id.data venue_id = form.venue_id.data start_time = form.start_time.data # Isolate hour from desired show time start_time_only = str(start_time).split(' ')[1] start_time_hour = int(start_time_only[0] + start_time_only[1]) # Get start and end hours for artist availability artist = Artist.query.get(artist_id) available_from = 0 available_to = 23 available_hours = artist.available_hours if available_hours: available_from = int(available_hours.split('-')[0]) available_to = int(available_hours.split('-')[1]) # If show time falls in Artist available hours, or no available hours were specified for the artist, try to list the show if (start_time_hour >= available_from) and (start_time_hour <= available_to): try: show = Show(artist_id=artist_id, venue_id=venue_id, start_time=start_time) db.session.add(show) db.session.commit() flash('Show was successfully listed!') # TODO: insert form data as a new Venue record in the db, instead # TODO: modify data to be the data object returned from db insertion except Exception as e: db.session.rollback() flash('ERROR: Show not created!') finally: db.session.close() else: flash("Artist not avaiable at that time") # TODO: on unsuccessful db insert, flash an error instead. # e.g., flash('An error occurred. Show could not be listed.') # see: http://flask.pocoo.org/docs/1.0/patterns/flashing/ return redirect(url_for('index'))
def create_show_submission(): form = ShowForm(request.form) try: show = Show() form.populate_obj(show) db.session.add(show) db.session.commit() flash('Show was successfully listed!') except: db.session.rollback() flash('An error occurred. Show could not be listed.') raise finally: db.session.close() return render_template('pages/home.html')
def edit_show_submission(id): form = ShowForm(request.form) artist = Artist.query.get(form.artist_id.data) venue = Venue.query.get(form.venue_id.data) result = update( db, Show, id, { "artist_id": form.artist_id.data, "artist_name": artist.name, "artist_image_link": artist.image_link, "venue_id": form.venue_id.data, "venue_name": venue.name, "venue_image_link": venue.image_link, "start_time": form.start_time.data }, 'Successfully updated show!', 'Error with updating show.') flash(result) return render_template('pages/home.html')
def create_show_submission(): """ Submit callback for show form """ # Get the form data artist_id = request.form['artist_id'] venue_id = request.form['venue_id'] start_time = request.form['start_time'] form = ShowForm() # Validate form data if not form.validate_on_submit(): flash(form.errors) # Redirect to the new_show.html page with the error message in the above line return redirect(url_for('create_show_submission')) error = False venue = Venue.query.get(venue_id) artist = Artist.query.get(artist_id) # Check if the venue id exists or not. if venue is None: flash('The venue id ' + venue_id + ' does not exist') return redirect(url_for('create_show_submission')) # Check if the artist id exists or not. if artist is None: flash('The artist id ' + artist_id + ' does not exist') return redirect(url_for('create_show_submission')) try: # Create Show instance using form data show = Show(venue_id=venue_id, artist_id=artist_id, start_time=start_time) db.session.add(show) db.session.commit() except(): db.session.rollback() error = True finally: db.session.close() if error: flash(f'An error occurred. Show could not be listed') abort(500) else: flash(f'Show listed successfully') return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) try: new_show = Show(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) Show.create(new_show) flash('Show was successfully listed!', "success") except: flash('An error occurred. Show could not be listed.', "danger") return render_template('pages/home.html')
def create_show_submission(): form = ShowForm(request.form) try: new_show = Show(artist_id=form.artist_id.data, venue_id=form.venue_id.data, start_time=form.start_time.data) Show.create(new_show) flash('Show was successfully listed!') except ValueError: # FIXME melhorar essa exception flash('An error occurred. Show could not be listed.') return render_template('pages/home.html')