Skip to content

Commit

Permalink
Merge branch 'next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z authored Jun 13, 2024
2 parents 4243509 + ba8ba6f commit 44b6b7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stregsystem/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class Meta:
def clean_username(self):
username = self.cleaned_data['username']
if self.instance is None or self.instance.pk is None:
if Member.objects.filter(username=username).exists():
if Member.objects.filter(username__iexact=username).exists():
raise forms.ValidationError("Brugernavnet er allerede taget")
return username

Expand Down Expand Up @@ -234,7 +234,7 @@ class MemberAdmin(admin.ModelAdmin):

def save_model(self, request, obj, form, change):
if 'username' in form.changed_data and change:
if Member.objects.filter(username=obj.username).exclude(pk=obj.pk).exists():
if Member.objects.filter(username__iexact=obj.username).exclude(pk=obj.pk).exists():
messages.add_message(request, messages.WARNING, 'Det brugernavn var allerede optaget')
super().save_model(request, obj, form, change)

Expand Down
5 changes: 5 additions & 0 deletions stregsystem/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,11 @@ def test_cant_create_duplicate_username(self):
form = MemberForm(model_to_dict(jeff))
self.assertFalse(form.is_valid())

def test_cant_create_duplicate_username_in_other_case(self):
jeff = Member(username="JeFf", firstname="jeffrey", lastname="jefferson", gender="M")
form = MemberForm(model_to_dict(jeff))
self.assertFalse(form.is_valid())

def test_can_create_non_duplicate_username(self):
not_jeff = Member(username="not_jeff", firstname="jeff", lastname="jefferson", gender="M")
form = MemberForm(model_to_dict(not_jeff))
Expand Down

0 comments on commit 44b6b7f

Please sign in to comment.