Add link to download generic template for vendor catalog batch
also let config restrict which parsers are "supported" and auto-choose parser if there is only one
This commit is contained in:
parent
df8778f85d
commit
5ff57ae7d2
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%def name="context_menu_items()">
|
||||||
${parent.context_menu_items()}
|
${parent.context_menu_items()}
|
||||||
|
% if generic_template_url and master.has_perm('create'):
|
||||||
|
<li>${h.link_to("Download Generic Template", generic_template_url)}</li>
|
||||||
|
% endif
|
||||||
% if h.route_exists(request, 'vendors') and request.has_perm('vendors.list'):
|
% if h.route_exists(request, 'vendors') and request.has_perm('vendors.list'):
|
||||||
<li>${h.link_to("View Vendors", url('vendors'))}</li>
|
<li>${h.link_to("View Vendors", url('vendors'))}</li>
|
||||||
% endif
|
% endif
|
||||||
|
|
|
@ -135,7 +135,13 @@ class VendorCatalogView(FileBatchMasterView):
|
||||||
|
|
||||||
def get_parsers(self):
|
def get_parsers(self):
|
||||||
if not hasattr(self, 'parsers'):
|
if not hasattr(self, 'parsers'):
|
||||||
self.parsers = sorted(iter_catalog_parsers(), key=lambda p: p.display)
|
parsers = sorted(iter_catalog_parsers(), key=lambda p: p.display)
|
||||||
|
supported = self.rattail_config.getlist(
|
||||||
|
'tailbone', 'batch.vendorcatalog.supported_parsers')
|
||||||
|
if supported:
|
||||||
|
parsers = [parser for parser in parsers
|
||||||
|
if parser.key in supported]
|
||||||
|
self.parsers = parsers
|
||||||
return self.parsers
|
return self.parsers
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
|
@ -176,7 +182,12 @@ class VendorCatalogView(FileBatchMasterView):
|
||||||
if self.creating:
|
if self.creating:
|
||||||
if 'parser_key' not in f:
|
if 'parser_key' not in f:
|
||||||
f.insert_after('filename', 'parser_key')
|
f.insert_after('filename', 'parser_key')
|
||||||
values = [(p.key, p.display) for p in self.get_parsers()]
|
parsers = self.get_parsers()
|
||||||
|
values = [(p.key, p.display) for p in parsers]
|
||||||
|
if len(values) == 1:
|
||||||
|
f.set_default('parser_key', parsers[0].key)
|
||||||
|
use_buefy = self.get_use_buefy()
|
||||||
|
if not use_buefy:
|
||||||
values.insert(0, ('', "(please choose)"))
|
values.insert(0, ('', "(please choose)"))
|
||||||
f.set_widget('parser_key', dfwidget.SelectWidget(values=values))
|
f.set_widget('parser_key', dfwidget.SelectWidget(values=values))
|
||||||
f.set_label('parser_key', "File Type")
|
f.set_label('parser_key', "File Type")
|
||||||
|
@ -241,6 +252,11 @@ class VendorCatalogView(FileBatchMasterView):
|
||||||
f.set_type('upc', 'gpc')
|
f.set_type('upc', 'gpc')
|
||||||
f.set_type('discount_percent', 'percent')
|
f.set_type('discount_percent', 'percent')
|
||||||
|
|
||||||
|
def template_kwargs_index(self, **kwargs):
|
||||||
|
url = self.rattail_config.get('tailbone', 'batch.vendorcatalog.generic_template_url')
|
||||||
|
kwargs['generic_template_url'] = url
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def template_kwargs_create(self, **kwargs):
|
def template_kwargs_create(self, **kwargs):
|
||||||
parsers = self.get_parsers()
|
parsers = self.get_parsers()
|
||||||
for parser in parsers:
|
for parser in parsers:
|
||||||
|
|
Loading…
Reference in a new issue