[damned-lies] Prevent crashing when new_branch_release is blank in 'new branch' form
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Prevent crashing when new_branch_release is blank in 'new branch' form
- Date: Mon, 20 Mar 2017 17:07:49 +0000 (UTC)
commit 9d684e97cd1140062bc2a6618046318d6fa8b1bd
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Mar 16 14:51:29 2017 +0100
Prevent crashing when new_branch_release is blank in 'new branch' form
stats/forms.py | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/stats/forms.py b/stats/forms.py
index 1ec5828..71bf49a 100644
--- a/stats/forms.py
+++ b/stats/forms.py
@@ -70,8 +70,17 @@ class ModuleBranchForm(forms.Form):
except Branch.DoesNotExist:
# The branch will be created later in the view
return cleaned_data
- rel = Release.objects.get(pk=cleaned_data['new_branch_release'].pk)
- cat = Category(release=rel, branch=branch, name=cleaned_data['new_branch_category'])
- cat.full_clean()
- cleaned_data['new_category'] = cat
+ if not cleaned_data['new_branch_release']:
+ self.add_error(
+ 'new_branch_release',
+ ValidationError(
+ "There is already an entry for branch %s. Edit that one if "
+ "you want to remove the release link." % branch
+ )
+ )
+ else:
+ rel = Release.objects.get(pk=cleaned_data['new_branch_release'].pk)
+ cat = Category(release=rel, branch=branch, name=cleaned_data['new_branch_category'])
+ cat.full_clean()
+ cleaned_data['new_category'] = cat
return cleaned_data
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]