Esempio n. 1
0
    def post(self, request, oracle_id):
        """Updates quantity of card.

        Updates the number of cards owned by user based on POST data

        @param request:
        @param oracle_id: Card ID for current card

        :todo: None
        """
        if 'collection' in request.POST:
            oracle_id = request.POST['oracle_id']
            user_id = request.user.id

            card_quantity = int(request.POST['card_quantity'])
            card_notes = html.escape(request.POST['card_notes'])
            wish_quantity = int(request.POST['wish_quantity'])
            wish_notes = html.escape(request.POST['wish_notes'])

            if card_quantity != 0:
                card_id_info = CardIDList.get_card_by_oracle(oracle_id)
                user_card = UserCard.objects.get_user_card_oracle(
                    user_id, card_id_info.oracle_id, True, False)
                if len(user_card) > 0:
                    UserCard.objects.user_card_update(user_id,
                                                      card_id_info.oracle_id,
                                                      card_quantity, False,
                                                      card_notes)
                else:
                    UserCard.objects.user_card_create(user_id,
                                                      card_id_info.oracle_id,
                                                      card_id_info.card_name,
                                                      card_id_info.color_id,
                                                      card_quantity, False,
                                                      card_notes)
            if wish_quantity != 0:
                card_id_info = CardIDList.get_card_by_oracle(oracle_id)
                card_info = CardFace.objects.get_face_by_card(
                    card_id_info.card_id)[0]
                user_card = UserCard.objects.get_user_card_oracle(
                    user_id, card_id_info.oracle_id, True, True)
                if len(user_card) > 0:
                    UserCard.objects.user_card_update(user_id,
                                                      card_id_info.oracle_id,
                                                      wish_quantity, True,
                                                      wish_notes)
                else:
                    UserCard.objects.user_card_create(user_id,
                                                      card_id_info.oracle_id,
                                                      card_id_info.card_name,
                                                      card_info.mana_cost,
                                                      wish_quantity, True,
                                                      wish_notes)
        return redirect('../' + oracle_id)
Esempio n. 2
0
    def add_to_user(self, request, user_id, card_list, wish):
        formatted_list = ''

        card_list = list(card_list.split("\n"))
        if card_list[0] == '':
            card_list = []
        for card_item in card_list:
            card_item = card_item.replace('\r', '')
            try:
                if card_item != '':
                    card_values = card_item.split(" ", 1)
                    if card_values[0] != '':
                        card_quantity = int(card_values[0])
                        card_name = card_values[1]
                        card_id_info = CardIDList.get_card_by_name(card_name)
                        user_card = UserCard.objects.get_user_card_oracle(
                            user_id, card_id_info.oracle_id, True, wish)
                        if len(user_card) > 0:
                            user_json = json.loads(user_card)
                            UserCard.objects.user_card_update(
                                user_id, card_id_info.oracle_id,
                                card_quantity + int(user_json['quantity']),
                                wish, user_json['notes'])
                        else:
                            UserCard.objects.user_card_create(
                                user_id, card_id_info.oracle_id,
                                card_id_info.card_name, card_id_info.color_id,
                                card_quantity, wish, '')
                        #formatted_list = formatted_list + str(card_quantity) + " " + str(card_name) + '\n'
            except:
                messages.error(
                    request, "List in incorrect format. " + str(card_item) +
                    " not added to collection.")
                formatted_list = formatted_list + str(card_item) + '\n'
        return formatted_list
Esempio n. 3
0
    def __str__(self):
        card_id_obj = CardIDList.get_card_face_by_oracle(self.card_oracle)
        card = CardFace.objects.select_related().filter(
            Q(legal__card_obj__card_id=card_id_obj.card_id))[0]

        return '{' \
               '"deck_id": "' + str(self.deck) + \
               '", "oracle_id": "' + str(self.card_oracle) + \
               '", "quantity": "' + str(self.quantity) + \
               '", "sideboard": "' + str(self.sideboard) + \
               '", "commander": "' + str(self.commander) + \
               '", "card_name": "' + str(card.name) + \
               '", "card_image": "' + str(card.image_url) + \
               '", "color_id": "' + str(card.color_id) + \
               '"}'
Esempio n. 4
0
    def __str__(self):
        card_id_obj = CardIDList.get_card_face_by_oracle(self.card_oracle)
        card = CardFace.objects.select_related().filter(
            Q(legal__card_obj__card_id=card_id_obj.card_id))[0]

        return '{' \
               '"user_id": "' + str(self.user) + \
               '", "oracle_id": "' + str(self.card_oracle) + \
               '", "quantity": "' + str(self.quantity) + \
               '", "wish": "' + str(self.wish) + \
               '", "notes": "' + str(self.notes) + \
               '", "card_name": "' + str(self.card_name) + \
               '", "card_image": "' + str(card.image_url) + \
               '", "avatar_img": "' + str(card.avatar_img) + \
               '", "color_id": "' + str(self.color_id) + \
               '"}'
Esempio n. 5
0
    def add_to_deck(self, request, deck_id, card_list, side):
        formatted_list = ''
        color_list = []
        DeckCard.objects.empty_deck(deck_id, side, False)

        card_list = list(card_list.split("\n"))
        if card_list[0] == '':
            card_list = []
        for card_item in card_list:
            card_values = card_item.split(" ", 1)
            try:
                if card_values[0] != '':
                    card_quantity = int(card_values[0])
                    card_name = card_values[1].replace('\r', '')
                    card_info = CardIDList.get_card_by_name(card_name)
                    DeckCard.objects.deck_card_create(deck_id,
                                                      card_info.oracle_id,
                                                      card_quantity, side,
                                                      False)
                    formatted_list = formatted_list + str(
                        card_quantity) + " " + str(card_name) + '\n'

                    card_color = (Card.objects.get_card(
                        card_info.card_id)).color.split(',')
                    for color in card_color:
                        if color != '':
                            color_tag = '{' + color.strip() + '}'
                            if color_tag not in color_list:
                                color_list.append(color_tag)
            except:
                messages.error(
                    request, "List in incorrect format. " + card_values[1] +
                    " not added to deck.")

        color_list = str(color_list).replace(',', '').replace(' ', '').replace(
            '[', '').replace(']', '').replace('\'', '')

        Deck.objects.set_card_list(deck_id, side, formatted_list)
        Deck.objects.set_color_list(deck_id, color_list)
        return formatted_list
Esempio n. 6
0
    def get(self, request, oracle_id):
        """Display individual cards.

        Retrieves card information from the database based on what 'card_id' is in request. Then displays the card data.

        @param request:
        @param oracle_id: Oracle ID for current card

        :todo: Touch up data display/layout
        """
        logger.info("Run: card_display; Params: " +
                    json.dumps(request.GET.dict()))
        SessionManager.clear_other_session_data(request, SessionManager.Card)

        try:
            card_obj = CardIDList.get_card_by_oracle(oracle_id)
            card = Card.objects.get_card(card_obj.card_id)
            card_faces = CardFace.objects.get_face_by_card(card_obj.card_id)

            card_set_list = CardFace.objects.get_card_sets(oracle_id)
            card_set_list.sort(key=lambda item: item.get("set_name"))

            rulings_list = Rule.objects.filter(
                oracle_id=oracle_id).order_by('-pub_date')

            tcg_pricing = CardIDList.get_tcg_price(oracle_id)

            font_family = UserProfile.get_font(request.user)
            should_translate = UserProfile.get_translate(request.user)
            if request.user.is_authenticated:
                try:
                    has_card = True
                    user_card = UserCard.objects.get_user_card_oracle(
                        request.user.id, oracle_id, True, False)
                    if user_card == '':
                        has_card = False
                except ObjectDoesNotExist:
                    has_card = False
                    user_card = ''

                try:
                    has_wish = True
                    user_wish = UserCard.objects.get_user_card_oracle(
                        request.user.id, oracle_id, True, True)
                    if user_wish == '':
                        has_wish = False
                except ObjectDoesNotExist:
                    has_wish = False
                    user_wish = ''
            else:
                has_card = False
                user_card = ''
                has_wish = False
                user_wish = ''

            context = {
                'font_family': font_family,
                'should_translate': should_translate,
                'card': card,
                'faces': card_faces,
                'set_info': card_set_list,
                'rulings': rulings_list,
                'has_rules': len(rulings_list) > 0,
                'has_card': has_card,
                'user_card': user_card,
                'has_wish': has_wish,
                'user_wish': user_wish,
                'tcg_pricing': tcg_pricing,
                'auth': request.user.is_authenticated
            }

            return render(request, 'Collection/card_display.html', context)

        except CardIDList.DoesNotExist:
            message = "Oracle ID incorrect.\nPlease check ID."
            font_family = UserProfile.get_font(request.user)
            should_translate = UserProfile.get_translate(request.user)
            context = {
                'font_family': font_family,
                'should_translate': should_translate,
                'message': message
            }
            return render(request, 'error.html', context)
Esempio n. 7
0
    def post(self, request):
        logger.info("Run: collection_display; Params: " +
                    json.dumps(request.GET.dict()))
        init_mana_list = Symbol.get_base_symbols()
        card_id_list_full = CardIDList.get_cards()
        full_card_list_all = []
        for card_list_obj in card_id_list_full:
            full_card_list_all.append(card_list_obj.card_id)

        if 'collection_card_clear_search' in request.POST:
            request.session['collection_card_search_Term'] = ""
            request.session['collection_card_selected_mana'] = []
            request.session[
                'collection_card_card_list'] = CardFace.objects.get_card_face(
                    True)
            request.session['collection_card_clear'] = False
            request.session['collection_card_card_full'] = False
        elif 'collection_card_full_list' in request.POST:
            request.session['collection_card_search_Term'] = "Full List"
            request.session['collection_card_selected_mana'] = []
            request.session[
                'collection_card_card_list'] = CardFace.objects.get_card_face(
                    False)
            request.session['collection_card_clear'] = True
            request.session['collection_card_card_full'] = True
        else:
            text = request.POST.get('collection_card_search_Term')
            if text == "Full List":
                text = request.session['collection_card_search_Term'] = ""
            search_term = text
            selected_mana = []
            has_colorless = False
            has_color = False
            for selected in init_mana_list:
                mana_ele = request.POST.get("mana-" + str(selected.id))
                if mana_ele == '':
                    selected_mana.append(selected.symbol)
                    if selected.symbol == '{W}':
                        alt_mana = Symbol.get_white()
                    elif selected.symbol == '{U}':
                        alt_mana = Symbol.get_blue()
                    elif selected.symbol == '{B}':
                        alt_mana = Symbol.get_black()
                    elif selected.symbol == '{R}':
                        alt_mana = Symbol.get_red()
                    elif selected.symbol == '{G}':
                        alt_mana = Symbol.get_green()
                    elif selected.symbol == '{C}':
                        alt_mana = Symbol.get_colorless()
                    else:
                        alt_mana = []

                    for am in alt_mana:
                        if am.symbol not in selected_mana:
                            selected_mana.append(am.symbol)

            if len(selected_mana) > 0:
                colorless = [
                    '{C}', '', '{X}', '{Y}', '{Z}', '{0}', '{1/2}', '{1}',
                    '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}',
                    '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}',
                    '{17}', '{18}', '{19}', '{20}', '{100}', '{1000000}', '{P}'
                ]

                has_colorless = any(item in selected_mana
                                    for item in colorless)
                has_color = True

            filtered_card_list = CardFace.objects.card_filter_by_color_term(
                selected_mana, search_term, has_colorless, has_color)

            request.session['collection_card_search_Term'] = search_term
            request.session['collection_card_selected_mana'] = selected_mana
            request.session['collection_card_card_list'] = filtered_card_list
            request.session['collection_card_clear'] = True
            request.session['collection_card_card_full'] = False
        return redirect('card_database')