def validate_local_variables(self):
        if (self.transaction_detail_class == None):
            raise VariableNotSetException(
                type(self).__name__, "transaction_detail_class")
        if (self.balance_class == None):
            raise VariableNotSetException(type(self).__name__, "balance_class")
        if (not issubclass(self.transaction_detail_class, TransactionDetail)):
            raise IncorrectVariableTypeException(
                type(self).__name__, "transaction_detail_class")
        if (not issubclass(self.balance_class, Balance)):
            raise IncorrectVariableTypeException(
                type(self).__name__, "balance_class")

        return
示例#2
0
 def validate_variable(self, expected_class, variable=None):
     if variable is not None:
         #
         # validate the contest is an instance of contest.models.Contest
         if not isinstance(variable, expected_class):
             raise IncorrectVariableTypeException(
                 type(self).__name__, 'contest')
示例#3
0
    def validate_local_variables(self):
        if (self.withdraw_class == None):
            raise VariableNotSetException(
                type(self).__name__, "withdraw_class")

        if (not issubclass(self.withdraw_class, models.Withdraw)):
            raise IncorrectVariableTypeException(
                type(self).__name__, "withdraw_class")
示例#4
0
 def validate_variable_array(self, expected_class, variable_array=[]):
     self.validate_variable(list, variable_array)
     for variable in variable_array:
         #
         # validate the contest is an instance of contest.models.Contest
         if not isinstance(variable, expected_class):
             raise IncorrectVariableTypeException(
                 type(self).__name__, 'contest')
示例#5
0
    def __validate_livestat(self, livestat):
        """
        validates livestat parameter

        :param livestat:
        :raises IncorrectVariableTypeException: when 'livestat' param is not the expected type
        :return:
        """
        if not issubclass(type(livestat), Hashable):
            raise IncorrectVariableTypeException(type(self).__name__, 'livestat')
示例#6
0
    def validate_amount(self, amount):
        """
        adds additional type checking. make sure super().validate_amount() is called last.
        :return:
        """
        try:
            amount = float(amount)
        except ValueError:
            raise IncorrectVariableTypeException(self.__class__.__name__,
                                                 'amount: [%s]' % str(amount))

        super().validate_amount(amount)
    def __check_sport(self, sport):
        """
        Validates the sport exists

        :param sport: the string representation of a specified sport

        :raises :class:`sports.exceptions.SportNameException`: when the string sport
            does not match a sport in the sports array
        """
        #
        # Makes sure the player_stats_object is an instance
        # of the subclass PlayerStats
        if not isinstance(sport, SiteSport):
            raise IncorrectVariableTypeException(
                type(self).__name__,
                type(sport).__name__)
示例#8
0
    def __init__(self, amount_model, name='default'):
        self.prize_structure = None
        self.buyin = None
        self.prize_structure_model = PrizeStructure
        self.rank_model = Rank
        self.ranks = None  # list of the rank instances once generated
        self.added_ranks = [
        ]  # if ranks are added to this class, add them as (rank, value) tuples here

        if not amount_model:
            raise VariableNotSetException(type(self).__name__, 'amount_model')
        if not issubclass(amount_model, AbstractAmount):
            raise IncorrectVariableTypeException(
                type(self).__name__, 'amount_model')
        self.amount_model = amount_model

        self.name = self.get_unique_name(
            name)  # return a name based on the one specified that is unique
    def deposit(self, amount, transaction_obj=None):
        """
        Deposits a ticket for a given amount into the
        ticket system for a given user. .

        :param amount: the dollar value of the ticket being
            created.
        :raise :class:`mysite.exceptions.AmountZeroException`: if
            the amount is 0.
        :raise :class:`mysite.exceptions.AmounNegativeException`:
            if the amount argument is less than 0.

        """
        ta = self.get_ticket_amount(amount)

        #
        # creates a Transaction if it does not exists
        if (transaction_obj != None):
            #
            # Validates it is trulya Transaction Object
            if (not isinstance(transaction_obj, Transaction)):
                raise IncorrectVariableTypeException(
                    type(self).__name__, "transaction_obj")
            self.transaction = transaction_obj
        else:
            self.transaction = Transaction(
                user=self.user, category=self.__get_deposit_category())
            self.transaction.save()

        #
        # creates the ticket
        self.ticket = ticket.models.Ticket()
        self.ticket.deposit_transaction = self.transaction
        self.ticket.user = self.user
        self.ticket.amount = ta
        self.ticket.save()

        msg = "User[" + self.user.username + "] had a $" + str(
            self.ticket.amount.amount) + " ticket #" + str(
                self.ticket.pk) + " deposited into their ticket account."
        logger.info("action: Ticket Deposit message: %s" % msg)
示例#10
0
    def __init__(self, user, pk):
        """
        Initializes the variables
        :param user:
        :return:
        """

        # if the pk is valid, we want to use the user already
        # associated with the cash_transaction_detail
        if pk:
            try:
                pk = int(pk)
            except:
                raise IncorrectVariableTypeException(
                    type(self).__name__, "pk - it needs to be an int()")
            if pk < 0:
                raise InvalidArgumentException(
                    type(self).__name__, "pk - must be non-negative")

            # get the model instance for the withdraw_class we have
            withdraw_model = self.withdraw_class.objects.get(pk=pk)

            # call the super, with the user in the original transaction
            if user and user.username not in withdraw_model.cash_transaction_detail.user.username:
                raise AmbiguousArgumentException(
                    type(self).__name__,
                    "user is valid, but different from the user in the model for that pk!!!"
                )

            super().__init__(withdraw_model.cash_transaction_detail.user)

            self.withdraw_object = withdraw_model  # self.withdraw_class.objects.get(pk=pk)

        else:
            # call super with the user object passed to us
            super().__init__(user)
            self.withdraw_object = None

        self.validate_local_variables()
示例#11
0
    def create(self, category, amount, trans=None):
        """
        :param user: The user the transaction will be associated
            with.
        :param category: The category type. The category must be
            a TransactionType model.
        :param amount: the amount stored for the transaction.
        :param trans: the optional transaction to point the transaction to

        :raises :class:`transaction.exceptions.IncorrectVariableTypeException`:
            If the variables are not the correct types it will
            raise this exception.
        """
        #
        # makes sure the class has valid local variables.
        try:
            self.validate_local_variables()
        except Exception as e:
            raise e

        if (not isinstance(category, TransactionType)):
            raise IncorrectVariableTypeException(
                type(self).__name__, "category")
        if trans is None:
            self.transaction = Transaction(user=self.user, category=category)
            self.transaction.save()
        else:
            self.transaction = trans
        self.transaction_detail = self.transaction_detail_class()
        self.transaction_detail.amount = amount
        self.transaction_detail.transaction = self.transaction
        self.transaction_detail.user = self.user
        self.transaction_detail.save()
        transaction_type = self.transaction.category

        self.__update_balance(amount, transaction_type)
示例#12
0
 def validate_draft_group(self, draft_group):
     if isinstance(draft_group, draftgroup.models.DraftGroup):
         return draft_group
     # else raise exception that this is not the proper type
     raise IncorrectVariableTypeException(self.__class__.__name__,
                                          'draft_group')
示例#13
0
 def validate_prize_structure(self, prize_structure):
     if isinstance(prize_structure, prize.models.PrizeStructure):
         return prize_structure
     # else raise exception that this is not the proper type
     raise IncorrectVariableTypeException(self.__class__.__name__,
                                          'prize_structure')
示例#14
0
 def validate_start(self, start):
     if not isinstance(start, datetime):
         raise IncorrectVariableTypeException(self.__class__.__name__,
                                              'start')
     return start
示例#15
0
 def validate_duration(self, duration):
     if not isinstance(duration, int):
         raise IncorrectVariableTypeException(self.__class__.__name__,
                                              'duration')
     return duration
示例#16
0
    def consume(self, amount=None, ticket_obj=None, transaction_obj=None):
        """
        Uses one of the tickets and points the ticket to the transaction.
        This consume method can only take one of the following arguments:
            * amount
            * ticket
        :param amount: The dollar amount (decimal) that the user wishes to use
            for a ticket.
        :param ticket_obj: The :class:`ticket.models.Ticket` model object.
        :param transaction_obj: The :class:`transaction.models.Transaction`
            model object. If not set it will create one and then make
            the reference.
        :raise :class:`mysite.exceptions.IncorrectVariableTypeException`:
            if arguments are the wrong types
        :raise :class:`ticket.exceptions.InvalidTicketAmountException`:
            if the ticket amount is an amount not in the TicketAmount table.
        :raise :class:`ticket.exceptions.TicketAlreadyUsedException`:
            if the ticket object passed has already been consumed.
        :raise :class:`ticket.exceptions.UserDoesNotHaveTicketException`:
            if the user does not have a ticket with the amount provided.

        """
        # ---------------------------------------------------------------
        # ---------------------------------------------------------------
        # Validation of the arguments before we attempt to consume

        #
        # Make sure that amount and ticket_obj are not both set.
        if (amount != None and ticket_obj != None):
            raise TooManyArgumentsException(
                type(self).__name__, ['amount', 'ticket_obj'])

        #
        # Makes sure that amount or ticket is set.
        if (amount == None and ticket_obj == None):
            raise TooLittleArgumentsException(
                type(self).__name__, ['amount', 'ticket_obj'])

        #
        # Gets the tickets that are not consumed and throw and
        # exception if there are no tickets for the given user.
        if (amount != None):

            #
            # Gets the amount from the pre-defined Ticket Amounts
            try:
                amount_obj = self.get_ticket_amount(amount)
            except ticket.models.TicketAmount.DoesNotExist:
                raise InvalidTicketAmountException(type(self).__name__, amount)

            #
            # Checks the ticket
            tickets = ticket.models.Ticket.objects.filter(
                amount=amount_obj, user=self.user,
                consume_transaction=None).order_by('-created')

            if (len(tickets) == 0):
                raise UserDoesNotHaveTicketException(
                    type(self).__name__, amount, self.user)
            self.ticket = tickets[0]

        else:
            if (not isinstance(ticket_obj, ticket.models.Ticket)):
                raise IncorrectVariableTypeException(
                    type(self).__name__, "ticket_obj")
            self.ticket = ticket_obj

        #
        # Makes sure that the ticket has not been consumed, and throws
        # an exception if has been.
        if (self.ticket.consume_transaction != None):
            raise TicketAlreadyUsedException(
                type(self).__name__, amount, self.ticket.pk)

        #
        # Creates a new transaction if it was not supplied by the
        # consume functionality.
        if (transaction_obj == None):
            self.transaction = ticket.models.Transaction(
                user=self.user, category=self.__get_consume_category())
            self.transaction.save()
        else:
            #
            # check to make sure the transaction object is in fact
            # a transaction
            if (not isinstance(transaction_obj, Transaction)):
                raise IncorrectVariableTypeException(
                    type(self).__name__, "transaction_obj")
            self.transaction = transaction_obj
        #
        # Sets the ticket's consume_transaction field so that
        # it will be marked as used.
        self.ticket.consume_transaction = self.transaction
        self.ticket.save()

        msg = "User[" + self.user.username + "] used ticket #" + str(
            self.ticket.pk) + " valued at $" + str(
                self.ticket.amount.amount) + " on transaction #" + str(
                    self.transaction.pk)
        logger.info("action: Ticket Consume message: %s" % msg)