Changeset - 874cbc4462bd
[Not reviewed]
1 3 0
Lance Edgar - 6 years ago 2019-02-18 21:27:57
ledgar@techsupport.coop
Clean up Rattail <-> Rattail import/export handlers a bit
4 files changed with 19 insertions and 317 deletions:
0 comments (0 inline, 0 general)
rattail/importing/rattail.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2019 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail 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, either version 3 of the License, or (at your option) any later
 
#  version.
 
#
 
#  Rattail 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.
 
@@ -118,49 +118,52 @@ class FromRattailToRattailBase(object):
 

	
 
    def get_default_keys(self):
 
        keys = self.get_importer_keys()
 
        if 'AdminUser' in keys:
 
            keys.remove('AdminUser')
 
        if 'ProductImage' in keys:
 
            keys.remove('ProductImage')
 
        return keys
 

	
 

	
 
class FromRattailToRattailImport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
 
    """
 
    Handler for Rattail -> Rattail data import.
 
    Handler for Rattail (other) -> Rattail (local) data import.
 
    """
 
    local_title = "Rattail (local)"
 
    dbkey = 'host'
 

	
 
    @property
 
    def host_title(self):
 
        return "Rattail ({})".format(self.dbkey)
 
        return "{} ({})".format(self.config.app_title(default="Rattail"), self.dbkey)
 

	
 
    @property
 
    def local_title(self):
 
        return self.config.node_title()
 

	
 
    def make_host_session(self):
 
        return Session(bind=self.config.rattail_engines[self.dbkey])
 

	
 
# TODO: deprecate/remove this?
 
FromRattailToRattail = FromRattailToRattailImport
 

	
 

	
 
class FromRattailToRattailExport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
 
    """
 
    Handler for Rattail -> Rattail data import.
 
    Handler for Rattail (local) -> Rattail (other) data export.
 
    """
 
    host_title = "Rattail (default)"
 

	
 
    @property
 
    def host_title(self):
 
        return self.config.node_title()
 

	
 
    @property
 
    def local_title(self):
 
        return "Rattail ({})".format(self.dbkey)
 
        return "{} ({})".format(self.config.app_title(default="Rattail"), self.dbkey)
 

	
 
    def make_session(self):
 
        return Session(bind=self.config.rattail_engines[self.dbkey])
 

	
 

	
 
class FromRattail(FromSQLAlchemy):
 
    """
 
    Base class for Rattail -> Rattail data importers.
 
    """
 

	
 
    @property
 
    def host_model_class(self):
rattail/importing/rattail_bulk.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2019 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail 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, either version 3 of the License, or (at your option) any later
 
#  version.
 
#
 
#  Rattail 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.
 
@@ -19,28 +19,28 @@
 
#  You should have received a copy of the GNU General Public License along with
 
#  Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 
"""
 
Rattail -> Rattail bulk data import
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from rattail import importing
 
from rattail.util import OrderedDict
 
from rattail.importing.rattail import FromRattailToRattail, FromRattail
 
from rattail.importing.rattail import FromRattailToRattailImport, FromRattail
 

	
 

	
 
class BulkFromRattailToRattail(FromRattailToRattail, importing.BulkImportHandler):
 
class BulkFromRattailToRattail(FromRattailToRattailImport, importing.BulkImportHandler):
 
    """
 
    Handler for Rattail -> Rattail bulk data import.
 
    """
 

	
 
    def get_importers(self):
 
        importers = OrderedDict()
 
        importers['Person'] = PersonImporter
 
        importers['PersonEmailAddress'] = PersonEmailAddressImporter
 
        importers['PersonPhoneNumber'] = PersonPhoneNumberImporter
 
        importers['PersonMailingAddress'] = PersonMailingAddressImporter
 
        importers['User'] = UserImporter
 
        importers['Message'] = MessageImporter
rattail/tests/commands/test_importing.py.bak
Show inline comments
 
deleted file
rattail/tests/importing/test_rattail.py
Show inline comments
 
@@ -47,25 +47,25 @@ class DualRattailTestCase(DualRattailMixin, TestCase):
 

	
 
class TestFromRattailHandler(RattailTestCase, ImporterTester):
 
    handler_class = rattail_importing.FromRattailHandler
 
        
 
    def test_make_host_session(self):
 
        handler = self.make_handler()
 
        session = handler.make_host_session()
 
        self.assertIsInstance(session, SessionBase)
 
        self.assertIs(session.bind, self.config.rattail_engine)
 

	
 

	
 
class TestFromRattailToRattail(DualRattailTestCase, ImporterTester):
 
    handler_class = rattail_importing.FromRattailToRattail
 
    handler_class = rattail_importing.FromRattailToRattailImport
 

	
 
    def test_host_title(self):
 
        handler = self.make_handler()
 
        self.assertEqual(handler.host_title, "Rattail (host)")
 

	
 
    # TODO
 
    def test_default_keys(self):
 
        handler = self.make_handler()
 
        handler.get_default_keys()
 

	
 
    def test_make_session(self):
 
        handler = self.make_handler()
0 comments (0 inline, 0 general)