You've already forked code_examples_server
mirror of
https://github.com/AdaCore/code_examples_server.git
synced 2026-02-12 12:45:18 -08:00
Initial implementation for the /example request
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user