Change vendor catalog upload, to allow vendor-less parsers.
The user must provide the vendor if the parser does not; the user cannot override the vendor if the parser does provide it.
This commit is contained in:
parent
0a223ac4f9
commit
d6bdc0e87d
52
tailbone/templates/vendors/catalogs/create.mako
vendored
52
tailbone/templates/vendors/catalogs/create.mako
vendored
|
@ -1,3 +1,55 @@
|
||||||
## -*- coding: utf-8 -*-
|
## -*- coding: utf-8 -*-
|
||||||
<%inherit file="/batch/create.mako" />
|
<%inherit file="/batch/create.mako" />
|
||||||
|
|
||||||
|
<%def name="head_tags()">
|
||||||
|
${parent.head_tags()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var vendormap = {
|
||||||
|
% for i, parser in enumerate(parsers, 1):
|
||||||
|
'${parser.key}': ${parser.vendormap_value|n}${',' if i < len(parsers) else ''}
|
||||||
|
% endfor
|
||||||
|
};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
if ($('#VendorCatalog--parser_key option:first').is(':selected')) {
|
||||||
|
$('#VendorCatalog--vendor_uuid-container').hide();
|
||||||
|
} else {
|
||||||
|
$('#VendorCatalog--vendor_uuid').val('');
|
||||||
|
$('#VendorCatalog--vendor_uuid-display').hide();
|
||||||
|
$('#VendorCatalog--vendor_uuid-display button').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-container').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#VendorCatalog--parser_key').change(function() {
|
||||||
|
if ($(this).find('option:first').is(':selected')) {
|
||||||
|
$('#VendorCatalog--vendor_uuid-container').hide();
|
||||||
|
} else {
|
||||||
|
var vendor = vendormap[$(this).val()];
|
||||||
|
if (vendor) {
|
||||||
|
$('#VendorCatalog--vendor_uuid').val(vendor.uuid);
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').hide();
|
||||||
|
$('#VendorCatalog--vendor_uuid-display span:first').text(vendor.name);
|
||||||
|
$('#VendorCatalog--vendor_uuid-display button').hide();
|
||||||
|
$('#VendorCatalog--vendor_uuid-display').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-container').show();
|
||||||
|
} else {
|
||||||
|
$('#VendorCatalog--vendor_uuid').val('');
|
||||||
|
$('#VendorCatalog--vendor_uuid-display').hide();
|
||||||
|
$('#VendorCatalog--vendor_uuid-display button').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').val('');
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-container').show();
|
||||||
|
$('#VendorCatalog--vendor_uuid-textbox').focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
## -*- coding: utf-8 -*-
|
## -*- coding: utf-8 -*-
|
||||||
<%inherit file="/batch/view.mako" />
|
<%inherit file="/batch/view.mako" />
|
||||||
|
|
||||||
|
<%def name="title()">Vendor Catalog: ${batch.vendor}</%def>
|
||||||
|
|
||||||
${parent.body()}
|
${parent.body()}
|
||||||
|
|
77
tailbone/views/vendors/catalogs.py
vendored
77
tailbone/views/vendors/catalogs.py
vendored
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2015 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,21 +24,27 @@
|
||||||
Views for maintaining vendor catalogs
|
Views for maintaining vendor catalogs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
from rattail.db.api import get_setting, get_vendor
|
from rattail.db.api import get_setting, get_vendor
|
||||||
from rattail.db.batch.vendorcatalog import VendorCatalog, VendorCatalogRow
|
from rattail.db.batch.vendorcatalog import VendorCatalog, VendorCatalogRow
|
||||||
from rattail.db.batch.vendorcatalog.handler import VendorCatalogHandler
|
from rattail.db.batch.vendorcatalog.handler import VendorCatalogHandler
|
||||||
from rattail.vendors.catalogs import iter_catalog_parsers, require_catalog_parser
|
from rattail.vendors.catalogs import iter_catalog_parsers
|
||||||
from rattail.util import load_object
|
from rattail.util import load_object
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy
|
||||||
|
|
||||||
|
from tailbone import forms
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views.batch import FileBatchGrid, FileBatchCrud, ProductBatchRowGrid, BatchRowCrud, defaults
|
from tailbone.views.batch import FileBatchGrid, FileBatchCrud, ProductBatchRowGrid, BatchRowCrud, defaults
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VendorCatalogGrid(FileBatchGrid):
|
class VendorCatalogGrid(FileBatchGrid):
|
||||||
"""
|
"""
|
||||||
Grid view for vendor catalogs.
|
Grid view for vendor catalogs.
|
||||||
|
@ -105,39 +111,62 @@ class VendorCatalogCrud(FileBatchCrud):
|
||||||
handler = super(VendorCatalogCrud, self).get_handler()
|
handler = super(VendorCatalogCrud, self).get_handler()
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
def get_parsers(self):
|
||||||
|
if not hasattr(self, 'parsers'):
|
||||||
|
self.parsers = sorted(iter_catalog_parsers(), key=lambda p: p.display)
|
||||||
|
return self.parsers
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
parsers = sorted(iter_catalog_parsers(), key=lambda p: p.display)
|
fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer)
|
||||||
parser_options = [(p.display, p.key) for p in parsers]
|
fs.filename.set(label="Catalog File")
|
||||||
|
|
||||||
|
if self.creating:
|
||||||
|
parser_options = [(p.display, p.key) for p in self.get_parsers()]
|
||||||
parser_options.insert(0, ("(please choose)", ''))
|
parser_options.insert(0, ("(please choose)", ''))
|
||||||
fs.parser_key.set(renderer=formalchemy.fields.SelectFieldRenderer,
|
fs.parser_key.set(renderer=formalchemy.fields.SelectFieldRenderer,
|
||||||
options=parser_options)
|
options=parser_options, label="File Type")
|
||||||
|
|
||||||
fs.configure(
|
fs.configure(
|
||||||
include=[
|
include=[
|
||||||
|
fs.filename,
|
||||||
|
fs.parser_key,
|
||||||
fs.vendor,
|
fs.vendor,
|
||||||
fs.filename.label("Catalog File"),
|
|
||||||
fs.parser_key.label("File Type"),
|
|
||||||
fs.effective,
|
|
||||||
fs.created,
|
fs.created,
|
||||||
fs.created_by,
|
fs.created_by,
|
||||||
fs.executed,
|
fs.executed,
|
||||||
fs.executed_by,
|
fs.executed_by,
|
||||||
])
|
])
|
||||||
if self.creating:
|
|
||||||
del fs.vendor
|
|
||||||
del fs.effective
|
|
||||||
else:
|
|
||||||
del fs.parser_key
|
|
||||||
fs.vendor.set(readonly=True)
|
|
||||||
fs.effective.set(readonly=True)
|
|
||||||
|
|
||||||
def init_batch(self, batch):
|
else:
|
||||||
parser = require_catalog_parser(batch.parser_key)
|
fs.configure(
|
||||||
vendor = get_vendor(Session, parser.vendor_key)
|
include=[
|
||||||
if not vendor:
|
fs.vendor.readonly(),
|
||||||
self.request.session.flash("No vendor setting found in database for key: {0}".format(parser.vendor_key))
|
fs.filename,
|
||||||
return False
|
fs.effective.readonly(),
|
||||||
batch.vendor = vendor
|
fs.created,
|
||||||
return True
|
fs.created_by,
|
||||||
|
fs.executed,
|
||||||
|
fs.executed_by,
|
||||||
|
])
|
||||||
|
|
||||||
|
def template_kwargs(self, form):
|
||||||
|
kwargs = super(VendorCatalogCrud, self).template_kwargs(form)
|
||||||
|
if self.creating:
|
||||||
|
parsers = self.get_parsers()
|
||||||
|
for parser in parsers:
|
||||||
|
if parser.vendor_key:
|
||||||
|
vendor = get_vendor(Session(), parser.vendor_key)
|
||||||
|
if vendor:
|
||||||
|
parser.vendormap_value = "{{uuid: '{}', name: '{}'}}".format(
|
||||||
|
vendor.uuid, vendor.name.replace("'", "\\'"))
|
||||||
|
else:
|
||||||
|
log.warning("vendor '{}' not found for parser: {}".format(
|
||||||
|
parser.vendor_key, parser.key))
|
||||||
|
parser.vendormap_value = 'null'
|
||||||
|
else:
|
||||||
|
parser.vendormap_value = 'null'
|
||||||
|
kwargs['parsers'] = parsers
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class VendorCatalogRowGrid(ProductBatchRowGrid):
|
class VendorCatalogRowGrid(ProductBatchRowGrid):
|
||||||
|
|
Loading…
Reference in a new issue