Beispiel #1
0
    def clean_album_and_timeslot(self):
        album_id = self.params.get('AlbumId', None)
        timeslot_id = self.params.get('TimeslotId', None)

        if album_id and timeslot_id:
            raise BadRequest(message="There is AlbumId and TimeslotId. Should be only one.")

        if not timeslot_id and not album_id:
            raise ParameterExpected(parameter="AlbumId or TimeslotId")

        if album_id:
            try:
                self.album = self.caching.get_album(album_id)
            except ValueError:
                raise WrongParameter(parameter='AlbumId')
            except Albums.DoesNotExist:
                raise NotFound(message='There is no album with id %s.' % album_id)

        if timeslot_id:
            try:
                timeslot = self.caching.get_timeslot(timeslot_id)
            except ValueError:
                raise WrongParameter(parameter='TimeslotId')
            except TimeSlots.DoesNotExist:
                raise NotFound(message="There is no timeslot with id %s." % timeslot_id)
            else:
                self.album = timeslot.AlbumId
    def clean_api(self):
        param_name = 'API'
        proper_api_value = '1'

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

        api_version = self.params[param_name]
        if api_version != proper_api_value:
            raise WrongParameter(parameter=param_name)
Beispiel #3
0
    def clean_episode(self):
        episode_id = self.params.get('EpisodeId', None)

        if not episode_id:
            ParameterExpected(parameter='EpisodeId')

        try:
            self.episode = self.caching.get_episode(episode_id)
        except ValueError:
            raise WrongParameter(parameter='EpisodeId')
        except Episodes.DoesNotExist:
            raise NotFound(message='There is no episode with id %s.' % episode_id)
Beispiel #4
0
    def clean_views_count(self):
        views_count = self.params.get('ViewsCount', None)
        if not views_count:
            raise ParameterExpected(parameter='ViewsCount')

        try:
            self.views_count = int(views_count)
            if self.views_count != SendMessage.UNLIMITED_VIEWS and \
                    (self.views_count > SendMessage.MAX_VIEWS_LIMIT or
                     self.views_count < SendMessage.MIN_VIEWS_LIMIT):
                raise WrongParameter(parameter='ViewsCount')
        except ValueError:
            raise WrongParameter(parameter='ViewsCount')
Beispiel #5
0
    def clean_timeslot(self):
        timeslot_id = self.params.get('TimeslotId', 0)

        if not timeslot_id:
            raise ParameterExpected(parameter='TimeslotId')

        try:
            self.timeslot = self.caching.get_timeslot(timeslot_id)
        except ValueError:
            raise WrongParameter(parameter='TimeslotId')
        except TimeSlots.DoesNotExist:
            raise NotFound\
                (message='There is no timeslot with id %s' % timeslot_id)
Beispiel #6
0
    def clean_uuid(self):
        user_uid = self.params.get('UUID', None)

        if not user_uid:
            raise ParameterExpected(parameter='UUID')

        try:
            self.pip_user = PipUsers.objects.get(UserUID=user_uid)
            if not self.pip_user.Purchaser:
                new_purchaser = Purchasers()
                new_purchaser.save()
                self.pip_user.Purchaser = new_purchaser
                self.pip_user.save()

        except PipUsers.DoesNotExist:
            raise UnauthorizedError()
    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.')
Beispiel #8
0
    def clean_query(self):
        query = self.params.get('query', None)
        if not query:
            raise ParameterExpected(parameter='query')

        self.search_query = lovins.remove_ending(query)
Beispiel #9
0
    def clean_username(self):
        self.user_name = self.params.get('UserName', None)

        if not self.user_name:
            raise ParameterExpected(parameter='UserName')