airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [1/4] airavata-django-portal git commit: Adding project's experiments to ProjectViewSet
Date Tue, 19 Sep 2017 18:07:02 GMT
Repository: airavata-django-portal
Updated Branches:
  refs/heads/master 4253233ff -> 4147972a1


Adding project's experiments to ProjectViewSet


Project: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/commit/0a2bc1c5
Tree: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/tree/0a2bc1c5
Diff: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/diff/0a2bc1c5

Branch: refs/heads/master
Commit: 0a2bc1c50cc53dfd030c6bec170f2d380ebf2404
Parents: 4253233
Author: Marcus Christie <machrist@iu.edu>
Authored: Mon Sep 18 09:19:59 2017 -0400
Committer: Marcus Christie <machrist@iu.edu>
Committed: Mon Sep 18 09:19:59 2017 -0400

----------------------------------------------------------------------
 django_airavata/apps/api/serializers.py |  4 ++--
 django_airavata/apps/api/urls.py        | 10 +++++++++-
 django_airavata/apps/api/views.py       | 17 +++++++----------
 3 files changed, 18 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/0a2bc1c5/django_airavata/apps/api/serializers.py
----------------------------------------------------------------------
diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py
index d13b718..7f38bf1 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -42,13 +42,13 @@ class GatewayIdDefaultField(serializers.CharField):
         self.default = settings.GATEWAY_ID
 
 class ProjectSerializer(serializers.Serializer):
-    url = FullyEncodedHyperlinkedIdentityField(view_name='project-detail', lookup_field='projectID',
lookup_url_kwarg='pk')
+    url = FullyEncodedHyperlinkedIdentityField(view_name='project-detail', lookup_field='projectID',
lookup_url_kwarg='project_id')
     projectID = serializers.CharField(read_only=True)
     name = serializers.CharField(required=True)
     description = serializers.CharField(required=False)
     owner = GatewayUsernameDefaultField()
     gatewayId = GatewayIdDefaultField()
-    experiments = FullyEncodedHyperlinkedIdentityField(view_name='api_project_experiments_list',
lookup_field='projectID', lookup_url_kwarg='project_id')
+    experiments = FullyEncodedHyperlinkedIdentityField(view_name='project-experiments', lookup_field='projectID',
lookup_url_kwarg='project_id')
 
     def create(self, validated_data):
         return Project(**validated_data)

http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/0a2bc1c5/django_airavata/apps/api/urls.py
----------------------------------------------------------------------
diff --git a/django_airavata/apps/api/urls.py b/django_airavata/apps/api/urls.py
index 544c07b..750e677 100644
--- a/django_airavata/apps/api/urls.py
+++ b/django_airavata/apps/api/urls.py
@@ -5,6 +5,10 @@ from django.conf.urls import include, url
 from rest_framework import routers
 from rest_framework.urlpatterns import format_suffix_patterns
 
+import logging
+
+logger = logging.getLogger(__name__)
+
 router = routers.SimpleRouter()
 router.register(r'projects', views.ProjectViewSet, base_name='project')
 
@@ -13,10 +17,14 @@ urlpatterns = [
     # url(r'^projects/$', views.ProjectList.as_view(), name='api_project_list'),
     # More specific, longer URLs should come before less specific, shorter ones
     # since the regular expression for project_id allows any character, even '/'
-    url(r'^projects/(?P<project_id>.+)/experiments/$', views.ProjectExperimentList.as_view(),
name='api_project_experiments_list'),
+    # url(r'^projects/(?P<project_id>.+)/experiments/$', views.ProjectExperimentList.as_view(),
name='api_project_experiments_list'),
     # url(r'^projects/(?P<project_id>.+)/$', views.ProjectDetail.as_view(), name='api_project_detail'),
     url(r'^experiments/$', views.ExperimentList.as_view(), name='api_experiment_list'),
     url(r'^', include(router.urls)),
 ]
 
+if logger.isEnabledFor(logging.DEBUG):
+    for url in router.urls:
+        logger.debug("router url: {}".format(url))
+
 urlpatterns = format_suffix_patterns(urlpatterns)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/0a2bc1c5/django_airavata/apps/api/views.py
----------------------------------------------------------------------
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index 2de3ba8..1181fa3 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -2,7 +2,7 @@
 from . import serializers
 
 from rest_framework import status, mixins
-from rest_framework.decorators import api_view
+from rest_framework.decorators import api_view, detail_route
 from rest_framework.views import APIView
 from rest_framework.viewsets import GenericViewSet
 from rest_framework.response import Response
@@ -81,6 +81,7 @@ class CreateUpdateRetrieveListViewSet(mixins.CreateModelMixin,
 class ProjectViewSet(CreateUpdateRetrieveListViewSet):
 
     serializer_class = serializers.ProjectSerializer
+    lookup_field = 'project_id'
 
     def get_list(self):
         # TODO: support pagination
@@ -98,6 +99,11 @@ class ProjectViewSet(CreateUpdateRetrieveListViewSet):
         project = serializer.save()
         self.request.airavata_client.updateProject(self.authz_token, project.projectID, project)
 
+    @detail_route()
+    def experiments(self, request, project_id=None):
+        experiments = request.airavata_client.getExperimentsInProject(self.authz_token, project_id,
-1, 0)
+        serializer = serializers.ExperimentSerializer(experiments, many=True, context={'request':
request})
+        return Response(serializer.data)
 
 class ExperimentList(APIView):
     def get(self, request, format=None):
@@ -107,12 +113,3 @@ class ExperimentList(APIView):
         experiments = request.airavata_client.getUserExperiments(request.authz_token, gateway_id,
username, -1, 0)
         serializer = serializers.ExperimentSerializer(experiments, many=True, context={'request':
request})
         return Response(serializer.data)
-
-class ProjectExperimentList(APIView):
-    def get(self, request, project_id, format=None):
-        gateway_id = settings.GATEWAY_ID
-        username = request.user.username
-
-        experiments = request.airavata_client.getExperimentsInProject(request.authz_token,
project_id, -1, 0)
-        serializer = serializers.ExperimentSerializer(experiments, many=True, context={'request':
request})
-        return Response(serializer.data)


Mime
View raw message