diff --git a/README.md b/README.md index 41bee51..2bc56fd 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,13 @@ To setup, do this: ```sh virtualenv env pip install -r REQUIREMENTS.txt + ./manage.py makemigrations + ./manage.py migrate +``` + +To enter some examples in the database, do this: +```sh +./manage.py fill_examples --dir=resources/example/a ``` To launch the server, do this: diff --git a/compile_server/app/serializers.py b/compile_server/app/serializers.py index 5d39f7f..17a6614 100644 --- a/compile_server/app/serializers.py +++ b/compile_server/app/serializers.py @@ -20,7 +20,7 @@ class ResourceSerializer(serializers.Serializer): model = Resource fields = ('basename', 'code') - code = serializers.CharField(style={'base_template': 'textarea.html'}) + contents = serializers.CharField(style={'base_template': 'textarea.html'}) basename = serializers.CharField(style={'base_template': 'textarea.html'}) def create(self, validated_data): diff --git a/compile_server/app/views.py b/compile_server/app/views.py index 6c57d6a..0c18dae 100644 --- a/compile_server/app/views.py +++ b/compile_server/app/views.py @@ -49,13 +49,6 @@ def check_program(request): return Response(serializer.data) -@api_view(['GET']) -def resources(request, example_name): - """Return the list of resources for the given example""" - # TODO - return Response() - - @api_view(['GET']) def examples(request): """Return a list of example names and their description""" @@ -69,4 +62,13 @@ def examples(request): @api_view(['GET']) def example(request, name): - return Response() + # TODO: create an example serializer + # TODO: catch case where the example does not exist + e = Example.objects.filter(name=name)[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} + return Response(result) diff --git a/compile_server/urls.py b/compile_server/urls.py index 9190aa2..fff971f 100644 --- a/compile_server/urls.py +++ b/compile_server/urls.py @@ -37,5 +37,5 @@ urlpatterns = [ url(r'^examples/', views.examples), # Get the details on one example - url(r'^example/([^/])+', views.example), + url(r'^example/([^\/]+)$', views.example), ]