Add basic "downloadable" support for ExportMasterView
instead of it trying to do its own thing for that... more to come on this
This commit is contained in:
parent
c8d6361c36
commit
993ce9289d
|
@ -45,7 +45,10 @@ class ExportMasterView(MasterView):
|
|||
"""
|
||||
creatable = False
|
||||
editable = False
|
||||
|
||||
# TODO: should deprecate `export_has_file` in favor of `downloadable`
|
||||
export_has_file = False
|
||||
downloadable = False
|
||||
|
||||
grid_columns = [
|
||||
'id',
|
||||
|
@ -126,6 +129,8 @@ class ExportMasterView(MasterView):
|
|||
f.set_readonly('record_count')
|
||||
|
||||
# download
|
||||
# TODO: should probably stop doing this altogether? and just make each
|
||||
# derived view declare the field renderer?
|
||||
if self.export_has_file and self.viewing:
|
||||
# download = forms.renderers.FileFieldRenderer.new(
|
||||
# self, storage_path=self.rattail_config.export_filedir(self.export_key),
|
||||
|
@ -202,6 +207,7 @@ class ExportMasterView(MasterView):
|
|||
model_title = cls.get_model_title()
|
||||
|
||||
# download export file
|
||||
# TODO: should deprecate this and just use 'downloadable' instead
|
||||
if cls.export_has_file:
|
||||
config.add_route('{}.download'.format(route_prefix), '{}/{{{}}}/download'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='download', route_name='{}.download'.format(route_prefix),
|
||||
|
|
|
@ -2767,6 +2767,13 @@ class MasterView(View):
|
|||
"""
|
||||
return getattr(cls, 'mobile_row_form_factory', forms.Form)
|
||||
|
||||
def download_path(self, obj, filename):
|
||||
"""
|
||||
Should return absolute path on disk, for the given object and filename.
|
||||
Result will be used to return a file response to client.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def render_downloadable_file(self, obj, field):
|
||||
filename = getattr(obj, field)
|
||||
if not filename:
|
||||
|
|
Loading…
Reference in a new issue