Skip to content

Commit

Permalink
Release 1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoleoncio committed Jul 3, 2024
2 parents 47927c4 + ff10ec3 commit 4b906df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CapX/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

# Alternative version of views, read-only and only returns the __str__ with the id as the key
router.register('list_language', ListLanguageViewSet, basename='list_language')
router.register('list_organizations', ListOrganizationViewSet, basename='list_organizations')
router.register('list_affiliation', ListOrganizationViewSet, basename='list_affiliation')
router.register('list_skills', ListSkillViewSet, basename='list_skills')
router.register('list_territory', ListTerritoryViewSet, basename='list_territory')
router.register('list_wikimedia_project', ListWikimediaProjectViewSet, basename='list_wikimedia_project')
Expand Down
14 changes: 9 additions & 5 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ def list(self, request, *args, **kwargs):
return Response(response, status=status.HTTP_400_BAD_REQUEST)


# Class to list users by "tags" (skills, languages, territories, projects, affiliation) with format /tags/<tag_type>/<tag_id>/
# Class to list users by "tags" (skills, languages, territories, wikimedia_project, affiliation) with format /tags/<tag_type>/<tag_id>/
# Example: /tags/project/1/
class UsersByTagViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Profile.objects.all()
serializer_class = ProfileSerializer

def retrieve(self, request, *args, **kwargs):
tag_type = self.kwargs['tag_type']
tag_id = self.kwargs['tag_id']
tag_type = self.kwargs.get('tag_type')
tag_id = self.kwargs.get('tag_id')

if tag_type and not tag_id:
response = {'message': 'Please provide a valid tag id.'}
return Response(response, status=status.HTTP_400_BAD_REQUEST)

if tag_type == 'skill':
known_users = Profile.objects.filter(skills_known=tag_id)
Expand All @@ -123,7 +127,7 @@ def retrieve(self, request, *args, **kwargs):
elif tag_type == 'territory':
users = Profile.objects.filter(territory=tag_id)
data = [{'id': user.id, 'display_name': user.display_name, 'username': user.user.username, 'profile_image': user.profile_image} for user in users]
elif tag_type == 'project':
elif tag_type == 'wikimedia_project':
users = Profile.objects.filter(wikimedia_project=tag_id)
data = [{'id': user.id, 'display_name': user.display_name, 'username': user.user.username, 'profile_image': user.profile_image} for user in users]
elif tag_type == 'affiliation':
Expand All @@ -136,5 +140,5 @@ def retrieve(self, request, *args, **kwargs):
return Response(data)

def list(self, request, *args, **kwargs):
response = {'message': 'Please provide a tag type and a tag id.'}
response = {'message': 'Please provide a tag type and a tag id. Options are: skill, language, territory, wikimedia_project, affiliation.'}
return Response(response, status=status.HTTP_400_BAD_REQUEST)

0 comments on commit 4b906df

Please sign in to comment.