# Path: radioco/apps/schedules/utils.py
# def next_dates(calendar, programme, after):
#     """
#     Returns: A generator with the next dates of a given programme
#     """
#     if not calendar or not calendar.id:
#         return
# 
#     from radioco.apps.schedules.models import Schedule
#     # Only taking into account schedules which belong to the active calendar
#     schedules = Schedule.objects.filter(programme=programme, type='L', calendar=calendar)
# 
#     while True:
#         candidates = [s.date_after(after) for s in schedules]
#         try:
#             next_date = min([_dt for _dt in candidates if _dt is not None])
#         except ValueError:
#             break
# 
#         yield next_date
#         after = next_date + datetime.timedelta(seconds=1)
#         # schedules = filter(lambda t: t[1] is not None, zip(schedules, candidates))
#         schedules = [_tuple[0] for _tuple in zip(schedules, candidates) if _tuple[1] is not None]


import pytz
import datetime
from bs4 import BeautifulSoup
from ckeditor_uploader.fields import RichTextUploadingField
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import FieldError
from django.core.urlresolvers import reverse
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import Q
from django.db.models.signals import post_save, pre_save
from django.template.defaultfilters import slugify
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from radioco.apps.radioco.utils import field_has_changed
from radioco.apps.schedules.utils import next_dates
            from radioco.apps.global_settings.models import PodcastConfiguration
    # XXX ensure not decreasing
    current_season = models.PositiveIntegerField(
        validators=[MinValueValidator(1)], verbose_name=_("current season")
    )
    category = models.CharField(
        blank=True, null=True, max_length=50, choices=CATEGORY_CHOICES, verbose_name=_("category")
    )
    slug = models.SlugField(max_length=100, unique=True,
        help_text=_("Please DON'T change this value. It's used to build URL's."))
    _runtime = models.PositiveIntegerField(
        validators=[MinValueValidator(1)], verbose_name=_("runtime"), help_text=_("In minutes."))

    start_date = models.DateField(blank=True, null=True, verbose_name=_('start date'))
    end_date = models.DateField(blank=True, null=True, verbose_name=_('end date'))

    @property
    def synopsis_text(self):
        return BeautifulSoup(self.synopsis, "html.parser").text

    @property
    def runtime(self):
        if not self._runtime:
            raise FieldError(_('Runtime not set'))
        return datetime.timedelta(minutes=self._runtime)

    @runtime.setter
    def runtime(self, value):
        self._runtime = value

    @property

# Path: radioco/apps/schedules/utils.py
# def next_dates(calendar, programme, after):
#     """
#     Returns: A generator with the next dates of a given programme
#     """
#     if not calendar or not calendar.id:
#         return
# 
#     from radioco.apps.schedules.models import Schedule
#     # Only taking into account schedules which belong to the active calendar
#     schedules = Schedule.objects.filter(programme=programme, type='L', calendar=calendar)
# 
#     while True:
#         candidates = [s.date_after(after) for s in schedules]
#         try:
#             next_date = min([_dt for _dt in candidates if _dt is not None])
#         except ValueError:
#             break
# 
#         yield next_date
#         after = next_date + datetime.timedelta(seconds=1)
#         # schedules = filter(lambda t: t[1] is not None, zip(schedules, candidates))
#         schedules = [_tuple[0] for _tuple in zip(schedules, candidates) if _tuple[1] is not None]


# Path: radioco/apps/programmes/models.py
import pytz
import datetime
from bs4 import BeautifulSoup
from ckeditor_uploader.fields import RichTextUploadingField
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import FieldError
from django.core.urlresolvers import reverse
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import Q
from django.db.models.signals import post_save, pre_save
from django.template.defaultfilters import slugify
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from radioco.apps.radioco.utils import field_has_changed
from radioco.apps.schedules.utils import next_dates
            from radioco.apps.global_settings.models import PodcastConfiguration

    # XXX ensure not decreasing
    current_season = models.PositiveIntegerField(
        validators=[MinValueValidator(1)], verbose_name=_("current season")
    )
    category = models.CharField(
        blank=True, null=True, max_length=50, choices=CATEGORY_CHOICES, verbose_name=_("category")
    )
    slug = models.SlugField(max_length=100, unique=True,
        help_text=_("Please DON'T change this value. It's used to build URL's."))
    _runtime = models.PositiveIntegerField(
        validators=[MinValueValidator(1)], verbose_name=_("runtime"), help_text=_("In minutes."))

    start_date = models.DateField(blank=True, null=True, verbose_name=_('start date'))
    end_date = models.DateField(blank=True, null=True, verbose_name=_('end date'))

    @property
    def synopsis_text(self):
        return BeautifulSoup(self.synopsis, "html.parser").text

    @property
    def runtime(self):
        if not self._runtime:
            raise FieldError(_('Runtime not set'))
        return datetime.timedelta(minutes=self._runtime)

    @runtime.setter
    def runtime(self, value):
        self._runtime = value

    @property

    def start_dt(self):