def main(): models.setup() create_colors() create_rarities() create_layouts() create_formats() models.close()
def __call__(self, environ, start_response): connect() # New session manager instance each time manager = SessionManager(environ, **self.kwargs) # Add a session object to wrapped app self.app.session = manager.session # Initial response to a cookie session def initial_response(environ, start_response): def session_response(status, headers, exc_info=None): manager.set_cookie(headers) return start_response(status, headers, exc_info) return self.app(environ, session_response) try: # Return initial response if new or session id is random if manager.is_new: return initial_response(environ, start_response) return self.app(environ, start_response) finally: # Always close session and database connection manager.close() close()
def create_artist_submission(): # called upon submitting the new artist listing form # 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 try: description = '' seeking = False if 'seeking_venue' in request.form: seeking = True if 'seeking_description' in request.form: description = request.form['seeking_description'] artist = Artist( name=request.form['name'], city=request.form['city'], state=request.form['state'], phone=request.form['phone'], genres=request.form.getlist('genres'), image_link=request.form['image_link'], facebook_link=request.form['facebook_link'], website=request.form['site_link'], seeking_description=description, seeking_venue=seeking, ) artist.insert() flash('Artist ' + request.form['name'] + ' was successfully listed!') except: rollback() flash('An error occurred. Artist ' + request.form['name'] + ' could not be listed.') finally: close() return render_template('pages/home.html')
def edit_venue_submission(venue_id): # TODO: take values from the form submitted, and update existing # venue record with ID <venue_id> using the new attributes try: seeking = False if 'seeking_talent' in request.form: seeking = True description = '' if 'seeking_description' in request.form: description = request.form['seeking_description'] venue = Venue.query.get(venue_id) venue.name = request.form['name'] venue.city = request.form['city'] venue.state = request.form['state'] venue.address = request.form['address'] venue.genres = request.form.getlist('genres') venue.phone = request.form['phone'] venue.image_link = request.form['image_link'] venue.facebook_link = request.form['facebook_link'] venue.website = request.form['site_link'] venue.seeking_description = description venue.seeking_talent = seeking venue.update() except: rollback() finally: close() return redirect(url_for('show_venue', venue_id=venue_id))
def edit_artist_submission(artist_id): # TODO: take values from the form submitted, and update existing # artist record with ID <artist_id> using the new attributes try: seeking = False if 'seeking_venue' in request.form: seeking = True description = '' if 'seeking_description' in request.form: description = request.form['seeking_description'] artist = Artist.query.get(artist_id) artist.name = request.form['name'] artist.city = request.form['city'] artist.state = request.form['state'] artist.genres = request.form.getlist('genres') artist.phone = request.form['phone'] artist.image_link = request.form['image_link'] artist.facebook_link = request.form['facebook_link'] artist.website = request.form['site_link'] artist.seeking_description = description artist.seeking_venue = seeking artist.update() except: rollback() finally: close() return redirect(url_for('show_artist', artist_id=artist_id))
def delete_venue(venue_id): try: venue = Venue.query.get(venue_id) venue.remove() except: rollback() finally: close() # TODO: Complete this endpoint for taking a venue_id, and using # SQLAlchemy ORM to delete a record. Handle cases where the session commit could fail. # BONUS CHALLENGE: Implement a button to delete a Venue on a Venue Page, have it so that # clicking that button delete it from the db then redirect the user to the homepage 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 try: show = Show( artist_id=request.form['artist_id'], venue_id=request.form['venue_id'], start_time=request.form['start_time'], ) show.insert() flash('Show was successfully listed!') except: rollback() flash('An error occurred. Show could not be listed.') finally: close() return render_template('pages/home.html')
def __call__(self, environ, start_response): request = Request(environ) handler, args = self._find_handler(request) if not handler: raise HTTPNotFound('No handler defined for %s (%s)' % (request.path_info, request.method)) if not args: args = () # Save request object for handlers self.request = request self.application_url = request.application_url connect() response = handler(*args) if not response: response = Response() # Provide an empty response close() return response(environ, start_response)
def on_fechar_arquivo_menu_item_activate(self, widget): models.close()
def create_db(): models.connect() models.create_tables() models.close()