From 8cac948ada1adea9a4e0f67788f3840527bf61e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 31 Dec 2015 15:56:30 +0100 Subject: [PATCH] fields: make sure document_type is always a dictionary (#9461) --- wcs/fields.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wcs/fields.py b/wcs/fields.py index 8e0785f..6f31a37 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -692,19 +692,19 @@ class FileField(WidgetField): def fill_admin_form(self, form): WidgetField.fill_admin_form(self, form) document_types = self.get_document_types() - cur_dt = self.document_type + cur_dt = self.document_type or {} # SingleSelectWidget compare the value and not the keys, so if we want # the current value not to be hidden, we must reset it with the corresponding # value from settings based on the 'id' - document_type_id = self.document_type.get('id') + document_type_id = cur_dt.get('id') if document_type_id in document_types \ - and self.document_type != document_types[document_type_id]: - self.document_type = document_types[document_type_id] + and cur_dt != document_types[document_type_id]: + cur_dt = document_types[document_type_id] options = [(None, '---', {})] options += [(doc_type, doc_type['label'], key) for key, doc_type in document_types.iteritems()] form.add(SingleSelectWidget, 'document_type', title=_('File type suggestion'), - value=self.document_type, options=options, - advanced=not(self.document_type)) + value=cur_dt, options=options, + advanced=not(cur_dt)) form.add(FileSizeWidget, 'max_file_size', title=('Max file size'), value=self.max_file_size, advanced=not(self.max_file_size)) @@ -764,7 +764,7 @@ class FileField(WidgetField): for key, document_type in document_types.iteritems(): document_type['id'] = key # add current file type if it does not exist anymore in the settings - cur_dt = self.document_type + cur_dt = self.document_type or {} if cur_dt and cur_dt['id'] not in document_types: document_types[cur_dt['id']] = cur_dt return document_types -- 2.6.4