Skip to content
Open
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
1 change: 1 addition & 0 deletions freemusicninja/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'raven.contrib.django.raven_compat',
'rest_framework',
'rest_framework.authtoken',
'rest_framework_swagger',

'artists',
'echonest',
Expand Down
1 change: 1 addition & 0 deletions freemusicninja/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
namespace='rest_framework')),
url(r'^api-token-auth/',
'rest_framework.authtoken.views.obtain_auth_token'),
url(r'^docs/', include('rest_framework_swagger.urls')),
url(r'^admin/', include(admin.site.urls)),
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ django-cors-headers==0.13
django-filter==0.8
django-jsonfield==0.9.13
django-model-utils==2.2.0
django-rest-swagger==0.2.0
djangorestframework==2.4.3
psycopg2==2.5.4
purl==1.0
Expand Down
1 change: 0 additions & 1 deletion users/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class UserTest(APITestCase):
def test_list_users_logged_out(self):
url = reverse('user-list')
response = self.client.get(url, format='json')
print(response.data)
assert response.status_code == status.HTTP_200_OK
assert (response.data == [{
'id': 1,
Expand Down
17 changes: 8 additions & 9 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ class UserViewSet(viewsets.ModelViewSet):

queryset = User.objects.all()
permission_classes = (IsUserOrReadOnly,)
serializer_class = UserSerializer

def get_serializer_class(self):
try:
obj = self.get_object()
except ImproperlyConfigured: # assume list view, use non-authenticated
pass
def get_serializer(self, instance=None, *args, **kwargs):
context = self.get_serializer_context()
if (self.request.user.is_authenticated()
and instance == self.request.user):
serializer_class = AuthenticatedUserSerializer
else:
if (self.request.user.is_authenticated()
and obj == self.request.user):
return AuthenticatedUserSerializer
return UserSerializer
serializer_class = self.serializer_class
return serializer_class(instance, context=context, *args, **kwargs)

def initial(self, request, *args, **kwargs):
"""Retrieve given user or current user if ``pk`` is "me"."""
Expand Down