From 1e0c0dec430b21be51f9626a97e3538f8845c6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 2 Dec 2015 10:19:49 +0100 Subject: [PATCH] fields: add a parameter to File field to remove the portfolio picker (#7182) --- wcs/fields.py | 11 ++++++++--- wcs/qommon/form.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wcs/fields.py b/wcs/fields.py index 53e8797..62ab90c 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -676,9 +676,10 @@ class FileField(WidgetField): description = N_('File Upload') document_type = None max_file_size = None + allow_portfolio_picking = True widget_class = FileWithPreviewWidget - extra_attributes = ['file_type', 'max_file_size'] + extra_attributes = ['file_type', 'max_file_size', 'allow_portfolio_picking'] def __init__(self, *args, **kwargs): super(FileField, self).__init__(*args, **kwargs) @@ -707,10 +708,14 @@ class FileField(WidgetField): form.add(FileSizeWidget, 'max_file_size', title=('Max file size'), value=self.max_file_size, advanced=not(self.max_file_size)) + form.add(CheckboxWidget, 'allow_portfolio_picking', + title=_('Allow user to pick a file from a portfolio'), + value=self.allow_portfolio_picking, + advanced=(self.allow_portfolio_picking is True)) def get_admin_attributes(self): - return WidgetField.get_admin_attributes(self) + ['document_type', - 'max_file_size'] + return WidgetField.get_admin_attributes(self) + [ + 'document_type', 'max_file_size', 'allow_portfolio_picking'] def get_view_value(self, value): return htmltext('%s') % ( diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 87699e4..c9d8c89 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -556,6 +556,7 @@ class FileWithPreviewWidget(CompositeWidget): self.value = value self.preview = kwargs.get('readonly') self.max_file_size = kwargs.pop('max_file_size', None) + self.allow_portfolio_picking = kwargs.pop('allow_portfolio_picking', True) if self.max_file_size: self.max_file_size_bytes = FileSizeWidget.parse_file_size(self.max_file_size) self.add(HiddenWidget, 'token') -- 2.6.2