start moving to nested serializers
@@ -12,6 +12,7 @@ from django.shortcuts import get_object_or_404
from django.utils import timezone as djangotime
from meshctrl.utils import get_login_token
from packaging import version as pyver
+from rest_framework import serializers
from rest_framework.decorators import api_view, permission_classes
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
@@ -166,6 +167,22 @@ class GetAgents(APIView):
class GetUpdateDeleteAgent(APIView):
permission_classes = [IsAuthenticated, AgentPerms]
+ class InputSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = Agent
+ fields = [
+ "monitoring_type",
+ "description",
+ "overdue_email_alert",
+ "overdue_text_alert",
+ "overdue_dashboard_alert",
+ "offline_time",
+ "overdue_time",
+ "check_interval",
+ "time_zone",
+ "site",
+ ]
+
# get agent details
def get(self, request, agent_id):
agent = get_object_or_404(Agent, agent_id=agent_id)
@@ -175,9 +192,9 @@ class GetUpdateDeleteAgent(APIView):
def put(self, request, agent_id):
agent = get_object_or_404(Agent, agent_id=agent_id)
- a_serializer = AgentSerializer(instance=agent, data=request.data, partial=True)
- a_serializer.is_valid(raise_exception=True)
- a_serializer.save()
+ s = self.InputSerializer(instance=agent, data=request.data, partial=True)
+ s.is_valid(raise_exception=True)
+ s.save()
if "winupdatepolicy" in request.data.keys():
policy = agent.winupdatepolicy.get() # type: ignore
