(self, request, format=None)
| 828 | responses={200: ProgramDataSerializer(many=True)}, |
| 829 | ) |
| 830 | def get(self, request, format=None): |
| 831 | # Use current time instead of midnight |
| 832 | now = timezone.now() |
| 833 | one_hour_ago = now - timedelta(hours=1) |
| 834 | twenty_four_hours_later = now + timedelta(hours=24) |
| 835 | logger.debug( |
| 836 | f"EPGGridAPIView: Querying programs between {one_hour_ago} and {twenty_four_hours_later}." |
| 837 | ) |
| 838 | |
| 839 | programs = ProgramData.objects.filter( |
| 840 | end_time__gt=one_hour_ago, |
| 841 | start_time__lt=twenty_four_hours_later, |
| 842 | ) |
| 843 | |
| 844 | # Generate dummy programs for channels that have no EPG data OR dummy EPG sources |
| 845 | from apps.channels.models import Channel |
| 846 | from apps.epg.models import EPGSource |
| 847 | from django.db.models import Q |
| 848 | |
| 849 | # Get channels with no EPG data at all (standard dummy) |
| 850 | channels_without_epg = Channel.objects.filter(Q(epg_data__isnull=True)) |
| 851 | |
| 852 | # Get channels with custom dummy EPG sources (generate on-demand with patterns) |
| 853 | channels_with_custom_dummy = Channel.objects.filter( |
| 854 | epg_data__epg_source__source_type='dummy' |
| 855 | ).select_related('epg_data__epg_source').distinct() |
| 856 | |
| 857 | # Log what we found |
| 858 | without_count = channels_without_epg.count() |
| 859 | custom_count = channels_with_custom_dummy.count() |
| 860 | |
| 861 | if without_count > 0: |
| 862 | channel_names = [f"{ch.name} (ID: {ch.id})" for ch in channels_without_epg] |
| 863 | logger.debug( |
| 864 | f"EPGGridAPIView: Channels needing standard dummy EPG: {', '.join(channel_names)}" |
| 865 | ) |
| 866 | |
| 867 | if custom_count > 0: |
| 868 | channel_names = [f"{ch.name} (ID: {ch.id})" for ch in channels_with_custom_dummy] |
| 869 | logger.debug( |
| 870 | f"EPGGridAPIView: Channels needing custom dummy EPG: {', '.join(channel_names)}" |
| 871 | ) |
| 872 | |
| 873 | logger.debug( |
| 874 | f"EPGGridAPIView: Found {without_count} channels needing standard dummy, {custom_count} needing custom dummy EPG." |
| 875 | ) |
| 876 | |
| 877 | # Serialize the regular programs using .values() to bypass DRF overhead |
| 878 | programs_qs = programs.values( |
| 879 | 'id', 'start_time', 'end_time', 'title', 'sub_title', |
| 880 | 'description', 'tvg_id', 'custom_properties', |
| 881 | ) |
| 882 | serialized_programs = [] |
| 883 | for p in programs_qs: |
| 884 | cp = p['custom_properties'] or {} |
| 885 | premiere_text = cp.get('premiere_text', '') |
| 886 | serialized_programs.append({ |
| 887 | 'id': p['id'], |
no test coverage detected