Skip to content

Commit f7d979c

Browse files
committed
Merged [5426] from ietf@augustcellars.com:
Make sure that the same rule cannot be entered twice in a community list. As part of this fix, you need to do the following: 1. Eliminate duplicates currently in the data base. This statement can be used to identify them. SELECT e1.id id1, e2.id id2, e1.community_list_id, e1.rule_type, e1.value FROM ietf_utf8.community_rule e1 JOIN ietf_utf8.community_rule e2 ON (e1.id != e2.id AND e1.community_list_id=e2.community_list_id AND e1.rule_type=e2.rule_type AND e1.value=e2.value); 2. Delete any current duplicate lines in the text. This uses the following commands as of the check-in DELETE FROM TABLE ietf_utf8.community_rule WHERE id=19 OR id=91 OR id=177 3. Add a constraint to the table so that it will enforce the rule itself ALTER TABLE ietf_utf8.community_rule ADD CONSTRAINT pc_CommunityRule UNIQUE (community_list_id, rule_type, value) - Legacy-Id: 5460 Note: SVN reference [5426] has been migrated to Git commit a18bebe
2 parents 4b4eb29 + a18bebe commit f7d979c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

ietf/community/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class Rule(models.Model):
126126
value = models.CharField(
127127
max_length=255)
128128

129+
class Meta:
130+
unique_together= ("community_list", "rule_type", "value")
131+
129132
last_updated = models.DateTimeField(
130133
auto_now=True)
131134

ietf/community/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import hashlib
55
from datetime import timedelta
6+
from django.db import IntegrityError
67

78
from django.conf import settings
89
from django.contrib.auth import REDIRECT_FIELD_NAME
@@ -25,7 +26,10 @@ def _manage_list(request, clist):
2526
rule_form = RuleForm(request.POST, clist=clist)
2627
display_form = DisplayForm(instance=display_config)
2728
if rule_form.is_valid():
28-
rule_form.save()
29+
try:
30+
rule_form.save()
31+
except IntegrityError:
32+
pass;
2933
rule_form = RuleForm(clist=clist)
3034
display_form = DisplayForm(instance=display_config)
3135
elif request.method == 'POST' and request.POST.get('save_display', None):

0 commit comments

Comments
 (0)