Ejemplo n.º 1
0
 def get_available_episodes(self):
     return Episodes.objects.filter(
         Q(AlbumId__HiddenAlbum=False),
         Q(DateReleased__lt=TimeUtils.user_now()),
         Q(AlbumId__AlbumId__in=self.purchased_albums_ids) |
         Q(AlbumId__PurchaseStatus=Albums.PURCHASE_TYPE_NOT_FOR_SALE)
     )
Ejemplo n.º 2
0
 def get_status(self):
     if self.is_current():
         return self.STATUS_CURRENT
     elif self.EndDate > TimeUtils.user_now().date():
         return self.STATUS_NEXT
     else:
         return self.STATUS_EXPIRED
Ejemplo n.º 3
0
 def get_status(self):
     if self.is_current():
         return self.STATUS_CURRENT
     elif self.EndDate > TimeUtils.user_now().date():
         return self.STATUS_NEXT
     else:
         return self.STATUS_EXPIRED
Ejemplo n.º 4
0
    def next_end_time(self):
        end_datetime = self._get_end_time()

        if end_datetime < TimeUtils.user_now():
            end_datetime += timedelta(days=1)

        return end_datetime
Ejemplo n.º 5
0
    def next_end_time(self):
        end_datetime = self._get_end_time()

        if end_datetime < TimeUtils.user_now():
            end_datetime += timedelta(days=1)

        return end_datetime
Ejemplo n.º 6
0
 def get_available_timeslots(self):
     today_utc = TimeUtils.user_now()
     weekday = str(today_utc.weekday())
     return TimeSlots.objects.select_related(depth=2)\
                             .filter(EndDate__gte=today_utc,
                                     StartDate__lte=today_utc,
                                     days__contains=weekday)\
                             .order_by('StartTime')
Ejemplo n.º 7
0
    def _get_end_time(self):
        end_datetime = TimeUtils.user_now().replace(hour=self.EndTime.hour,
                                                    minute=self.EndTime.minute,
                                                    second=self.EndTime.second)
        if self.EndTime < self.StartTime:
            end_datetime += timedelta(days=1)

        return end_datetime
Ejemplo n.º 8
0
 def get_available_timeslots(self):
     today_utc = TimeUtils.user_now()
     weekday = str(today_utc.weekday())
     return TimeSlots.objects.select_related(depth=2)\
                             .filter(EndDate__gte=today_utc,
                                     StartDate__lte=today_utc,
                                     days__contains=weekday)\
                             .order_by('StartTime')
Ejemplo n.º 9
0
    def _get_end_time(self):
        end_datetime = TimeUtils.user_now().replace(hour=self.EndTime.hour,
                                                    minute=self.EndTime.minute,
                                                    second=self.EndTime.second)
        if self.EndTime < self.StartTime:
            end_datetime += timedelta(days=1)

        return end_datetime
Ejemplo n.º 10
0
    def get_context_data(self):
        timeslots = self.get_available_timeslots()
        timeslots = [self.jsonify(timeslot) for timeslot in timeslots]
        timeslots.sort(cmp=GetTimeslots.cmp_timeslots)

        return {
            'CurrentTime': TimeUtils.user_now(),
            'Timeslots': timeslots,
        }
Ejemplo n.º 11
0
 def default(self, o):
     if isinstance(o, datetime):
         return str(TimeUtils.get_timestamp(o))
     elif isinstance(o, decimal.Decimal):
         return str(o)
     elif isinstance(o, CustomFieldFile):
         return o.get_url()
     else:
         return super(ApiJSONEncoder, self).default(o)
Ejemplo n.º 12
0
    def get_context_data(self):
        timeslots = self.get_available_timeslots()
        timeslots = [self.jsonify(timeslot) for timeslot in timeslots]
        timeslots.sort(cmp=GetTimeslots.cmp_timeslots)

        return {
            'CurrentTime': TimeUtils.user_now(),
            'Timeslots': timeslots,
        }
Ejemplo n.º 13
0
    def next_start_time(self):
        user_now = TimeUtils.user_now()

        start_datetime = user_now.replace(hour=self.StartTime.hour,
                                          minute=self.StartTime.minute,
                                          second=self.StartTime.second)
        if self._get_end_time() < user_now:
            start_datetime += timedelta(days=1)

        return start_datetime
Ejemplo n.º 14
0
    def next_start_time(self):
        user_now = TimeUtils.user_now()

        start_datetime = user_now.replace(hour=self.StartTime.hour,
                                          minute=self.StartTime.minute,
                                          second=self.StartTime.second)
        if self._get_end_time() < user_now:
            start_datetime += timedelta(days=1)

        return start_datetime
Ejemplo n.º 15
0
    def get_autoepisode(self, start_episode_id, start_time):
        d1 = TimeUtils.user_now()
        delta = d1 - datetime(start_time.year, start_time.month, start_time.day)

        video = self.caching.get_episode(start_episode_id)
        episodes = Episodes.objects.filter(AlbumId=video.AlbumId)\
                                   .order_by('EpisodeNo')
        if len(episodes) > delta.days:
            return episodes[delta.days]

        return None
Ejemplo n.º 16
0
    def get_autoepisode(self, start_episode_id, start_time):
        d1 = TimeUtils.user_now()
        delta = d1 - datetime(start_time.year, start_time.month,
                              start_time.day)

        video = self.caching.get_episode(start_episode_id)
        episodes = Episodes.objects.filter(AlbumId=video.AlbumId)\
                                   .order_by('EpisodeNo')
        if len(episodes) > delta.days:
            return episodes[delta.days]

        return None
Ejemplo n.º 17
0
    def clean_timezone(self):
        param_name = 'tz'

        if param_name not in self.params:
            raise ParameterExpected(parameter=param_name)

        timezone = self.params[param_name]
        try:
            user_timezone = pytz.timezone(timezone)
            user_now = TimeUtils.get_utc_now_as_local(user_timezone)

            LocalUserMiddleware.update(user_timezone=user_timezone,
                                       user_now=user_now)

        except pytz.exceptions.UnknownTimeZoneError:
            raise BadRequest(message='Unknown timezone.')
Ejemplo n.º 18
0
    def is_episode_on_air(self, episode):
        user_now = TimeUtils.user_now()
        today = user_now.date()
        date_released = episode.DateReleased.date()

        if date_released > today:
            return False
        if date_released <= today:
            return True

        timeslot_videos = self._get_timeslot_videos(episode)

        for video in timeslot_videos:
            if video.TimeSlotsId.next_start_time < user_now:
                return True

        return bool(timeslot_videos)
Ejemplo n.º 19
0
    def get_album_status(cls, album, released, updated):
        user_now = TimeUtils.user_now()

        if not album.episodes.all():
            status = album.STATUS_NORMAL
        elif released > user_now:
            status = album.STATUS_COMING_SOON
        else:
            # TODO: move PiptureSettings from huge models file and remove inline import
            # I use inline import to avoid importing pipture.models in this file
            #from restserver.pipture.models import PiptureSettings

            premiere_days = PiptureSettings.get().PremierePeriod
            premiere_period = timedelta(days=premiere_days)
            if updated >= user_now - premiere_period:
                status = album.STATUS_PREMIERE
            else:
                status = album.STATUS_NORMAL

        return status
Ejemplo n.º 20
0
 def is_current(self):
     return self.next_start_time < TimeUtils.user_now() < self.next_end_time
Ejemplo n.º 21
0
 def is_current(self):
     return self.next_start_time < TimeUtils.user_now() < self.next_end_time
Ejemplo n.º 22
0
 def is_episode_available(self, episode):
     return (episode.AlbumId.PurchaseStatus == Albums.PURCHASE_TYPE_NOT_FOR_SALE
             and episode.DateReleased < TimeUtils.user_now()) \
             or self.is_episode_purchased(episode)