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
0
rattail_demo/shopfoo/__init__.py
Normal file
0
rattail_demo/shopfoo/__init__.py
Normal file
6
rattail_demo/shopfoo/importing/__init__.py
Normal file
6
rattail_demo/shopfoo/importing/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Importing into Shopfoo
|
||||
"""
|
||||
|
||||
from . import model
|
28
rattail_demo/shopfoo/importing/model.py
Normal file
28
rattail_demo/shopfoo/importing/model.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Shopfoo model importers
|
||||
"""
|
||||
|
||||
from rattail_demo.db import model
|
||||
from rattail.importing.exporters import ToCSV
|
||||
from rattail.shopfoo.importing.model import ProductImporterMixin
|
||||
|
||||
|
||||
class ToShopfoo(ToCSV):
|
||||
pass
|
||||
|
||||
|
||||
class ProductImporter(ProductImporterMixin, ToShopfoo):
|
||||
"""
|
||||
Shopfoo product data importer
|
||||
"""
|
||||
key = 'uuid'
|
||||
simple_fields = [
|
||||
'uuid',
|
||||
'product_uuid',
|
||||
'upc',
|
||||
'description',
|
||||
'price',
|
||||
'enabled',
|
||||
]
|
||||
export_model_class = model.ShopfooProductExport
|
62
rattail_demo/shopfoo/importing/rattail.py
Normal file
62
rattail_demo/shopfoo/importing/rattail.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Rattail -> Shopfoo importing
|
||||
"""
|
||||
|
||||
from rattail import importing
|
||||
from rattail.util import OrderedDict
|
||||
|
||||
from rattail_demo.db import model
|
||||
from rattail_demo.shopfoo import importing as shopfoo_importing
|
||||
from rattail.shopfoo.importing.rattail import ProductImporterMixin
|
||||
|
||||
|
||||
class FromRattailToShopfoo(importing.FromRattailHandler):
|
||||
"""
|
||||
Rattail -> Shopfoo import handler
|
||||
"""
|
||||
host_title = "Rattail"
|
||||
local_title = "Shopfoo"
|
||||
direction = 'export'
|
||||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['Product'] = ProductImporter
|
||||
return importers
|
||||
|
||||
|
||||
class FromRattail(importing.FromSQLAlchemy):
|
||||
"""
|
||||
Base class for Shopfoo -> Rattail importers
|
||||
"""
|
||||
|
||||
|
||||
class ProductImporter(ProductImporterMixin, FromRattail, shopfoo_importing.model.ProductImporter):
|
||||
"""
|
||||
Product data importer
|
||||
"""
|
||||
host_model_class = model.ShopfooProduct
|
||||
supported_fields = [
|
||||
'uuid',
|
||||
'product_uuid',
|
||||
'upc',
|
||||
'description',
|
||||
'price',
|
||||
'enabled',
|
||||
]
|
||||
|
||||
def query(self):
|
||||
return self.host_session.query(model.ShopfooProduct)\
|
||||
.order_by(model.ShopfooProduct.upc)
|
||||
|
||||
def normalize_host_object(self, product):
|
||||
|
||||
# copy all values "as-is" from our cache record
|
||||
data = dict([(field, getattr(product, field))
|
||||
for field in self.fields])
|
||||
|
||||
# TODO: is it ever a good idea to set this flag? doing so will mean
|
||||
# the record is *not* included in CSV output file
|
||||
# data['_deleted_'] = product.deleted_from_shopfoo
|
||||
|
||||
return data
|
Loading…
Add table
Add a link
Reference in a new issue