def add(request, model, model_id):
	model = model.lower()
	obj = loadObject(model, int(model_id))
	error_message = False
	if request.POST:
		name = request.POST['name']
		type = request.POST['type']
		if name and type:
			card = Card(
				user = request.user,
				model = model,
				model_id = model_id,
				name = name,
				created = timezone.now(),
				type = type,
				content = generateContent(type)
			)
			card.save()
			return redirect('/' + model + '/' + model_id)
		else:
			error_message = 'Some fields are required.'
	context = {
		'obj'			: obj,
		'model'			: model,
		'model_id'		: model_id,
		'types'			: supportedTypes(),
		'user'			: views.user_status(request),
		'shopping_cart'	: views.shopping_cart_status(request)
	}
	return render(request, 'card/add.html', context)
Beispiel #2
0
def new_hand(request):
    game = Game.objects.get(player_name=request.user.username)

    if game.bot_stack == 0 or game.player_stack == 0:
        return redirect('/board')

    game.street = 0
    game.hand_number += 1
    newDeck = Deck()
    newDeck.save()

    #shuffle the deck and put it into the db
    cardTuples = [(i, j) for i in range(2, 15) for j in range(1, 5)]
    random.shuffle(cardTuples)

    for (i, j) in cardTuples:
        newCard = Card(value=i, suit=j)
        newCard.save()
        newDeck.cards.add(newCard)

    x1, x2 = newDeck.deal(), newDeck.deal()
    y1, y2 = newDeck.deal(), newDeck.deal()

    #deal players new cards
    playerHand = Hand()
    playerHand.save()
    playerHand.cards.add(x1)
    playerHand.cards.add(x2)

    botHand = Hand()
    botHand.save()
    botHand.cards.add(y1)
    botHand.cards.add(y2)

    board = Board(player=request.user)
    board.save()

    #deal 5 cards for the board
    boardCards = [newDeck.deal() for i in range(5)]

    for bc in boardCards:
        board.cards.add(bc)

    game.player_hand = playerHand
    game.bot_hand = botHand
    game.pot = 0
    game.board = board
    game.player_bet = min(game.blinds, game.player_stack)
    game.bot_bet = min(game.blinds, game.bot_stack)
    game.player_stack -= game.player_bet
    game.bot_stack -= game.bot_bet

    game.pot = game.player_bet + game.bot_bet

    game.save()

    return redirect('/board')
Beispiel #3
0
def new_game(request):

    username = request.POST['username']
    password = request.POST['password']
    email = request.POST['email']
    stack = int(request.POST['stack_amount'])
    blinds = int(stack // 75)

    user = User.objects.create_user(username=username,
                                    email=email,
                                    password=password)
    login(request, user)

    newDeck = Deck()
    newDeck.save()

    #new deck
    cardTuples = [(i, j) for i in range(2, 15) for j in range(1, 5)]
    random.shuffle(cardTuples)

    for (i, j) in cardTuples:
        newCard = Card(value=i, suit=j)
        newCard.save()
        newDeck.cards.add(newCard)

    x1, x2 = newDeck.deal(), newDeck.deal()
    y1, y2 = newDeck.deal(), newDeck.deal()

    #deal players new hand
    playerHand = Hand()
    playerHand.save()
    playerHand.cards.add(x1)
    playerHand.cards.add(x2)

    botHand = Hand()
    botHand.save()
    botHand.cards.add(y1)
    botHand.cards.add(y2)

    board = Board(player=request.user)
    board.save()

    boardCards = [newDeck.deal() for i in range(5)]

    for bc in boardCards:
        board.cards.add(bc)

    newGame = Game(player_name=request.user.username, player=request.user,\
        player_stack=stack, bot_stack=stack, player_hand=playerHand, \
            bot_hand=botHand, board=board, street=0, blinds=blinds)

    newGame.save()

    #start a new hand
    return redirect('/newhand')
Beispiel #4
0
    def create(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = User.objects.get(id=serializer.data['user'])
        if user != request.user:
            if not request.user.has_perm('%s.add_%s' % (Card._meta.app_label, Card._meta.model_name)):
                self.permission_denied(request)

        card = Card(user=user, card_number=serializer.data['card_number'])
        card.save()
        return Response(CardSerializer(card).data, status=status.HTTP_201_CREATED)
Beispiel #5
0
 def mutate(root, info, input=None):
     ok = True
     print(input.author)
     print(User.objects.get(pk=input.author))
     card_instance = Card(name=input.name,
                          description=input.description,
                          importance=input.importance,
                          limit=datetime.datetime.strptime(
                              input.limit, "%Y-%m-%d %H:%M"),
                          author=User.objects.get(pk=input.author))
     card_instance.save()
     return CreateCard(ok=ok, card=card_instance)
Beispiel #6
0
    def post(self, request, *args, **kwargs):
        response = request.data.get('response',None)
        userID = request.data.get('userID', None)

        reference = response["reference"]
        status = response["status"]

        if reference is not None and status == "success":
            verify_response = Transaction.verify(reference=f"{reference}")
            
            user = User.objects.get(pk=userID)
            reference = verify_response["data"]["reference"]
            auth_code = verify_response["data"]["authorization"]["authorization_code"]
            card_bin = verify_response["data"]["authorization"]["bin"]
            last_4 = verify_response["data"]["authorization"]["last4"]
            expiry_month = verify_response["data"]["authorization"]["exp_month"]
            expiry_year = verify_response["data"]["authorization"]["exp_year"]
            card_type = verify_response["data"]["authorization"]["card_type"]
            bank = verify_response["data"]["authorization"]["bank"]
            first_name = verify_response["data"]["customer"]["first_name"]
            last_name = verify_response["data"]["customer"]["last_name"]
            email = verify_response["data"]["customer"]["email"]
            
            card = Card(
                user = user, 
                reference = reference, 
                auth_code = auth_code, 
                card_bin = card_bin, 
                last_4 = last_4,
                expiry_month = expiry_month,
                expiry_year = expiry_year,
                card_type = card_type,
                bank = bank,
                first_name = first_name,
                last_name = last_name,
                email = email
            )

            card_qs = Card.objects.filter(user = user)
            
            if card_qs.exists():
                return Response({"message": "You already have a registered card"}, status=HTTP_400_BAD_REQUEST)
            else:
                card.save()
                return Response(status=HTTP_201_CREATED)

        return Response(status=HTTP_200_OK)
Beispiel #7
0
def create_deck():
    """
    Create a list of playing cards in our database
    :return:
    """
    suits = ["SPADE", "CLUB", "DIAMOND", "HEART"]
    ranks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
    cards = [Card(suit=suit, rank=rank) for rank in ranks for suit in suits]
    Card.objects.bulk_create(cards)
Beispiel #8
0
    def handle(self, *args, **options):
        self.clean_cards()
        cards = self.get_cards()
        card_type = self.get_card_type("Minion")

        for card_content in cards:
            card_keys = list(card_content.keys())
            if self.verify_card(card_keys) and not self.card_exists(
                    card_content['cardId']):
                card = Card(card_id=card_content['cardId'],
                            dbf_id=card_content['dbfId'],
                            name=card_content['name'],
                            card_set=self.get_card_set(
                                card_content['cardSet']),
                            type=card_type,
                            text=card_content['text'],
                            health=card_content['health'],
                            attack=card_content['attack'])

                if "img" in card_keys:
                    card.img = card_content['img']

                if "imgGold" in card_keys:
                    card.img_gold = card_content['imgGold']

                card.save()