Add initial Shopfoo pattern feature
data models, import/export, web views etc.
This commit is contained in:
parent
a7656928f5
commit
852f9d4902
19 changed files with 515 additions and 1 deletions
6
rattail_demo/importing/__init__.py
Normal file
6
rattail_demo/importing/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Importing into Rattail Demo
|
||||
"""
|
||||
|
||||
from . import model
|
60
rattail_demo/importing/local.py
Normal file
60
rattail_demo/importing/local.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Rattail Demo -> Rattail Demo "self" data import
|
||||
"""
|
||||
|
||||
from rattail.importing.local import FromRattailLocalToRattail, FromRattailLocal
|
||||
from rattail.importing.shopfoo import ShopfooProductImporterMixin
|
||||
from rattail.util import OrderedDict
|
||||
from rattail_demo import importing as rattail_demo_importing
|
||||
|
||||
|
||||
class FromRattailDemoToSelf(FromRattailLocalToRattail):
|
||||
"""
|
||||
Handler for Rattail Demo -> Rattail Demo ("self") imports
|
||||
"""
|
||||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['ShopfooProduct'] = ShopfooProductImporter
|
||||
return importers
|
||||
|
||||
|
||||
class ShopfooProductImporter(ShopfooProductImporterMixin, FromRattailLocal, rattail_demo_importing.model.ShopfooProductImporter):
|
||||
"""
|
||||
Product -> ShopfooProduct
|
||||
"""
|
||||
supported_fields = [
|
||||
'uuid',
|
||||
'product_uuid',
|
||||
'upc',
|
||||
'description',
|
||||
'price',
|
||||
'enabled',
|
||||
]
|
||||
|
||||
def normalize_base_product_data(self, product):
|
||||
|
||||
price = None
|
||||
if product.regular_price:
|
||||
price = product.regular_price.price
|
||||
|
||||
return {
|
||||
'product_uuid': product.uuid,
|
||||
'upc': str(product.upc or '') or None,
|
||||
'description': product.full_description,
|
||||
'price': price,
|
||||
'enabled': True, # will maybe unset this in mark_unwanted()
|
||||
}
|
||||
|
||||
def product_is_unwanted(self, product, data):
|
||||
if super(ShopfooProductImporter, self).product_is_unwanted(product, data):
|
||||
return True
|
||||
if not data['price']: # let's say this is a required field for Shopfoo
|
||||
return True
|
||||
return False
|
||||
|
||||
def mark_unwanted(self, product, data):
|
||||
data = super(ShopfooProductImporter, self).mark_unwanted(product, data)
|
||||
data['enabled'] = False
|
||||
return data
|
18
rattail_demo/importing/model.py
Normal file
18
rattail_demo/importing/model.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Rattail Demo model importers
|
||||
"""
|
||||
|
||||
from rattail.importing.model import ToRattail
|
||||
from rattail_demo.db import model
|
||||
|
||||
|
||||
##############################
|
||||
# custom models
|
||||
##############################
|
||||
|
||||
class ShopfooProductImporter(ToRattail):
|
||||
"""
|
||||
Importer for ShopfooProduct data
|
||||
"""
|
||||
model_class = model.ShopfooProduct
|
25
rattail_demo/importing/versions.py
Normal file
25
rattail_demo/importing/versions.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Rattail Demo -> Rattail Demo "versions" data import
|
||||
"""
|
||||
|
||||
from rattail_demo.db import model
|
||||
from rattail.importing import versions as base
|
||||
from rattail_corepos.importing.versions import CoreposVersionMixin
|
||||
|
||||
|
||||
class FromRattailDemoToRattailDemoVersions(base.FromRattailToRattailVersions,
|
||||
CoreposVersionMixin):
|
||||
"""
|
||||
Handler for Rattail Demo -> Rattail Demo "versions" data import
|
||||
"""
|
||||
|
||||
def get_importers(self):
|
||||
importers = super(FromRattailDemoToRattailDemoVersions, self).get_importers()
|
||||
importers = self.add_corepos_importers(importers)
|
||||
importers['ShopfooProduct'] = ShopfooProductImporter
|
||||
return importers
|
||||
|
||||
|
||||
class ShopfooProductImporter(base.VersionImporter):
|
||||
host_model_class = model.ShopfooProduct
|
Loading…
Add table
Add a link
Reference in a new issue