def delete(self, request, pk, format=None): alarmclock = self.get_object(pk) # remove the line from the crontab job_comment = "piclodio%s" % alarmclock.id CrontabManager.remove_job(job_comment) # remove from the database alarmclock.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def delete(self, request, pk, format=None): webradio = self.get_object(pk) # when we delete a web radio, all alarm based on this on will be deleted to, remove them from the contab before all_alarms_which_use_the_web_radio_to_delete = AlarmClock.objects.filter(webradio=webradio) for alarm in all_alarms_which_use_the_web_radio_to_delete: # remove the job from the crontab job_comment = "piclodio%s" % alarm.id CrontabManager.remove_job(job_comment) # then we can safely delete the web radio webradio.delete() return Response(status=status.HTTP_204_NO_CONTENT)
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)