Complete the view of a single example.

This commit is contained in:
Nicolas Setton
2017-07-21 15:59:27 -04:00
parent 014ded7ec2
commit fc6ccd2717
2 changed files with 10 additions and 5 deletions

View File

@@ -63,12 +63,17 @@ def examples(request):
@api_view(['GET'])
def example(request, name):
# TODO: create an example serializer
# TODO: catch case where the example does not exist
e = Example.objects.filter(name=name)[0]
matches = Example.objects.filter(name=name)
if not matches:
return Response()
e = matches[0]
resources = []
for r in e.resources.all():
serializer = ResourceSerializer(r)
resources.append(serializer.data)
# TODO: add example metadata to the result
result = {'resources': resources}
result = {'name': e.name,
'description': e.description,
'resources': resources}
return Response(result)

View File

@@ -13,4 +13,4 @@ Add -u <login>:<password> when using authentication
curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/check_program/ --data "{\"program\": \"hello\"}" --header "Content-Type:application/json"
# get the examples
curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/examples/ --header "Content-Type:application/json"
curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/examples/ --header "Content-Type:application/json"