Skip to content

Commit

Permalink
Merge pull request #338 from fasrc/cp_api_auth
Browse files Browse the repository at this point in the history
API report views
  • Loading branch information
claire-peters authored Sep 13, 2024
2 parents 495aeea + b6b84f7 commit a83aefd
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 45 deletions.
14 changes: 0 additions & 14 deletions coldfront/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
'django_tables2',
'table',
'rest_framework_datatables',
'rest_framework',
'easy_pdf',
]

Expand Down Expand Up @@ -148,19 +147,6 @@
},
]

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
'rest_framework_datatables.renderers.DatatablesRenderer',
),
'DEFAULT_FILTER_BACKENDS': (
'rest_framework_datatables.filters.DatatablesFilterBackend',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework_datatables.pagination.DatatablesPageNumberPagination',
'PAGE_SIZE': 500,
}

# Add local site templates files if set
SITE_TEMPLATES = ENV.str('SITE_TEMPLATES', default='')
if len(SITE_TEMPLATES) > 0:
Expand Down
8 changes: 4 additions & 4 deletions coldfront/config/plugins/api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from coldfront.config.base import INSTALLED_APPS

INSTALLED_APPS += [
'django_filters',
'coldfront.plugins.api'
]
'django_filters',
'rest_framework',
'coldfront.plugins.api',
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated'
Expand Down
43 changes: 37 additions & 6 deletions coldfront/plugins/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,27 @@ class Meta:
'usage',
'pct_full',
'cost',
'created',
)

def get_type(self, obj):
resource = obj.get_parent_resource
if resource:
return resource.resource_type.name
return None


class AllocationRequestSerializer(serializers.ModelSerializer):
project = serializers.SlugRelatedField(slug_field='title', read_only=True)
resource = serializers.ReadOnlyField(source='get_resources_as_string', read_only=True)
pi = serializers.ReadOnlyField(source='project.pi.full_name')
resource = serializers.ReadOnlyField(source='get_parent_resource.name', allow_null=True)
tier = serializers.ReadOnlyField(source='get_parent_resource.parent_resource.name', allow_null=True)
status = serializers.SlugRelatedField(slug_field='name', read_only=True)
fulfilled_date = serializers.DateTimeField(read_only=True)
requested_size = serializers.ReadOnlyField(source='quantity')
current_size = serializers.ReadOnlyField(source='size')
created = serializers.DateTimeField(format="%Y-%m-%d %H:%M", read_only=True)
created_by = serializers.SerializerMethodField(read_only=True)
fulfilled_date = serializers.DateTimeField(format="%Y-%m-%d %H:%M", read_only=True)
fulfilled_by = serializers.SerializerMethodField(read_only=True)
time_to_fulfillment = serializers.DurationField(read_only=True)

Expand All @@ -111,10 +123,13 @@ class Meta:
fields = (
'id',
'project',
'pi',
'resource',
'tier',
'path',
'status',
'size',
'requested_size',
'current_size',
'created',
'created_by',
'fulfilled_date',
Expand All @@ -139,10 +154,14 @@ def get_fulfilled_by(self, obj):


class AllocationChangeRequestSerializer(serializers.ModelSerializer):
allocation = AllocationSerializer(read_only=True)
project = serializers.ReadOnlyField(source='allocation.project.title')
pi = serializers.ReadOnlyField(source='allocation.project.pi.full_name')
resource = serializers.ReadOnlyField(source='allocation.get_resources_as_string')
tier = serializers.ReadOnlyField(source='allocation.get_parent_resource.parent_resource.name', allow_null=True)
status = serializers.SlugRelatedField(slug_field='name', read_only=True)
created = serializers.DateTimeField(format="%Y-%m-%d %H:%M", read_only=True)
created_by = serializers.SerializerMethodField(read_only=True)
fulfilled_date = serializers.DateTimeField(read_only=True)
fulfilled_date = serializers.DateTimeField(format="%Y-%m-%d %H:%M", read_only=True)
fulfilled_by = serializers.SerializerMethodField(read_only=True)
time_to_fulfillment = serializers.DurationField(read_only=True)

Expand All @@ -151,6 +170,10 @@ class Meta:
fields = (
'id',
'allocation',
'project',
'pi',
'resource',
'tier',
'justification',
'status',
'created',
Expand Down Expand Up @@ -205,7 +228,15 @@ class ProjectSerializer(serializers.ModelSerializer):

class Meta:
model = Project
fields = ('id', 'title', 'pi', 'status', 'project_users', 'allocations')
fields = (
'id',
'title',
'pi',
'status',
'project_users',
'allocations',
'created',
)

def get_project_users(self, obj):
request = self.context.get('request', None)
Expand Down
Loading

0 comments on commit a83aefd

Please sign in to comment.