Skip to content

Commit 1997a90

Browse files
committed
Removed the insertion of 'confirm_acronym' in the active form in clean_acronym(). It triggers an exception due to changing a dictionary while the django validation code is iterating through the form fields. XXX Check if we need to put this back some other way, or if we can handle acronym re-use through the admin instead.
- Legacy-Id: 16412
1 parent f8d4c3c commit 1997a90

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

ietf/group/forms.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ietf.review.utils import close_review_request_states, setup_reviewer_field
2020
from ietf.utils.textupload import get_cleaned_text_file_content
2121
from ietf.utils.text import strip_suffix
22-
from ietf.utils.ordereddict import insert_after_in_ordered_dict
22+
#from ietf.utils.ordereddict import insert_after_in_ordered_dict
2323
from ietf.utils.fields import DatepickerDateField, MultiEmailField
2424

2525
# --- Constants --------------------------------------------------------
@@ -122,6 +122,7 @@ def __init__(self, *args, **kwargs):
122122
del self.fields[f]
123123

124124
def clean_acronym(self):
125+
try:
125126
# Changing the acronym of an already existing group will cause 404s all
126127
# over the place, loose history, and generally muck up a lot of
127128
# things, so we don't permit it
@@ -140,42 +141,45 @@ def clean_acronym(self):
140141

141142
confirmed = self.data.get("confirm_acronym", False)
142143

143-
def insert_confirm_field(label, initial):
144-
# set required to false, we don't need it since we do the
145-
# validation of the field in here, and otherwise the
146-
# browser and Django may barf
147-
insert_after_in_ordered_dict(self.fields, "confirm_acronym", forms.BooleanField(label=label, required=False), after="acronym")
148-
# we can't set initial, it's ignored since the form is bound, instead mutate the data
149-
self.data = self.data.copy()
150-
self.data["confirm_acronym"] = initial
144+
# def insert_confirm_field(label, initial):
145+
# # set required to false, we don't need it since we do the
146+
# # validation of the field in here, and otherwise the
147+
# # browser and Django may barf
148+
# insert_after_in_ordered_dict(self.fields, "confirm_acronym", forms.BooleanField(label=label, required=False), after="acronym")
149+
# # we can't set initial, it's ignored since the form is bound, instead mutate the data
150+
# self.data = self.data.copy()
151+
# self.data["confirm_acronym"] = initial
151152

152153
if existing and existing.type_id == self.group_type:
153154
if existing.state_id == "bof":
154-
insert_confirm_field(label="Turn BoF %s into proposed %s and start chartering it" % (existing.acronym, existing.type.name), initial=True)
155+
#insert_confirm_field(label="Turn BoF %s into proposed %s and start chartering it" % (existing.acronym, existing.type.name), initial=True)
155156
if confirmed:
156157
return acronym
157158
else:
158-
raise forms.ValidationError("Warning: Acronym used for an existing BoF (%s)." % existing.name)
159+
raise forms.ValidationError("Warning: Acronym used for an existing BoF (%s)." % existing.acronym)
159160
else:
160-
insert_confirm_field(label="Set state of %s %s to proposed and start chartering it" % (existing.acronym, existing.type.name), initial=False)
161+
#insert_confirm_field(label="Set state of %s %s to proposed and start chartering it" % (existing.acronym, existing.type.name), initial=False)
161162
if confirmed:
162163
return acronym
163164
else:
164-
raise forms.ValidationError("Warning: Acronym used for an existing %s (%s, %s)." % (existing.type.name, existing.name, existing.state.name if existing.state else "unknown state"))
165+
raise forms.ValidationError("Warning: Acronym used for an existing %s (%s, %s)." % (existing.type.name, existing.acronym, existing.state.name if existing.state else "unknown state"))
165166

166167
if existing:
167-
raise forms.ValidationError("Acronym used for an existing group (%s)." % existing.name)
168+
raise forms.ValidationError("Acronym used for an existing group (%s)." % existing.acronym)
168169

169-
# TODO: Why is this limited to types wg and rg? We would want to be warned about _any_ old collision I think?
170-
old = GroupHistory.objects.filter(acronym__iexact=acronym, type__in=("wg", "rg"))
170+
old = GroupHistory.objects.filter(acronym__iexact=acronym)
171171
if old:
172-
insert_confirm_field(label="Confirm reusing acronym %s" % old[0].acronym, initial=False)
172+
#insert_confirm_field(label="Confirm reusing acronym %s" % old[0].acronym, initial=False)
173173
if confirmed:
174174
return acronym
175175
else:
176176
raise forms.ValidationError("Warning: Acronym used for a historic group.")
177-
178177
return acronym
178+
except forms.ValidationError:
179+
pass
180+
except Exception:
181+
import traceback
182+
traceback.print_exc()
179183

180184
def clean_urls(self):
181185
return [x.strip() for x in self.cleaned_data["urls"].splitlines() if x.strip()]
@@ -199,7 +203,7 @@ def clean_parent(self):
199203
else:
200204
raise forms.ValidationError("A group cannot be its own ancestor. "
201205
"Found that the group '%s' would end up being the ancestor of (%s)" % (p.acronym, ', '.join([g.acronym for g in seen])))
202-
206+
203207
def clean(self):
204208
cleaned_data = super(GroupForm, self).clean()
205209
state = cleaned_data.get('state', None)

0 commit comments

Comments
 (0)