Skip to content

Commit

Permalink
Merge pull request #2529 from Eskimon/hotfix-2501
Browse files Browse the repository at this point in the history
MP hotfix - on peut mp une liste de participants via GET
  • Loading branch information
SpaceFox committed Apr 12, 2015
2 parents 9fd4266 + 5baa6a1 commit ee2a7d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 15 additions & 0 deletions zds/mp/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ def test_success_get_with_and_without_username(self):
self.profile2.user.username,
response2.context['form'].initial['participants'])

def test_success_get_with_multi_username(self):

profile3 = ProfileFactory()

response = self.client.get(
reverse('mp-new') +
'?username=' + self.profile2.user.username +
'&username=' + profile3.user.username)

self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.context['form'].initial['participants'].split(', ')))
self.assertTrue(self.profile1.user.username not in response.context['form'].initial['participants'])
self.assertTrue(self.profile2.user.username in response.context['form'].initial['participants'])
self.assertTrue(profile3.user.username in response.context['form'].initial['participants'])

def test_success_get_with_and_without_title(self):

response = self.client.get(reverse('mp-new'))
Expand Down
17 changes: 12 additions & 5 deletions zds/mp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ def dispatch(self, *args, **kwargs):

def get(self, request, *args, **kwargs):
title = request.GET.get('title') if 'title' in request.GET else None
try:
participants = User.objects.get(username=request.GET.get('username')).username \
if 'username' in request.GET else None
except:
participants = None

participants = None
if 'username' in request.GET:
dest_list = []
# check that usernames in url is in the database
for username in request.GET.getlist('username'):
try:
dest_list.append(User.objects.get(username=username).username)
except ObjectDoesNotExist:
pass
if len(dest_list) > 0:
participants = ', '.join(dest_list)

form = self.form_class(username=request.user.username,
initial={
Expand Down

0 comments on commit ee2a7d6

Please sign in to comment.