When a channel is saved, check if the EPG data has changed. If so, trigger a refresh of the program data for the EPG.
(sender, instance, created, **kwargs)
| 193 | |
| 194 | @receiver(post_save, sender=Channel) |
| 195 | def refresh_epg_programs(sender, instance, created, **kwargs): |
| 196 | """ |
| 197 | When a channel is saved, check if the EPG data has changed. |
| 198 | If so, trigger a refresh of the program data for the EPG. |
| 199 | """ |
| 200 | # Check if this is an update (not a new channel) and the epg_data has changed |
| 201 | if not created and kwargs.get('update_fields') and 'epg_data' in kwargs['update_fields']: |
| 202 | logger.info(f"Channel {instance.id} ({instance.name}) EPG data updated, refreshing program data") |
| 203 | if instance.epg_data: |
| 204 | if instance.epg_data.epg_source and instance.epg_data.epg_source.source_type == 'dummy': |
| 205 | return |
| 206 | logger.info(f"Triggering EPG program refresh for {instance.epg_data.tvg_id}") |
| 207 | parse_programs_for_tvg_id.delay(instance.epg_data.id) |
| 208 | # For new channels with EPG data, also refresh |
| 209 | elif created and instance.epg_data: |
| 210 | if instance.epg_data.epg_source and instance.epg_data.epg_source.source_type == 'dummy': |
| 211 | return |
| 212 | logger.info(f"New channel {instance.id} ({instance.name}) created with EPG data, refreshing program data") |
| 213 | parse_programs_for_tvg_id.delay(instance.epg_data.id) |
| 214 | |
| 215 | @receiver(post_save, sender=ChannelProfile) |
| 216 | def create_profile_memberships(sender, instance, created, **kwargs): |