reworked code

This commit is contained in:
andreas 2010-07-19 10:50:44 +02:00
parent 1a462e1a65
commit 3502149556
1 changed files with 14 additions and 20 deletions

View File

@ -393,17 +393,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
and_(Author.first_name == existing_author.first_name, and_(Author.first_name == existing_author.first_name,
Author.last_name == existing_author.last_name, Author.last_name == existing_author.last_name,
Author.display_name == existing_author.display_name)) Author.display_name == existing_author.display_name))
songs = self.songmanager.get_all_objects_filtered(AuthorsSongs, songs = self.songmanager.get_all_objects(Song)
AuthorsSongs.author_id == existing_author.id)
for song in songs: for song in songs:
# We have to check if the song has already the new_author as author. if existing_author in song.authors:
# If that is the case we must not change song.author_id to the # We check if the song has already the new_author as author.
# new_author's id, because then they were not unique. # If that is not the case we add it.
temp_song = self.songmanager.get_all_objects_filtered(AuthorsSongs, if new_author not in song.authors:
and_(AuthorsSongs.author_id == new_author.id, song.authors.append(new_author)
AuthorsSongs.song_id == song.song_id)) song.authors.remove(existing_author)
if len(temp_song) < 1:
song.author_id = new_author.id
self.songmanager.save_object(song) self.songmanager.save_object(song)
self.songmanager.delete_object(Author, existing_author.id) self.songmanager.delete_object(Author, existing_author.id)
@ -416,17 +413,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
''' '''
new_topic = self.songmanager.get_object_filtered(Topic, new_topic = self.songmanager.get_object_filtered(Topic,
Topic.name == existing_topic.name) Topic.name == existing_topic.name)
songs = self.songmanager.get_all_objects_filtered(SongsTopics, songs = self.songmanager.get_all_objects(Song)
SongsTopics.topic_id == existing_topic.id)
for song in songs: for song in songs:
# We have to check if the song has already the new_topic as topic. if existing_topic in song.topics:
# If that is the case we must not change song.topic_id to the # We check if the song has already the new_topic as topic.
# new_topic's id, because then they were not unique. # If that is not the case we add it.
temp_song = self.songmanager.get_all_objects_filtered(SongsTopics, if new_topic not in song.topics:
and_(SongsTopics.topic_id == new_topic.id, song.topics.append(new_topic)
SongsTopics.song_id == song.song_id)) song.topics.remove(existing_topic)
if len(temp_song) < 1:
song.topic_id = new_topic.id
self.songmanager.save_object(song) self.songmanager.save_object(song)
self.songmanager.delete_object(Topic, existing_topic.id) self.songmanager.delete_object(Topic, existing_topic.id)