Skip to content
This repository has been archived by the owner on Mar 22, 2020. It is now read-only.

Commit

Permalink
added get by score attribute slug to api:
Browse files Browse the repository at this point in the history
  • Loading branch information
kencochrane committed Sep 29, 2013
1 parent 1c016c1 commit 28d7640
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions scorinator/score/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.http import Http404

from rest_framework import viewsets, permissions
from rest_framework.views import APIView
from rest_framework.response import Response

from .models import ProjectScore, ScoreAttribute, ProjectScoreAttribute
from .serializers import (
Expand All @@ -22,3 +26,18 @@ class ProjectScoreAttribute(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated,]
model = ProjectScoreAttribute
serializer_class = ProjectScoreAttributeSerializer

class ScoreAttributeDetail(APIView):
"""
Retrieve, score attrribute instance.
"""
def get_object(self, slug):
try:
return ScoreAttribute.objects.get(slug=slug)
except ScoreAttribute.DoesNotExist:
raise Http404

def get(self, request, slug, format=None):
score = self.get_object(slug)
serializer = ScoreAttributeSerializer(score)
return Response(serializer.data)
6 changes: 4 additions & 2 deletions scorinator/scorinator/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from core.views import HomeView
from project.viewsets import ProjectViewSet
from score.viewsets import (
ProjectScoreViewSet, ScoreAttributeViewSet, ProjectScoreAttribute)
from score.viewsets import (ProjectScoreViewSet, ScoreAttributeViewSet,
ProjectScoreAttribute, ScoreAttributeDetail)


router = routers.DefaultRouter()
Expand All @@ -24,6 +24,8 @@

# TODO we may want to disable this later post development.
# for now, it's useful to understand what is available
#TODO: this is a little hack to get the query by slug, replace with better way later
url(r'^api/v1/score-attributes/(?P<slug>[\w-]+)/$', ScoreAttributeDetail.as_view()),
url(r'^api/v1/', include(router.urls)),
url(r'^__admin__/', include(admin.site.urls)),

Expand Down

0 comments on commit 28d7640

Please sign in to comment.