Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update validate_zds_username using exists() #4568

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions zds/member/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,17 @@ def test_karma_and_pseudo_change(self):
self.assertEqual(len(notes), 1)
self.assertTrue(old_pseudo in notes[0].note and 'dummy' in notes[0].note)

data = {
'username': 'DuMmY',
'email': tester.user.email
}
result = self.client.post(reverse('update-username-email-member'), data, follow=False)

self.assertEqual(result.status_code, 302)
notes = KarmaNote.objects.filter(user=tester.user).all()
self.assertEqual(len(notes), 2)
self.assertTrue('dummy' in notes[1].note and 'DuMmY' in notes[1].note)

def test_ban_member_is_not_contactable(self):
"""
When a member is ban, we hide the button to send a PM.
Expand Down
9 changes: 6 additions & 3 deletions zds/member/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ def validate_zds_username(value, check_username_available=True):
:return:
"""
msg = None
user_count = User.objects.filter(username=value).count()
user_exist = User.objects.filter(username=value).exists()
print (value)
print (list(User.objects.filter(username=value).all()))
print (value)
if ',' in value:
msg = _('Le nom d\'utilisateur ne peut contenir de virgules')
elif value != value.strip():
msg = _('Le nom d\'utilisateur ne peut commencer ou finir par des espaces')
elif contains_utf8mb4(value):
msg = _('Le nom d\'utilisateur ne peut pas contenir des caractères utf8mb4')
elif check_username_available and user_count > 0:
elif check_username_available and user_exist:
msg = _('Ce nom d\'utilisateur est déjà utilisé')
elif not check_username_available and user_count == 0:
elif not check_username_available and not user_exist:
msg = _('Ce nom d\'utilisateur n\'existe pas')
if msg is not None:
raise ValidationError(msg)
Expand Down