continued working on 'merging' song books, topics, authors (still not finished)

This commit is contained in:
andreas 2010-07-17 13:49:54 +02:00
parent 94660ee798
commit dacfe58bea
2 changed files with 43 additions and 26 deletions

View File

@ -28,7 +28,8 @@ from sqlalchemy.sql import and_
from openlp.core.lib import translate from openlp.core.lib import translate
from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm
from openlp.plugins.songs.lib.db import Author, Book, Topic, Song from openlp.plugins.songs.lib.db import Author, Book, Topic, Song, \
SongsTopics, AuthorsSongs
from songmaintenancedialog import Ui_SongMaintenanceDialog from songmaintenancedialog import Ui_SongMaintenanceDialog
class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
@ -290,7 +291,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
temp_display_name, author.display_name)), temp_display_name, author.display_name)),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | \ QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | \
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes: QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
self.mergeAuthors(authors) self.mergeAuthors(author)
self.resetAuthors() self.resetAuthors()
else: else:
# We restore the author's old first and last name as well as # We restore the author's old first and last name as well as
@ -377,31 +378,33 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
book.name = temp_name book.name = temp_name
book.publisher = temp_publisher book.publisher = temp_publisher
# def mergeAuthors(self, existing_author): def mergeAuthors(self, existing_author):
# ''' '''
# ''' '''
# new_author = self.songmanager.get_object_filtered(Author, new_author = self.songmanager.get_object_filtered(Author,
# 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(......, songs = self.songmanager.get_all_objects_filtered(AuthorsSongs,
# Song.song_book_id == existing_book.id) AuthorsSongs.author_id == existing_author.id)
# for song in songs: for song in songs:
# # 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)
# def mergeTopics(self, existing_topic): def mergeTopics(self, existing_topic):
# ''' '''
# ''' '''
# 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(....., songs = self.songmanager.get_all_objects_filtered(SongsTopics,
# songs_topics.topic_id == existing_topic.id) SongsTopics.topic_id == existing_topic.id)
# for song in songs: for song in songs:
# # song.topic_id = new_topic.id
# self.songmanager.save_object(song) self.songmanager.save_object(song)
# self.songmanager.delete_object(Book, existing_topic.id) songs = self.songmanager.get_all_objects_filtered(SongsTopics,
SongsTopics.topic_id == new_topic.id)
self.songmanager.delete_object(Topic, existing_topic.id)
def mergeBooks(self, existing_book): def mergeBooks(self, existing_book):
''' '''

View File

@ -58,6 +58,18 @@ class Topic(BaseModel):
""" """
pass pass
class SongsTopics(BaseModel):
"""
Songs topics model
"""
pass
class AuthorsSongs(BaseModel):
"""
Songs authors model
"""
pass
def init_schema(url): def init_schema(url):
""" """
Setup the songs database connection and initialise the database schema Setup the songs database connection and initialise the database schema
@ -146,6 +158,8 @@ def init_schema(url):
'topics': relation(Topic, backref='songs', 'topics': relation(Topic, backref='songs',
secondary=songs_topics_table)}) secondary=songs_topics_table)})
mapper(Topic, topics_table) mapper(Topic, topics_table)
mapper(SongsTopics, songs_topics_table)
mapper(AuthorsSongs, authors_songs_table)
metadata.create_all(checkfirst=True) metadata.create_all(checkfirst=True)
return session return session