Skip to content

Commit

Permalink
[Fixes #2274] Error is now caught and conveyed to user
Browse files Browse the repository at this point in the history
  • Loading branch information
damienallen committed Jul 4, 2016
1 parent d9f7370 commit c3f2392
Show file tree
Hide file tree
Showing 6 changed files with 1,448 additions and 1,366 deletions.
8 changes: 7 additions & 1 deletion akvo/rest/views/employment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"""

from django.contrib.auth.models import Group
from django.db import IntegrityError
from rest_framework.decorators import api_view, permission_classes
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status
from akvo.rsr.models import Employment
from ..serializers import EmploymentSerializer
from ..viewsets import BaseRSRViewSet
Expand Down Expand Up @@ -48,6 +50,10 @@ def set_group(request, pk=None, group_id=None):
raise PermissionDenied

employment.group = group
employment.save()
try:
employment.save()
except IntegrityError:
return Response({'status': 'group not set', 'error': 'Employment already exists.'},
status=status.HTTP_400_BAD_REQUEST)

return Response({'status': 'group set'})
Loading

0 comments on commit c3f2392

Please sign in to comment.