From 128c0a6dbbab8b68e3f519a21da5fd315bbc4428 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Sat, 3 Nov 2018 04:28:50 +0000 Subject: [PATCH] Removed the field and widget that made editing document states easier on the document admin page since they do not survive validation failure of other fields on the form. Excluded states from the modelform since the default states widget is almost impossible to use without producing bad data. If states need to be edited through the admin, it will, for now, need to be done gruelingly through the admin form for State. Fixes #2524. Commit ready for merge. - Legacy-Id: 15684 --- ietf/doc/admin.py | 54 +---------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/ietf/doc/admin.py b/ietf/doc/admin.py index 2b39ae761..7fe15d912 100644 --- a/ietf/doc/admin.py +++ b/ietf/doc/admin.py @@ -40,66 +40,14 @@ class RelatedDocumentInline(admin.TabularInline): raw_id_fields = ['target'] extra = 1 -# document form for managing states in a less confusing way - -class StatesWidget(forms.SelectMultiple): - """Display all applicable states as separate select boxes, - requires 'instance' have been set on the widget.""" - def render(self, name, value, attrs=None, choices=()): - - types = StateType.objects.filter(slug__in=get_state_types(self.instance)).order_by("slug") - - categorized_choices = [] - for t in types: - states = State.objects.filter(used=True, type=t).select_related() - if states: - categorized_choices.append((t.label, states)) - - html = [] - first = True - for label, states in categorized_choices: - htmlid = "id_%s_%s" % (name, slugify(label)) - - html.append('
' % ("1em" if first else "0.5em")) - html.append(u'' % (htmlid, label)) - html.append(u'') - html.append("
") - - first = False - - return mark_safe(u"".join(html)) - -class StatesField(forms.ModelMultipleChoiceField): - def __init__(self, *args, **kwargs): - # use widget with multiple select boxes - kwargs['widget'] = StatesWidget - super(StatesField, self).__init__(*args, **kwargs) - - def clean(self, value): - if value and isinstance(value, (list, tuple)): - # remove "", in case a state is reset - value = [x for x in value if x] - return super(StatesField, self).clean(value) - class DocumentForm(forms.ModelForm): - states = StatesField(queryset=State.objects.all(), required=False) comment_about_changes = forms.CharField( widget=forms.Textarea(attrs={'rows':10,'cols':40,'class':'vLargeTextField'}), strip=False, help_text="This comment about the changes made will be saved in the document history.") - def __init__(self, *args, **kwargs): - super(DocumentForm, self).__init__(*args, **kwargs) - - # we don't normally have access to the instance in the widget - # so set it here - self.fields["states"].widget.instance = self.instance - class Meta: fields = '__all__' + exclude = ('states',) model = Document class DocumentAuthorAdmin(admin.ModelAdmin):