def artist(self, mbid_id): """ Query for artist mbid_id | (string) of MusicBrain's ID """ self.http.set_base('/music') response = self.http.get(mbid_id) response = json.loads(response.text) artist = Artist() artist.load(response) return artist
def create_artist(self, *args, **kwargs): """Create artits for Organizer""" args[0]["organizer_id"] = self.id artist = Artist() for key, value in args[0].items(): setattr(artist, key, value) try: artist.save() return artist except exc.IntegrityError as e: print("artist") errorInfo = e.orig.args print(errorInfo[0]) # This will give you error code print(errorInfo[1]) # This will give you error message
def create_artist_submission(): genres = request.form.getlist("genres") data = request.form.to_dict() data["genres"] = genres data["seeking_venue"] = (True if data.get("seeking_venue", False) is "y" else False) artist = Artist(**data) result = artist.save_to_db() if result["error"]: flash("An error occurred. Artist " + data["name"] + " could not be listed.") abort(500) flash("Artist " + data["name"] + " was successfully listed!") return render_template("pages/home.html")
def get(self): loginTitle = "" loginURL = "" user = users.get_current_user() if user: loginTitle = "logout" loginURL= users.create_logout_url('/') else: loginTitle = "login" loginURL= users.create_login_url('/') photos = {} artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: photos[artist.key] = artist.picture.get() templateVars = { "title" : "Manage Artists", "loginURL" : loginURL, "loginTitle": loginTitle, "artists": artists, "photos": photos } self.render_template("/templates/adminArtists.html", templateVars)
def get_artist(album): sql = "SELECT * FROM albums WHERE artist_id = %s" values = [album.id] results = run_sql(sql, values)[0] if results is not None: artist = Artist(results['name'], results['id']) return artist
def post(self): artistKeyString = self.request.get('editArtistKey') artistID = int(artistKeyString) firstName = self.request.get('editFirstName') lastName = self.request.get('editLastName') biography = self.request.get('editBiography') photoName = self.request.get('editPhotoName') #get the photo specified by the user photo = File.query(File.file_name == photoName.upper()).get() #get the artist based on the key and update all fields artist = Artist.get_by_id(artistID) artist.biography = biography artist.firstName = firstName artist.lastName = lastName artist.picture = photo.key artist.uploaded_by = users.get_current_user() artist.put() artist.add_to_search_index() message = "Successfully updated artist record: " + artist.firstName + " " + artist.lastName self.response.write(message)
def get(self): loginTitle = "" loginURL = "" user = users.get_current_user() if user: loginTitle = "logout" loginURL = users.create_logout_url('/') else: loginTitle = "login" loginURL = users.create_login_url('/') photos = {} artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: photos[artist.key] = artist.picture.get() templateVars = { "title": "Manage Artists", "loginURL": loginURL, "loginTitle": loginTitle, "artists": artists, "photos": photos } self.render_template("/templates/adminArtists.html", templateVars)
def get(self): photos = {} artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: photos[artist.key] = artist.picture.get() html = "" for artist in artists: html += """<tr> <td>""" + artist.firstName + """</td> <td>""" + artist.lastName + """</td> <td>""" + artist.biography + """</td> <td>""" + photos[artist.key].file_name + """</td> <td> <a data-toggle="modal" href="#editArtistModal" onclick="fillEditModalDefaults(""" + str( artist.key.id() ) + ", '" + artist.firstName + "', '" + artist.lastName + "', '" + artist.biography + "', '" + photos[ artist.key].file_name + """');" class="btn btn-medium"> <span class="glyphicon icon-edit"></span> </a> <a data-toggle="modal" data-id=\"""" + str( artist.key.id() ) + """\" href="#deleteArtistModal" class="open-deleteArtistModal btn btn-medium"> <span class="glyphicon icon-remove"></span> </a> </td> </tr>""" self.response.write(html)
def post(self): artistKeyString = self.request.get('editArtistKey') artistID = int(artistKeyString) firstName = self.request.get('editFirstName') lastName = self.request.get('editLastName') biography = self.request.get('editBiography') photoName = self.request.get('editPhotoName') #get the photo specified by the user photo = File.query(File.file_name==photoName.upper()).get() #get the artist based on the key and update all fields artist = Artist.get_by_id(artistID) artist.biography=biography artist.firstName=firstName artist.lastName=lastName artist.picture=photo.key artist.uploaded_by=users.get_current_user() artist.put() artist.add_to_search_index() message = "Successfully updated artist record: " + artist.firstName + " " + artist.lastName self.response.write(message)
def select(self, id): artist = None sql = "SELECT * FROM artists WHERE id = %s" results = SqlRunner.run(sql, (id, )) row = results[0] artist = Artist(row['name'], row['id']) return artist
def select_all(): artists = [] sql = "SELECT * FROM artists" results = run_sql(sql) for row in results: artist = Artist(result['title'], result['id']) artists.append(artist) return artists
def find_artist(id): artist = None sql = "SELECT * FROM artist WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result['title'], result['id']) return artist
def search_artists(): search_term = request.form.get("search_term", "") results = Artist.search(search_term) return render_template( "pages/search_artists.html", results=results, search_term=search_term, )
def select_all(): artists = [] sql = "SELECT * FROM artists ORDER BY name" results = run_sql(sql) for row in results: artist = Artist(row['name'], row['id']) artists.append(artist) return artists
def find_by_id(id): sql = "SELECT * FROM artists WHERE ID = %s" values = [id] results = run_sql(sql, values) artist_dictionary = results[0] if artist_dictionary is not None: return Artist(artist_dictionary["name"], artist_dictionary["id"])
def list_artists(): artists = [] sql = "SELECT * FROM artists" results = run_sql(sql) for row in results: artist = Artist(row['name'], row['id']) artists.append(artist) return artists
def select(id): artist = None sql = 'SELECT * FROM artists WHERE id = %s' values = [id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result['name'], result['id']) return artist
def select(id): artist = None sql = "SELECT * FROM albums WHERE id = %s" values = [id] results = run_sql(sql, values)[0] if results is not None: artist = Artist(results['name'], results['id']) return artist
def select_all(self): artists = [] sql = "SELECT * FROM artists" results = SqlRunner.run(sql) for row in results: artist = Artist(row['name'], row['id']) artists.append(artist) return artists
def artist(album): artist = None sql = "SELECT * FROM artists WHERE id=%s" values = [album.artist.id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result["first_name"], result["last_name"], result["id"]) return artist
def select(id): artist = None sql = "SELECT * FROM artists WHERE id = %s" results = run_sql(sql, (id, )) row = results[0] name = row["name"] id = row["id"] artist = Artist(name, id) return artist
def select(artist): artist = None sql = "SELECT * FROM tasks WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = artist.select(result['artist_id']) task = Artist(result["first_name"], result["last_name"]) return artist
def select(id): artist = None sql = "SELECT * FROM artists WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result["name"], result["id"]) return artist
def select_all(): artists = [] sql = "SELECT * FROM users" results = run_sql(sql) for row in results: artist = Artist(row[first_name], row['last_name'], row['id']) artists.append(artist) return artists
def select(id): artist = None sql = "SELECT * FROM users WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result['first_name'], result['last_name'], result['id']) return artist
def select_all(): artists = [] sql = "SELECT * FROM artists" results = run_sql(sql) for row in results: name = row["name"] id = row["id"] artist = Artist(name, id) artists.append(artist) return artists
def select_all(): artists = [] sql = "SELECT * FROM artists" results = run_sql(sql) for row in results: artist = Artist(row["first_name"], row["last_name"], row["id"]) artists.append(artist) return artists
def setUp(self): self.artist = Artist("Frightened Rabbit") self.label = Label("Fat Cat Records") self.album = Album( "Midnight Organ Fight", self.artist, "Indie Rock", 22.99, 13.79, "2008", "https://is2-ssl.mzstatic.com/image/thumb/Music123/v4/53/79/37/53793762-eeef-8cce-96b2-6de1c18740e2/source/600x600bb.jpg", 6, self.label, 15)
def create_artist_submission(): error = False try: app.logger.info(request.get_json()) body = {} artist = Artist(name=request.get_json()['name']) city_name = request.get_json()['city'] state_id = request.get_json()['state'] genres = request.get_json()['genres'] city = City.query.filter(City.name == city_name).first() if city == None: city = City(name=city_name) city.state_id = state_id db.session.add(city) db.session.commit() artist.city_id = city.id artist.phone = request.get_json()['phone'] artist.facebook_link = request.get_json()['facebook_link'] for genre_id in genres: genre = Genre.query.get(genre_id) artist.genres.append(genre) db.session.add(artist) db.session.commit() body['id'] = artist.id body['name'] = artist.name except: print("Oops!", sys.exc_info(), "occured.") error = True db.session.rollback() finally: db.session.close() if error: flash('Artist ' + artist.name + ' could not be listed.') abort(400) else: flash('Artist ' + artist.name + ' was successfully listed!') return jsonify(body)
def artist(album): artist = None sql = "SELECT * FROM artists WHERE id = %s" values = [album.artist_id] result = run_sql(sql, values)[0] if result is not None: artist = Artist(result['name']) return artist
def getArtistContent(filename): """ Read json file from data dir, and grab corresponding Artist info """ # checking extension if not filename.endswith('.json'): raise ValueError('this is not a JSON file') filepath = os.path.join(data_dir, filename) # checking exisitence if not os.path.exists(filepath): raise IOError('this file does not exist') # read file and load into a dict try: with open(filepath) as f: data = json.loads(f.read()) artist = Artist(data['name'], data['mbid']) artist.setTopAlbum(data['topAlbums']) return artist except IOError: raise
def artists(album): artists = [] sql = "SELECT * FROM artists WHERE album_id = %s" values = [album.id] results = run_sql(sql, values) for row in results: artist = Artist(row['name'], album) artists.append(artist) return artists
def post(self): firstName = self.request.get('firstName') lastName = self.request.get('lastName') biography = self.request.get('biography') photoName = self.request.get('photoName') #get the photo specified by the user photo = File.query(File.file_name==photoName.upper()).get() #check to see if a artist with that name already exists existingArtist = Artist.query(Artist.firstName==firstName and Artist.lastName==lastName).get() if existingArtist: #if an artist with that name already exists, then update the information with the form data existingArtist.biography=biography existingArtist.firstName=firstName existingArtist.lastName=lastName existingArtist.picture=photo.key existingArtist.uploaded_by=users.get_current_user() existingArtist.put() existingArtist.add_to_search_index() message = "Successfully updated artist record: " + existingArtist.firstName + " " + existingArtist.lastName else: #add a new artist entry if no artist with that name already exists artist = Artist(biography=biography, firstName=firstName, lastName=lastName, picture=photo.key, uploaded_by=users.get_current_user()) artist.put() artist.add_to_search_index() message = "Successfully created artist record: " + artist.firstName + " " + artist.lastName self.response.write(message)
def post(self): artistKeyString = self.request.get('deleteArtistKey') #generate message artist = Artist.get_by_id(int(artistKeyString)) artist.remove_from_search_index() message = "Successfully deleted artist: " + artist.firstName + " " + artist.lastName #delete artist artistKey = artist.key artistKey.delete() self.response.write(message)
def get(self): loginTitle = "" loginURL = "" user = users.get_current_user() if user: loginTitle = "logout" loginURL= users.create_logout_url('/') else: loginTitle = "login" loginURL= users.create_login_url('/') uploadURL = blobstore.create_upload_url('/admin/art/upload') categoriesList = {} masterItemNumberList = {} art = [] #sort the art by artist name and then by artpiece name artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: artistArt = ArtPiece.query().order(ArtPiece.name).filter(ArtPiece.artist==artist.key) for artpiece in artistArt: art.append(artpiece) for artpiece in art: #create a comma separated string of categories categoryNamesString = artpiece.categoryNames() categoriesList[artpiece.key] = categoryNamesString #check for null master art piece itemNumber = '' if artpiece.masterArtPiece is None else artpiece.masterArtPiece.get().itemNumber masterItemNumberList[artpiece.key] = itemNumber templateVars = { "title" : "Manage Art", "loginURL" : loginURL, "loginTitle": loginTitle, "art": art, "categoriesList": categoriesList, "masterItemNumberList": masterItemNumberList, "uploadURL": uploadURL } self.render_template("/templates/adminArt.html", templateVars)
def get(self): categoriesList = {} art = [] #sort the art by artist name and then by artpiece name artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: artistArt = ArtPiece.query().order(ArtPiece.name).filter(ArtPiece.artist==artist.key) for artpiece in artistArt: art.append(artpiece) for artpiece in art: categories = ndb.get_multi(artpiece.categories) categoryNamesList = [] for category in categories: categoryNamesList.append(str(category.categoryName)) categoryNamesString = ",".join(categoryNamesList) categoriesList[artpiece.key] = categoryNamesString html = "" for artpiece in art: html+="""<tr> <td>""" + artpiece.artist.get().firstName + " " + artpiece.artist.get().lastName + """</td> <td>""" + artpiece.name + """</td> <td>""" + artpiece.itemNumber + """</td> <td>""" + categoriesList[artpiece.key] + """</td> <td>""" + artpiece.priceDisplay + """</td> <td> <a data-toggle="modal" href="#editArtModal" onclick="fillEditArtModalDefaults(""" + str(artpiece.key.id()) + ",'" + artpiece.artist.get().firstName + " " + artpiece.artist.get().lastName + "', '" + categoriesList[artpiece.key] + "', '" + artpiece.name + "', '" + artpiece.price + "', '" + artpiece.itemNumber + "', '" + artpiece.width + "', '" + artpiece.height + "', '" + artpiece.depth + "', '" + artpiece.weight + "', '" + artpiece.description + "', '" + artpiece.colors + "', '" + artpiece.mediums + "', '" + ('' if artpiece.masterArtPiece is None else artpiece.masterArtPiece.get().itemNumber) + "', '" + artpiece.picture.get().file_name + """');" class="btn btn-medium"> <span class="glyphicon icon-edit"></span> </a> <a data-toggle="modal" data-id=\"""" + str(artpiece.key.id()) + """\" href="#deleteArtModal" class="open-deleteArtModal btn btn-medium"> <span class="glyphicon icon-remove"></span> </a> </td> </tr>""" self.response.write(html)
def get(self): photos = {} artists = Artist.query().order(Artist.firstName, Artist.lastName) for artist in artists: photos[artist.key] = artist.picture.get() html = "" for artist in artists: html+="""<tr> <td>""" + artist.firstName + """</td> <td>""" + artist.lastName + """</td> <td>""" + artist.biography + """</td> <td>""" + photos[artist.key].file_name + """</td> <td> <a data-toggle="modal" href="#editArtistModal" onclick="fillEditModalDefaults(""" + str(artist.key.id()) + ", '" + artist.firstName +"', '" + artist.lastName +"', '" + artist.biography + "', '" + photos[artist.key].file_name + """');" class="btn btn-medium"> <span class="glyphicon icon-edit"></span> </a> <a data-toggle="modal" data-id=\"""" + str(artist.key.id()) + """\" href="#deleteArtistModal" class="open-deleteArtistModal btn btn-medium"> <span class="glyphicon icon-remove"></span> </a> </td> </tr>""" self.response.write(html)
def get(self): artists=Artist.query() for artist in artists: artist.remove_from_search_index() logging.error("removed index for: %s" % artist.firstName)
def post(self): blob_info = self.get_uploads()[0] #only act on the file if it is a .csv, .xls, or .xlsx file type if blob_info.content_type == "application/vnd.ms-excel" or blob_info.content_type == ".csv" or blob_info.content_type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": blobdata=blobstore.BlobReader(blob_info) reader = csv.DictReader(blobdata,dialect='excel') self.response.headers['Content-Type'] = 'text/plain' message = "" editedMessage = "" createdMessage = "" for row in reader: artistString = row["Artist"] categoriesString = row["Categories"] name = row["Name of Piece"] price = row["Price($)"] priceDisplay = "$" + '{:20,.2f}'.format(Decimal(price)) itemNumber = row["Item Number"] height = row["Height(in)"] depth = row["Depth(in)"] weight = row["Weight"] width = row["Width(in)"] description = row["Product Description"] colors = row["Colors"] mediums = row["Mediums"] masterItemNum = row["Master Art Piece (Item Number)"] pictureName = row ["Picture Name"] #find related objects to tie to this artpiece artistNameList=artistString.split(" ") artistFirstName=artistNameList[0] artistLastName=artistNameList[-1] artist = Artist.query(Artist.firstName==artistFirstName, Artist.lastName==artistLastName).get() categories = [] categoriesList = categoriesString.split(",") for categoryString in categoriesList: category = Category.query(Category.categoryName==categoryString.strip()).get() categories.append(category) masterArtPiece = ArtPiece.query(ArtPiece.itemNumber==masterItemNum).get() photo = File.query(File.file_name==pictureName.upper()).get() #check if artpiece with this item number already exists existingArtPiece = ArtPiece.query(ArtPiece.itemNumber==itemNumber).get() if existingArtPiece: #if an artpiece with that itemNumber is already stored then update the record with the new information existingArtPiece.artist = artist.key existingArtPiece.categories = [] for category in categories: existingArtPiece.categories.append(category.key) existingArtPiece.colors = colors existingArtPiece.depth = depth existingArtPiece.description = description existingArtPiece.height = height if masterArtPiece: existingArtPiece.masterArtPiece = masterArtPiece.key existingArtPiece.slaveArtFlag = True masterArtPiece.masterArtFlag = True masterArtPiece.put() existingArtPiece.mediums = mediums existingArtPiece.name = name existingArtPiece.picture = photo.key existingArtPiece.price = price existingArtPiece.priceDisplay = priceDisplay existingArtPiece.uploaded_by=users.get_current_user() existingArtPiece.weight = weight existingArtPiece.width = width existingArtPiece.put() existingArtPiece.add_to_search_index() editedMessage += "<br>" + existingArtPiece.name else: #otherwise create a new record for the artpiece artPiece = ArtPiece(artist=artist.key, colors=colors, depth=depth, description=description, height=height, itemNumber=itemNumber, mediums=mediums, name=name, picture=photo.key, price=price, priceDisplay=priceDisplay, weight=weight, width=width, uploaded_by=users.get_current_user()) for category in categories: artPiece.categories.append(category.key) if masterArtPiece: artPiece.masterArtPiece = masterArtPiece.key artPiece.slaveArtFlag = True masterArtPiece.masterArtFlag = True masterArtPiece.put() artPiece.put() artPiece.add_to_search_index() createdMessage += "<br>" + artPiece.name #no need to save the file in the blobstore blob_info.delete() message = "The following items were added to the database: <br>" message += createdMessage + "<br><br>" message+= "The following items were updated in the database: <br>" message += editedMessage self.response.write(message)
def post(self): artpieceKeyString = self.request.get('editArtKey') artpieceID = int(artpieceKeyString) artistString = self.request.get('editArtist') categoriesString = self.request.get('editCategories') name = self.request.get('editName') price = self.request.get('editPrice') priceDisplay = "$" + '{:20,.2f}'.format(Decimal(price)) itemNumber = self.request.get('editItemNumber') width = self.request.get('editWidth') height = self.request.get('editHeight') depth = self.request.get('editDepth') weight = self.request.get('editWeight') description = self.request.get('editProductDescription') colors = self.request.get('editColors') mediums = self.request.get('editMediums') masterItemNum = self.request.get('editMasterArtNum') pictureName = self.request.get('editProductPhotoName') #find related objects to tie to this artpiece artistNameList=artistString.split(" ") artistFirstName=artistNameList[0] artistLastName=artistNameList[-1] artist = Artist.query(Artist.firstName==artistFirstName, Artist.lastName==artistLastName).get() categories = [] categoriesList = categoriesString.split(",") for categoryString in categoriesList: category = Category.query(Category.categoryName==categoryString.strip()).get() categories.append(category) masterArtPiece = ArtPiece.query(ArtPiece.itemNumber==masterItemNum).get() photo = File.query(File.file_name==pictureName.upper()).get() #get the artpiece based on the key and update all fields accordingly artpiece = ArtPiece.get_by_id(artpieceID) artpiece.artist = artist.key artpiece.categories = [] for category in categories: artpiece.categories.append(category.key) artpiece.colors = colors artpiece.depth = depth artpiece.description = description artpiece.height = height artpiece.itemNumber = itemNumber if masterArtPiece: artpiece.masterArtPiece = masterArtPiece.key artpiece.slaveArtFlag = True masterArtPiece.masterArtFlag = True masterArtPiece.put() artpiece.mediums = mediums artpiece.name = name artpiece.picture = photo.key artpiece.price = price artpiece.priceDisplay = priceDisplay artpiece.uploaded_by=users.get_current_user() artpiece.weight = weight artpiece.width = width artpiece.put() artpiece.add_to_search_index() message = "Successfully updated artpiece record: " + artpiece.name self.response.write(message)