Skip to content

Commit 128c0a6

Browse files
committed
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 ietf-tools#2524. Commit ready for merge.
- Legacy-Id: 15684
1 parent 16ae849 commit 128c0a6

1 file changed

Lines changed: 1 addition & 53 deletions

File tree

ietf/doc/admin.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,66 +40,14 @@ def this(self, instance):
4040
raw_id_fields = ['target']
4141
extra = 1
4242

43-
# document form for managing states in a less confusing way
44-
45-
class StatesWidget(forms.SelectMultiple):
46-
"""Display all applicable states as separate select boxes,
47-
requires 'instance' have been set on the widget."""
48-
def render(self, name, value, attrs=None, choices=()):
49-
50-
types = StateType.objects.filter(slug__in=get_state_types(self.instance)).order_by("slug")
51-
52-
categorized_choices = []
53-
for t in types:
54-
states = State.objects.filter(used=True, type=t).select_related()
55-
if states:
56-
categorized_choices.append((t.label, states))
57-
58-
html = []
59-
first = True
60-
for label, states in categorized_choices:
61-
htmlid = "id_%s_%s" % (name, slugify(label))
62-
63-
html.append('<div style="clear:both;padding-top:%s">' % ("1em" if first else "0.5em"))
64-
html.append(u'<label for="%s">%s:</label>' % (htmlid, label))
65-
html.append(u'<select name="%s" id="%s">' % (name, htmlid))
66-
html.append(u'<option value="">-----------</option>')
67-
for s in states:
68-
html.append('<option %s value="%s">%s</option>' % ("selected" if s.pk in value else "", s.pk, s.name))
69-
html.append(u'</select>')
70-
html.append("</div>")
71-
72-
first = False
73-
74-
return mark_safe(u"".join(html))
75-
76-
class StatesField(forms.ModelMultipleChoiceField):
77-
def __init__(self, *args, **kwargs):
78-
# use widget with multiple select boxes
79-
kwargs['widget'] = StatesWidget
80-
super(StatesField, self).__init__(*args, **kwargs)
81-
82-
def clean(self, value):
83-
if value and isinstance(value, (list, tuple)):
84-
# remove "", in case a state is reset
85-
value = [x for x in value if x]
86-
return super(StatesField, self).clean(value)
87-
8843
class DocumentForm(forms.ModelForm):
89-
states = StatesField(queryset=State.objects.all(), required=False)
9044
comment_about_changes = forms.CharField(
9145
widget=forms.Textarea(attrs={'rows':10,'cols':40,'class':'vLargeTextField'}), strip=False,
9246
help_text="This comment about the changes made will be saved in the document history.")
9347

94-
def __init__(self, *args, **kwargs):
95-
super(DocumentForm, self).__init__(*args, **kwargs)
96-
97-
# we don't normally have access to the instance in the widget
98-
# so set it here
99-
self.fields["states"].widget.instance = self.instance
100-
10148
class Meta:
10249
fields = '__all__'
50+
exclude = ('states',)
10351
model = Document
10452

10553
class DocumentAuthorAdmin(admin.ModelAdmin):

0 commit comments

Comments
 (0)