def perform_destroy(self, watch_tv_show: WatchTVShow): # delete all seasons, season requests, episodes and remove from transmission # delete season requests WatchTVSeasonRequest.objects.filter( watch_tv_show=watch_tv_show).delete() # delete instance and from transmission and send websocket messages queries = [ WatchTVSeason.objects.filter(watch_tv_show=watch_tv_show), WatchTVEpisode.objects.filter(watch_tv_show=watch_tv_show) ] for qs in queries: for media in qs: # send a websocket message that this media was removed media_type, data = websocket.get_media_type_and_serialized_watch_media( media) send_websocket_message_task.delay(websocket.ACTION_REMOVED, media_type, data) # delete from transmission destroy_transmission_result(media) # delete the media media.delete() return super().perform_destroy(watch_tv_show)
def perform_create(self, serializer): super().perform_create(serializer) # save a watch tv season instance to try and download the whole season immediately watch_tv_season, _ = WatchTVSeason.objects.get_or_create( watch_tv_show=WatchTVShow.objects.get( id=serializer.data['watch_tv_show']), season_number=serializer.data['season_number'], defaults=dict( # add non-unique constraint fields for the default values user=self.request.user, ), ) # send a websocket message for this new season media_type, data = websocket.get_media_type_and_serialized_watch_media( watch_tv_season) send_websocket_message_task.delay(websocket.ACTION_UPDATED, media_type, data) # delete any individual episodes (including in transmission) now that we're watching the entire season for episode in WatchTVEpisode.objects.filter( watch_tv_show=watch_tv_season.watch_tv_show, season_number=watch_tv_season.season_number): # send a websocket message for this removed episode media_type, data = websocket.get_media_type_and_serialized_watch_media( episode) send_websocket_message_task.delay(websocket.ACTION_REMOVED, media_type, data) # delete from transmission destroy_transmission_result(episode) # delete the episode episode.delete() # create a task to download the whole season (fallback to individual episodes if it fails) watch_tv_show_season_task.delay(watch_tv_season.id)
def perform_destroy(self, watch_tv_season_request: WatchTVSeasonRequest): # destroy all watch tv season & episode instances as well, including any related torrents in transmission query_args = dict( watch_tv_show=watch_tv_season_request.watch_tv_show, season_number=watch_tv_season_request.season_number, ) for season in WatchTVSeason.objects.filter(**query_args): destroy_transmission_result(season) season.delete() for episode in WatchTVEpisode.objects.filter(**query_args): destroy_transmission_result(episode) episode.delete() return super().perform_destroy(watch_tv_season_request)
def perform_destroy(self, watch_tv_season_request: WatchTVSeasonRequest): # destroy watch tv season instances as well, including any related torrents in transmission query_args = dict( watch_tv_show=watch_tv_season_request.watch_tv_show, season_number=watch_tv_season_request.season_number, ) for season in WatchTVSeason.objects.filter(**query_args): # send a websocket message that this season was removed media_type, data = websocket.get_media_type_and_serialized_watch_media( season) send_websocket_message_task.delay(websocket.ACTION_REMOVED, media_type, data) # delete from transmission destroy_transmission_result(season) # delete the season season.delete() return super().perform_destroy(watch_tv_season_request)
def perform_destroy(self, instance: WatchMediaBase): # delete transmission result, including data, if it still exists destroy_transmission_result(instance) super().perform_destroy(instance)