Projet

Général

Profil

0001-fields-make-sure-document_type-is-always-a-dictionar.patch

Frédéric Péters, 31 décembre 2015 15:59

Télécharger (2,37 ko)

Voir les différences:

Subject: [PATCH] fields: make sure document_type is always a dictionary
 (#9461)

 wcs/fields.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
wcs/fields.py
692 692
    def fill_admin_form(self, form):
693 693
        WidgetField.fill_admin_form(self, form)
694 694
        document_types = self.get_document_types()
695
        cur_dt = self.document_type
695
        cur_dt = self.document_type or {}
696 696
        # SingleSelectWidget compare the value and not the keys, so if we want
697 697
        # the current value not to be hidden, we must reset it with the corresponding
698 698
        # value from settings based on the 'id'
699
        document_type_id = self.document_type.get('id')
699
        document_type_id = cur_dt.get('id')
700 700
        if document_type_id in document_types \
701
               and self.document_type != document_types[document_type_id]:
702
            self.document_type = document_types[document_type_id]
701
               and cur_dt != document_types[document_type_id]:
702
            cur_dt = document_types[document_type_id]
703 703
        options = [(None, '---', {})]
704 704
        options += [(doc_type, doc_type['label'], key) for key, doc_type in document_types.iteritems()]
705 705
        form.add(SingleSelectWidget, 'document_type', title=_('File type suggestion'),
706
                value=self.document_type, options=options,
707
                advanced=not(self.document_type))
706
                value=cur_dt, options=options,
707
                advanced=not(cur_dt))
708 708
        form.add(FileSizeWidget, 'max_file_size', title=('Max file size'),
709 709
                value=self.max_file_size,
710 710
                advanced=not(self.max_file_size))
......
764 764
        for key, document_type in document_types.iteritems():
765 765
            document_type['id'] = key
766 766
        # add current file type if it does not exist anymore in the settings
767
        cur_dt = self.document_type
767
        cur_dt = self.document_type or {}
768 768
        if cur_dt and cur_dt['id'] not in document_types:
769 769
            document_types[cur_dt['id']] = cur_dt
770 770
        return document_types
771
-