Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/apigen/api.template.py b/planetstack/apigen/api.template.py
new file mode 100644
index 0000000..15995af
--- /dev/null
+++ b/planetstack/apigen/api.template.py
@@ -0,0 +1,63 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from core.models import *
+from django.forms import widgets
+
+"""
+ Schema of the generator object:
+ all: Set of all Model objects
+ all_if(regex): Set of Model objects that match regex
+
+ Model object:
+ plural: English plural of object name
+ camel: CamelCase version of object name
+ refs: list of references to other Model objects
+
+ TODO: Deal with subnets
+"""
+
+# Based on api_root.py
+
+@api_view(['GET'])
+def api_root(request, format=None):
+ return Response({
+ {% for object in generator.all %}
+ '{{ object.plural }}': reverse('{{ object }}-list', request=request, format=format),
+ {% endfor %}
+ })
+
+# Based on serializers.py
+
+{% for object in generator.all %}
+
+class {{ object.camel }}Serializer(serializers.HyperlinkedModelSerializer):
+ id = serializers.Field()
+ {% for ref in object.refs %}
+ sites = serializers.HyperlinkedRelatedField(view_name='{{ ref }}-detail')
+ {% endfor %}
+ class Meta:
+ model = {{ object }}
+ fields = ('id',{% for ref in object.refs %}'{{ ref }}',{% endfor %})
+{% endfor %}
+
+serializerLookUp = {
+{% for object in generator.all %}
+ {{ object.camel }}: {{ object.camel }}Serializer,
+{% endfor %}
+ None: None,
+ }
+
+# Based on core/views/*.py
+{% for object in generator.all %}
+
+class {{ object.camel }}List(generics.ListCreateAPIView):
+ queryset = {{ object.camel }}.objects.all()
+ serializer_class = {{ object.camel }}Serializer
+
+class {{ object.camel }}Detail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = {{ object.camel }}.objects.all()
+ serializer_class = {{ object.camel }}Serializer
+
+{% endfor %}
diff --git a/planetstack/dmdot b/planetstack/dmdot
index 2d95e9d..b40d1af 100755
--- a/planetstack/dmdot
+++ b/planetstack/dmdot
@@ -20,6 +20,7 @@
g = globals()
model_classes = []
class_names = []
+
for c in g.values():
if type(c)==type(PlCoreBase):
model_classes.append(c)