def create_song(cls, song_json, versions, songs): if song_json is None: return None # create the song object and save it to the store song = Song({"song" : song_json}) if versions is not None: song.versions = versions if songs is not None: song.songs = songs song.save() # call the indexing process, and index this object and all # related ones SongIndex.by_id(song.id, cascade=True) return song
def update_song(cls, song_id, song_json=None, versions=None, songs=None): # retrieve and update the song object in the desired way song = Song().get(song_id, links=True) if song is None: raise NotFoundException() if song_json is not None: song.patch_song(song_json, replace_all=True, keep_id=True) if versions is not None: song.versions = versions if songs is not None: song.songs = songs song.save() # call the indexing process, and index this object and all related ones print song.id SongIndex.by_id(song.id, cascade=True) return song
song2.add_location(relation="main", name="Dumfries") song2.set_time_period("Late 19th Century", "Early 20th Century") song2.lv_id = "LV2" song2.id = song2.makeid() song_ids.append(song2.id) # we need the ids of the related songs, which we add get later # The Boreland of Balmaghie song3 = Song() song3.title = "The Boreland of Balmaghie" song3.summary = "Bothy song in which man is hired to work at a farm near Castle Douglas, and is critical of the treatment he receives." song3.add_location(relation="main", name="Castle Douglas") song3.set_time_period("Late 19th Century", "Early 20th Century") song3.lv_id = "LV3" song3.id = song3.makeid() song3.songs = [song1.id, song2.id] song_ids.append(song3.id) # add the relations for song1 and song2 song1.songs = [song2.id, song3.id] song2.songs = [song1.id, song3.id] # save all three song1.save(host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB, refresh=True) song2.save(host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB, refresh=True) song3.save(host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB, refresh=True) # Andrew Lammie song = Song() song.title = "Andrew Lammie" song.summary = "Song of tragic love between Andrew Lammie, the Laird o Fyvie's trumpeter and Mill o Tifty's Annie. Annie's parents disapprove, and have Andrew dismissed and sent away, then kill their daughter for shaming them."