コード例 #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
コード例 #2
0
ファイル: messages.py プロジェクト: pipture/Old-App-iPhone
    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')
コード例 #3
0
    def perform_other_operations(self):
        fresh_transaction = self.transaction_id == self.original_transaction_id
        if not fresh_transaction and self.restore_purchased_item():
            return True

        album_id = None

        if self.product[:29] == self.APPLE_PRODUCT_ALBUM_BUY:
            album_id = self.product[29:]

        if self.product[:30] == self.APPLE_PRODUCT_ALBUM_PASS:
            album_id = self.product[30:]

        if album_id is None:
            raise WrongParameter(parameter='Product')

        album_purchase_item = PurchaseItems.objects.get(Description='Album')
        AppleTransactionId \
            = self.transaction_id if fresh_transaction else self.original_transaction_id
        purchased_item = UserPurchasedItems(
            Purchaser=self.user.Purchaser,
            ItemId=int(album_id),
            PurchaseItemId=album_purchase_item,
            ItemCost=0,
            AppleTransactionId=AppleTransactionId)
        purchased_item.save()
コード例 #4
0
 def _clean_episode(self):
     try:
         return Episodes.objects.get(EpisodeId=self.episode_id)
     except ValueError:
         raise WrongParameter(parameter='EpisodeId')
     except Episodes.DoesNotExist:
         raise NotFound( message='There is no episode with id %s' % self.episode_id)
コード例 #5
0
 def _clean_trailer(self):
     try:
         return Trailers.objects.get(TrailerId=self.trailer_id)
     except ValueError:
         raise WrongParameter(parameter='TrailerId')
     except Trailers.DoesNotExist:
         raise NotFound(message='There is no trailer with id %s' % self.trailer_id)
コード例 #6
0
ファイル: videos.py プロジェクト: pipture/Old-App-iPhone
    def clean_quality(self):
        try:
            self.video_quality = int(self.params.get('q', 0))
        except ValueError:
            raise WrongParameter(parameter='q')

        if self.video_quality > 1:
            self.video_quality = 1
コード例 #7
0
ファイル: videos.py プロジェクト: pipture/Old-App-iPhone
    def clean_timeslot(self):
        self.timeslot_id = self.params.get('TimeslotId', None)

        try:
            self.timeslot = self.caching.get_timeslot(self.timeslot_id)
        except ValueError:
            raise WrongParameter(parameter='TimeslotId')
        except TimeSlots.DoesNotExist:
            self.timeslot = None
コード例 #8
0
    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)
コード例 #9
0
    def clean_episode(self):
        episode_id = self.params.get('EpisodeId', None)

        try:
            self.episode = episode_id and self.caching.get_episode(episode_id)
            if not self.episode or self.episode.AlbumId.PurchaseStatus == Albums.PURCHASE_TYPE_NOT_FOR_SALE:
                self.episode = None
        except ValueError:
            raise WrongParameter(parameter='EpisodeId')
        except Episodes.DoesNotExist:
            self.episode = None
コード例 #10
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)
コード例 #11
0
ファイル: videos.py プロジェクト: pipture/Old-App-iPhone
    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)
コード例 #12
0
    def perform_credits_oprations(self):
        try:
            apple_product = AppleProducts.objects.get(ProductId=self.product)
        except AppleProducts.DoesNotExist:
            raise WrongParameter(parameter='Product')

        cost = Decimal(apple_product.ViewsCount * self.quantity)

        try:
            transaction = Transactions(Purchaser=self.user.Purchaser,
                                       ProductId=apple_product,
                                       Cost=cost,
                                       ViewsCount=apple_product.ViewsCount,
                                       AppleTransactionId=self.transaction_id)
            transaction.save()
        except IntegrityError:
            raise Conflict(message='Duplicated transaction.')

        self.user.Purchaser.Balance += cost
        self.user.Purchaser.save()
コード例 #13
0
ファイル: videos.py プロジェクト: pipture/Old-App-iPhone
 def clean_preview(self):
     try:
         self.video_preview = int(self.params.get('preview', 0))
     except ValueError:
         raise WrongParameter(parameter='preview')