From bbcfd7729cd1b86e0ca6a8161f8283f7883af1de Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Fri, 28 May 2010 01:26:49 +0100 Subject: [PATCH] Refactor BaseModel --- openlp/core/lib/__init__.py | 1 + openlp/core/lib/basemodel.py | 41 +++++++++++++++++++++++++ openlp/migration/migratebibles.py | 2 +- openlp/migration/migratesongs.py | 2 +- openlp/plugins/alerts/lib/classes.py | 16 +--------- openlp/plugins/bibles/lib/models.py | 15 +-------- openlp/plugins/custom/lib/classes.py | 16 +--------- openlp/plugins/songs/lib/classes.py | 16 +--------- openlp/plugins/songusage/lib/classes.py | 16 +--------- 9 files changed, 49 insertions(+), 76 deletions(-) create mode 100644 openlp/core/lib/basemodel.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 3794afde0..30663ffbe 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -184,4 +184,5 @@ from songxmlhandler import SongXMLBuilder, SongXMLParser from themexmlhandler import ThemeXML from renderer import Renderer from rendermanager import RenderManager +from basemodel import BaseModel from baselistwithdnd import BaseListWithDnD diff --git a/openlp/core/lib/basemodel.py b/openlp/core/lib/basemodel.py new file mode 100644 index 000000000..f4aa2fbef --- /dev/null +++ b/openlp/core/lib/basemodel.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2010 Raoul Snyman # +# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin # +# Thompson, Jon Tibble, Carsten Tinggaard # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### + +class BaseModel(object): + """ + BaseModel provides a base object with a set of generic functions + """ + + @classmethod + def populate(cls, **kwargs): + """ + Creates an instance of a class and populates it, returning the instance + """ + me = cls() + keys = kwargs.keys() + for key in keys: + me.__setattr__(key, kwargs[key]) + return me + diff --git a/openlp/migration/migratebibles.py b/openlp/migration/migratebibles.py index 17ded3a80..bd94dd6a0 100644 --- a/openlp/migration/migratebibles.py +++ b/openlp/migration/migratebibles.py @@ -30,7 +30,7 @@ import sqlite3 from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker, mapper -from openlp.core.lib import SettingsManager +from openlp.core.lib import BaseModel, SettingsManager from openlp.core.utils import AppLocation from openlp.plugins.bibles.lib.models import * diff --git a/openlp/migration/migratesongs.py b/openlp/migration/migratesongs.py index f7624e98c..47ddd6fe6 100644 --- a/openlp/migration/migratesongs.py +++ b/openlp/migration/migratesongs.py @@ -31,7 +31,7 @@ from sqlalchemy import * from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation -from openlp.core.lib import SettingsManager +from openlp.core.lib import BaseModel, SettingsManager from openlp.core.utils import AppLocation from openlp.plugins.songs.lib.models import metadata, songs_table, Song, \ Author, Topic, Book diff --git a/openlp/plugins/alerts/lib/classes.py b/openlp/plugins/alerts/lib/classes.py index fd1883b71..e58f80829 100644 --- a/openlp/plugins/alerts/lib/classes.py +++ b/openlp/plugins/alerts/lib/classes.py @@ -23,21 +23,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -class BaseModel(object): - """ - BaseModel provides a base object with a set of generic functions - """ - - @classmethod - def populate(cls, **kwargs): - """ - Creates an instance of a class and populates it, returning the instance - """ - me = cls() - keys = kwargs.keys() - for key in keys: - me.__setattr__(key, kwargs[key]) - return me +from openlp.core.lib import BaseModel class AlertItem(BaseModel): """ diff --git a/openlp/plugins/bibles/lib/models.py b/openlp/plugins/bibles/lib/models.py index 4631b1e32..011a216d2 100644 --- a/openlp/plugins/bibles/lib/models.py +++ b/openlp/plugins/bibles/lib/models.py @@ -27,20 +27,7 @@ from sqlalchemy import Column, Table, MetaData, ForeignKey, types, \ create_engine from sqlalchemy.orm import mapper, relation, sessionmaker, scoped_session -class BaseModel(object): - """ - BaseModel provides a base object with a set of generic functions - """ - @classmethod - def populate(cls, **kwargs): - """ - Creates an instance of a class and populates it, returning the instance - """ - me = cls() - keys = kwargs.keys() - for key in keys: - me.__setattr__(key, kwargs[key]) - return me +from openlp.core.lib import BaseModel class BibleMeta(BaseModel): diff --git a/openlp/plugins/custom/lib/classes.py b/openlp/plugins/custom/lib/classes.py index 305852df2..dc6c5c1b8 100644 --- a/openlp/plugins/custom/lib/classes.py +++ b/openlp/plugins/custom/lib/classes.py @@ -23,21 +23,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -class BaseModel(object): - """ - BaseModel provides a base object with a set of generic functions - """ - - @classmethod - def populate(cls, **kwargs): - """ - Creates an instance of a class and populates it, returning the instance - """ - me = cls() - keys = kwargs.keys() - for key in keys: - me.__setattr__(key, kwargs[key]) - return me +from openlp.core.lib import BaseModel class CustomSlide(BaseModel): """ diff --git a/openlp/plugins/songs/lib/classes.py b/openlp/plugins/songs/lib/classes.py index 115943814..c465588a4 100644 --- a/openlp/plugins/songs/lib/classes.py +++ b/openlp/plugins/songs/lib/classes.py @@ -23,21 +23,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -class BaseModel(object): - """ - BaseModel provides a base object with a set of generic functions - """ - - @classmethod - def populate(cls, **kwargs): - """ - Creates an instance of a class and populates it, returning the instance - """ - me = cls() - keys = kwargs.keys() - for key in keys: - me.__setattr__(key, kwargs[key]) - return me +from openlp.core.lib import BaseModel class Author(BaseModel): """ diff --git a/openlp/plugins/songusage/lib/classes.py b/openlp/plugins/songusage/lib/classes.py index a780b57ac..298380f58 100644 --- a/openlp/plugins/songusage/lib/classes.py +++ b/openlp/plugins/songusage/lib/classes.py @@ -23,21 +23,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -class BaseModel(object): - """ - BaseModel provides a base object with a set of generic functions - """ - - @classmethod - def populate(cls, **kwargs): - """ - Creates an instance of a class and populates it, returning the instance - """ - me = cls() - keys = kwargs.keys() - for key in keys: - me.__setattr__(key, kwargs[key]) - return me +from openlp.core.lib import BaseModel class SongUsageItem(BaseModel): """