From 993ce9289dde1b9e9701448701ac6730ead2fa67 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 5 Jul 2019 16:48:29 -0500 Subject: [PATCH] Add basic "downloadable" support for ExportMasterView instead of it trying to do its own thing for that... more to come on this --- tailbone/views/exports.py | 6 ++++++ tailbone/views/master.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tailbone/views/exports.py b/tailbone/views/exports.py index 3d5762e3..94f939b3 100644 --- a/tailbone/views/exports.py +++ b/tailbone/views/exports.py @@ -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), diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 0164333d..0c0cc29d 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -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: