Don't error out when newRef already exist, use it instead

Before this commit when a newRef was entered on user registration and
that ref already existed we errored out. Now we use exactly that
reference when it already exists.
py3
Sebastian Lohff 4年前 committed by root
コミット 1f2d34c8b4

@ -27,8 +27,6 @@ class UpdateRefForm(forms.Form):
def clean_newRefName(self):
data = self.cleaned_data["newRefName"].strip().upper()
if Reference.objects.filter(name=data).count() > 0:
raise forms.ValidationError("Reference already exists")
return data
@ -38,6 +36,14 @@ class UpdateRefForm(forms.Form):
existingRef = cleaned_data.get("existingRef")
newRefName = cleaned_data.get("newRefName")
if newRefName:
try:
ref = Reference.objects.get(name=newRefName)
self.cleaned_data['newRefName'] = None
self.cleaned_data['existingRef'] = ref
except Reference.DoesNotExist:
pass
if existingRef and newRefName:
raise forms.ValidationError("Select an existing exchange or create a new one, not both!")
if not existingRef and not newRefName:

読み込み中…
キャンセル
保存