コード例 #1
0
 def post(self, request, format=None):
     serializer = AlarmClockSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         # create a job line
         last_alarmclock = AlarmClock.objects.latest('id')
         Utils.add_job_in_crontab(last_alarmclock)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
 def put(self, request, pk, format=None):
     alarmclock = self.get_object(pk)
     serializer = AlarmClockSerializer(alarmclock, data=request.data)
     if serializer.is_valid():
         serializer.save()
         updated_alarmclock = AlarmClock.objects.get(pk=pk)
         # remove the job from the crontab
         job_comment = "piclodio%s" % updated_alarmclock.id
         CrontabManager.remove_job(job_comment)
         # add it back with new info
         Utils.add_job_in_crontab(updated_alarmclock)
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
 def get(self, request, pk, format=None):
     alarmclock = self.get_object(pk)
     serializer = AlarmClockSerializer(alarmclock)
     return Response(serializer.data)
コード例 #4
0
 def get(self, request, format=None):
     alarmclocks = AlarmClock.objects.all()
     serializer = AlarmClockSerializer(alarmclocks, many=True)
     return Response(serializer.data)