Browse Source

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.
Sebastian Lohff 1 year ago
parent
commit
1f2d34c8b4
1 changed files with 8 additions and 2 deletions
  1. 8
    2
      contest/forms.py

+ 8
- 2
contest/forms.py View File

@@ -27,8 +27,6 @@ class UpdateRefForm(forms.Form):
27 27
 
28 28
 	def clean_newRefName(self):
29 29
 		data = self.cleaned_data["newRefName"].strip().upper()
30
-		if Reference.objects.filter(name=data).count() > 0:
31
-			raise forms.ValidationError("Reference already exists")
32 30
 
33 31
 		return data
34 32
 
@@ -38,6 +36,14 @@ class UpdateRefForm(forms.Form):
38 36
 		existingRef = cleaned_data.get("existingRef")
39 37
 		newRefName = cleaned_data.get("newRefName")
40 38
 
39
+		if newRefName:
40
+			try:
41
+				ref = Reference.objects.get(name=newRefName)
42
+				self.cleaned_data['newRefName'] = None
43
+				self.cleaned_data['existingRef'] = ref
44
+			except Reference.DoesNotExist:
45
+				pass
46
+
41 47
 		if existingRef and newRefName:
42 48
 			raise forms.ValidationError("Select an existing exchange or create a new one, not both!")
43 49
 		if not existingRef and not newRefName:

Loading…
Cancel
Save