Skip to content

Commit

Permalink
Add user_documents to API.
Browse files Browse the repository at this point in the history
  • Loading branch information
r-xyz committed Dec 9, 2024
1 parent 14b9d9b commit 6785bfc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions NEMO/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
TrainingSession,
UsageEvent,
User,
UserDocuments,
)


Expand Down Expand Up @@ -152,13 +153,16 @@ class Meta:


class UserSerializer(FlexFieldsSerializerMixin, ModelSerializer):
user_documents = serializers.PrimaryKeyRelatedField(many=True, read_only=True)

class Meta:
model = User
exclude = ["preferences"]
expandable_fields = {
"projects": ("NEMO.serializers.ProjectSerializer", {"many": True}),
"managed_projects": ("NEMO.serializers.ProjectSerializer", {"many": True}),
"groups": ("NEMO.serializers.GroupSerializer", {"many": True}),
"user_documents": ("NEMO.serializers.UserDocumentSerializer", {"many": True}),
"user_permissions": ("NEMO.serializers.PermissionSerializer", {"many": True}),
}

Expand All @@ -177,6 +181,17 @@ class Meta:
fields = "__all__"


class UserDocumentSerializer(FlexFieldsSerializerMixin, ModelSerializer):
user = PrimaryKeyRelatedField(many=False, queryset=User.objects.all(), allow_null=True, required=False)

class Meta:
model = UserDocuments
fields = "__all__"
expandable_fields = {
"user": ("NEMO.serializers.UserSerializer", {"many": False, "read_only": True}),
}


class ProjectSerializer(FlexFieldsSerializerMixin, ModelSerializer):
principal_investigators = PrimaryKeyRelatedField(
source="manager_set", many=True, queryset=User.objects.all(), allow_null=True, required=False
Expand Down
1 change: 1 addition & 0 deletions NEMO/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def sort_urls(url_path):
router.register(r"training_sessions", api.TrainingSessionViewSet)
router.register(r"usage_events", api.UsageEventViewSet)
router.register(r"users", api.UserViewSet)
router.register(r"user_documents", api.UserDocumentsViewSet)
router.registry.sort(key=sort_urls)

reservation_item_types = f'(?P<item_type>{"|".join(ReservationItemType.values())})'
Expand Down
9 changes: 9 additions & 0 deletions NEMO/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
TrainingSession,
UsageEvent,
User,
UserDocuments,
)
from NEMO.rest_pagination import NEMOPageNumberPagination
from NEMO.serializers import (
Expand Down Expand Up @@ -82,6 +83,7 @@
TrainingSessionSerializer,
UsageEventSerializer,
UserSerializer,
UserDocumentSerializer,
)
from NEMO.typing import QuerySetType
from NEMO.utilities import export_format_datetime, remove_duplicates
Expand Down Expand Up @@ -213,6 +215,13 @@ class UserViewSet(ModelViewSet):
}


class UserDocumentsViewSet(ModelViewSet):
filename = "user_documents"
queryset = UserDocuments.objects.all()
serializer_class = UserDocumentSerializer
filterset_fields = {"id": key_filters, "user": key_filters, "name": string_filters, "display_order": number_filters}


class ProjectDisciplineViewSet(ModelViewSet):
filename = "project_disciplines"
queryset = ProjectDiscipline.objects.all()
Expand Down

0 comments on commit 6785bfc

Please sign in to comment.