Merge pull request #2648 from normanjaeckel/FixBroadcastOnDelete

Fixed projector broadcast if projector is deleted. Fixed #2646.
This commit is contained in:
Emanuel Schütze 2016-11-20 22:43:47 +01:00 committed by GitHub
commit 829acce22d

View File

@ -214,13 +214,20 @@ class ProjectorViewSet(ModelViewSet):
result = False result = False
return result return result
# Assign all ProjectionDefault objects from this projector to the default projector (pk=1).
def destroy(self, *args, **kwargs): def destroy(self, *args, **kwargs):
"""
REST API operation for DELETE requests.
Assigns all ProjectionDefault objects from this projector to the
default projector (pk=1). Resets broadcast if set to this projector.
"""
projector_instance = self.get_object() projector_instance = self.get_object()
for projection_default in ProjectionDefault.objects.all(): for projection_default in ProjectionDefault.objects.all():
if projection_default.projector.id == projector_instance.id: if projection_default.projector.id == projector_instance.id:
projection_default.projector_id = 1 projection_default.projector_id = 1
projection_default.save() projection_default.save()
if config['projector_broadcast'] == projector_instance.pk:
config['projector_broadcast'] = 0
return super(ProjectorViewSet, self).destroy(*args, **kwargs) return super(ProjectorViewSet, self).destroy(*args, **kwargs)
@detail_route(methods=['post']) @detail_route(methods=['post'])