Commit 33c8da075299ecada6d1699e56940a65850cd6f4

Authored by Alexis Koralewski
1 parent ea903e92
Exists in dev

Adding SP_Period in API

CHANGELOG
1   -08-03-2022 (AKo): v0.4.2.0
  1 +12-04-2022 (AKo): v0.4.3.0
  2 + - Adding SP_Period in API
  3 + - Adding guitastro gitclone and installation of guitastro's python package in docker_build
  4 + - Addind git pull of guitastro in pyros.py
  5 +
  6 +08-04-2022 (AKo): v0.4.2.0
2 7 - Fixing pyros.py for classic installation (without docker)
3 8 - Add export for SP
4 9 - Handling exceptions in pyros_api.py
... ...
VERSION
1   -0.4.1.0
  1 +0.4.3.0
... ...
src/core/pyros_django/api/serializers.py
1   -from common.models import Institute, PyrosUser, ScienceTheme, ScientificProgram, Sequence, Plan, Album
  1 +from common.models import Institute, Period, PyrosUser, SP_Period, ScienceTheme, ScientificProgram, Sequence, Plan, Album
2 2 from rest_framework import serializers
3 3  
4 4  
  5 +
  6 +class InstituteSerializer(serializers.ModelSerializer):
  7 + class Meta:
  8 + model = Institute
  9 + fields = ["name"]
  10 +
  11 +
5 12 class UserSerializer(serializers.ModelSerializer):
6 13 user_level = serializers.StringRelatedField(many=True)
7   -
  14 + institute = InstituteSerializer(read_only=True)
8 15 class Meta:
9 16 model = PyrosUser
10 17 fields = ['url', 'username', 'email', 'institute',
... ... @@ -12,11 +19,11 @@ class UserSerializer(serializers.ModelSerializer):
12 19 depth = 1
13 20  
14 21  
15   -class InstituteSerializer(serializers.ModelSerializer):
  22 +class PeriodSerializer(serializers.ModelSerializer):
  23 +
16 24 class Meta:
17   - model = Institute
18   - fields = ["name"]
19   -
  25 + model = Period
  26 + fields = "__all__"
20 27  
21 28 class ScienceThemeSerializer(serializers.ModelSerializer):
22 29 class Meta:
... ... @@ -35,6 +42,12 @@ class ScientificProgramSerializer(serializers.ModelSerializer):
35 42 "description_long", "science_theme"]
36 43 #fields = "__all__"
37 44  
  45 +class SPPeriodSerializer(serializers.ModelSerializer):
  46 + period = PeriodSerializer(read_only=True)
  47 + scientific_program = ScientificProgramSerializer(read_only=True)
  48 + class Meta:
  49 + model = SP_Period
  50 + fields = ["id", "scientific_program","period", "quota_remaining", "over_quota_duration_remaining", "token_remaining"]
38 51  
39 52 class SequenceSerializer(serializers.ModelSerializer):
40 53 pyros_user = UserSerializer(read_only=True)
... ...
src/core/pyros_django/api/urls.py
... ... @@ -10,6 +10,7 @@ router.register(r'albums', views.AlbumViewSet)
10 10 router.register(r'plans', views.PlanViewSet)
11 11 router.register(r'full_sequences', views.FullSequenceViewSet)
12 12 router.register(r'scientific_programs', views.ScientificProgramViewSet)
  13 +router.register(r'sp_period', views.SPPeriodViewSet)
13 14  
14 15 urlpatterns = [
15 16 path('', include(router.urls)),
... ...
src/core/pyros_django/api/views.py
... ... @@ -6,8 +6,8 @@ from rest_framework.permissions import IsAuthenticated, AllowAny
6 6 from rest_framework.decorators import api_view, permission_classes, action
7 7 from django.core.validators import ValidationError
8 8 from src.core.pyros_django.user_manager import views as user_views
9   -from api.serializers import AlbumSerializer, FullSequenceSerializer, PlanSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer
10   -from common.models import PyrosUser, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User
  9 +from api.serializers import AlbumSerializer, FullSequenceSerializer, PlanSerializer, SPPeriodSerializer, ScientificProgramSerializer, SequenceSerializer, UserSerializer
  10 +from common.models import PyrosUser, SP_Period, ScientificProgram, Sequence, Album, Plan, UserLevel, SP_Period_User
11 11 from routine_manager.functions import check_sequence_file_validity
12 12 from rest_framework.request import Request
13 13 from django.db.models import Q
... ... @@ -115,6 +115,31 @@ class ScientificProgramViewSet(viewsets.ModelViewSet):
115 115 return user.get_scientific_program().order_by("-updated")
116 116  
117 117  
  118 +class SPPeriodViewSet(viewsets.ModelViewSet):
  119 + """
  120 + API endpoint that allows users to view their sp_periods
  121 + """
  122 + queryset = SP_Period.objects.all()
  123 + serializer_class = SPPeriodSerializer
  124 +
  125 + permission_classes = [IsAuthenticated]
  126 + http_method_names = ["get"]
  127 +
  128 + def get_queryset(self):
  129 + """
  130 + This view should return a list of all the sp_period
  131 + for the currently authenticated user.
  132 + """
  133 + user = self.request.user
  134 + user_role = str(UserLevel.objects.get(
  135 + priority=user.get_priority()).name)
  136 + if user_role in ("Unit-PI", "Unit-board", "Admin"):
  137 + return SP_Period.objects.all().order_by("-scientific_program")
  138 + else:
  139 + user_scientific_programs = user.get_scientific_program()
  140 + return SP_Period.objects.filter(scientific_program__in=user_scientific_programs).order_by("-scientific_program")
  141 +
  142 +
118 143 class FullSequenceViewSet(viewsets.ModelViewSet):
119 144 """
120 145 API endpoint that allows users to view their full sequences.
... ...