def get(self, request): """Displays list for selecting new avatar Displays full list of card art with search by name feature. @param request: :todo: None """ SessionManager.clear_other_session_data(request, SessionManager.EditCard) deck_id = request.GET.get('deck_id', -1) side = False title = " deck " if request.GET.get('side', 'False') == 'True': side = True title = " sideboard " modify_deck_list_cards = Deck.objects.get_card_list(deck_id, side) font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, str(self.list): modify_deck_list_cards, 'deck_id': deck_id, 'side': side, 'title': title } return render(request, 'Users/Profile/ProfileDecks/edit_cards.html', context)
def get(self, request): """Displays list for selecting new avatar Displays full list of card art with search by name feature. @param request: :todo: None """ SessionManager.clear_other_session_data(request, SessionManager.DeckImage) deck_id = request.GET.get('deck_id', -1) try: user_search_deck_image_term = request.session[self.term] deck_image_list = request.session[self.cards] clear_deck_image = request.session[self.clear] except KeyError: user_search_deck_image_term = request.session[self.term] = "" deck_image_list = request.session[ self.cards] = CardFace.objects.card_face_commander_filter( user_search_deck_image_term) clear_deck_image = request.session[self.clear] = False deck_image_list_split = list(deck_image_list.split("},")) if deck_image_list_split[0] == '': deck_image_list_split = [] page = request.GET.get('page', 1) paginator = Paginator(deck_image_list_split, 20) try: cards = paginator.page(page) except PageNotAnInteger: cards = paginator.page(1) except EmptyPage: cards = paginator.page(paginator.num_pages) font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'pages': cards, 'deck_id': deck_id, str(self.term): user_search_deck_image_term, str(self.clear): clear_deck_image } return render(request, 'Users/Profile/ProfileDecks/select_deck_image.html', context)
def get(self, request): """Displays list for selecting new avatar Displays full list of card art with search by name feature. @param request: :todo: None """ SessionManager.clear_other_session_data(request, SessionManager.Avatar) user_id = request.GET.get('user_id', -1) try: avatar_search_term = request.session[str(self.term)] avatar_card_list = request.session[str(self.cards)] avatar_clear_search = request.session[str(self.clear)] except KeyError: avatar_search_term = request.session[str(self.term)] = "" avatar_card_list = request.session[str( self.cards)] = CardFace.objects.card_face_avatar_filter('') avatar_clear_search = request.session[str(self.clear)] = False avatar_card_list_split = list(avatar_card_list.split("},")) if avatar_card_list_split[0] == '': avatar_card_list_split = [] page = request.GET.get('page', 1) paginator = Paginator(avatar_card_list_split, 50) try: cards = paginator.page(page) except PageNotAnInteger: cards = paginator.page(1) except EmptyPage: cards = paginator.page(paginator.num_pages) font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'pages': cards, str(self.term): avatar_search_term, str(self.clear): avatar_clear_search, 'user_id': user_id } return render(request, 'Users/Profile/select_avatar.html', context)
def index(request): """Display landing page for life counter. This page is not currently used by the application. :param request: Does not utilize any portions of this param. :returns: "Hello World From LifeCounter" :todo: None """ game_code = "" if request.method == "POST": game_code = request.POST.get("game_code") if 'join_game' in request.POST: game = Game.get_by_code(game_code) if game == None: messages.error(request, 'Game code invalid.') else: Game.set_game_player_stats(request.user.id, {}) return redirect( 'game/' + game_code ) else: # todo finish create game_type = request.POST.get("game_type") game = Game.create_new(request.user, game_type) return redirect( 'game/' + Game.game_code ) game_types = GameType.objects.all() font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = {'font_family': font_family, 'should_translate': should_translate, 'game_code': game_code, 'game_types': game_types} return render(request, "LifeCounter/game_selector.html", context)
def get(self, request): """Displays list for selecting new avatar Displays full list of card art with search by name feature. @param request: :todo: None """ SessionManager.clear_other_session_data(request, SessionManager.BulkCard) user_id = request.GET.get('user_id', -1) wish = False title = " collection " if request.GET.get('wish', 'False') == 'True': wish = True title = " wish List " try: user_card_list = request.session[str(self.list)] except KeyError: user_card_list = '' font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, str(self.list): user_card_list, 'user_id': user_id, 'wish': wish, 'title': title } return render(request, 'Users/Profile/ProfileCards/bulk_add_card.html', context)
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)
def get(self, request): """Display entire card database. Retrieves all cards from database in alphabetical order and displays them based on what 'page' is in request. @param request: :todo: Loading image for long searches """ logger.info("Run: collection_display; Params: " + json.dumps(request.GET.dict())) SessionManager.clear_other_session_data(request, SessionManager.Card) init_mana_list = Symbol.get_base_symbols() try: search_term = request.session['collection_card_search_Term'] selected_mana = request.session['collection_card_selected_mana'] card_list = request.session['collection_card_card_list'] clear_search = request.session['collection_card_clear'] full_list = request.session['collection_card_card_full'] except KeyError: search_term = request.session['collection_card_search_Term'] = "" selected_mana = request.session[ 'collection_card_selected_mana'] = [] card_list = request.session[ 'collection_card_card_list'] = CardFace.objects.get_card_face( True) clear_search = request.session['collection_card_clear'] = False full_list = request.session['collection_card_card_full'] = False mana_list = [] for init_mana in init_mana_list: if init_mana.symbol in selected_mana: mana_list.append({ 'symbol': init_mana.symbol, 'checked': True, 'image_url': init_mana.image_url, 'id': init_mana.id }) else: mana_list.append({ 'symbol': init_mana.symbol, 'checked': False, 'image_url': init_mana.image_url, 'id': init_mana.id }) card_list_split = list(card_list.split("},")) if card_list_split[0] == '': card_list_split = [] page = request.GET.get('page', 1) paginator = Paginator(card_list_split, 20) try: cards = paginator.page(page) except PageNotAnInteger: cards = paginator.page(1) except EmptyPage: cards = paginator.page(paginator.num_pages) try: font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'pages': cards, 'search_Term': search_term, 'mana_list': mana_list, 'clearSearch': clear_search, 'full_list': full_list } return render(request, 'Collection/collection_display.html', context) except JSONDecodeError: 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 message = "Invalid search. Please try again." 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)
def get(self, request): """Displays new deck page Redirects to new deck page @param request: :todo: Finish new deck page """ SessionManager.clear_other_session_data(request, SessionManager.Profile) user_id = int(request.GET.get('user_id', request.user.id)) deck_id = int(request.GET.get('deck_id', -1)) try: deck_obj = Deck.objects.get_deck(request.user.username, deck_id) deck_type_obj = Deck.objects.get_deck_type(deck_id) deck_private = deck_obj.is_private if deck_obj.deck_user != request.user.username: deck_obj = deck_obj.create_copy(request.user) messages.success(request, "Deck copied to your profile.") return HttpResponseRedirect( reverse('modify_deck') + '?user_id=' + str(user_id) + '&deck_id=' + str(deck_obj.id)) except ObjectDoesNotExist: deck_obj = "new" deck_type_obj = '{"type_id": "1"}' deck_private = UserProfile.get_deck_private(request.user) deck_types = DeckType.objects.get_types() deck_type_split = list(deck_types.split("},")) deck_commander = DeckCard.objects.deck_card_by_deck_side( deck_id, False, True) deck_cards = DeckCard.objects.deck_card_by_deck_side( deck_id, False, False) side_cards = DeckCard.objects.deck_card_by_deck_side( deck_id, True, False) commanders = list(deck_commander.split("},")) if commanders[0] == '': commanders = [] deck_cards_list = list(deck_cards.split("},")) if deck_cards_list[0] == '': deck_cards_list = [] side_cards_list = list(side_cards.split("},")) if side_cards_list[0] == '': side_cards_list = [] font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'deck_obj': deck_obj, 'deck_types': deck_type_split, 'deck_id': deck_id, 'is_private': deck_private, 'deck_type_obj': deck_type_obj, 'commander': commanders, 'commander_len': len(deck_commander), 'deck_cards': deck_cards_list, 'side_cards': side_cards_list, 'user_id': user_id } return render(request, 'Users/Profile/ProfileDecks/modify_deck.html', context)
def get(self, request): """Display the profile of a user. Uses the GET data from request to display user data. @param request: @param user_id: User id of displayed profile. :todo: None """ logger.info("Run: user_profile; Params: " + json.dumps(request.GET.dict())) SessionManager.clear_other_session_data(request, SessionManager.Profile) user_id = request.GET.get('user_id', -1) user_profile_obj = UserProfile.get_profile_by_user(user_id) try: session_user = request.session['user_view'] if session_user != user_id: SessionManager.clear_other_session_data( request, SessionManager.All) request.session['user_view'] = user_id except KeyError: SessionManager.clear_other_session_data(request, SessionManager.All) request.session['user_view'] = user_id user_profile = UserProfile.get_profile_by_user(user_id) # region Page numbers try: deck_page = request.GET.get('deckPage', -1) if deck_page == -1: deck_page = request.session['deck_page'] except KeyError: deck_page = request.GET.get('deckPage', 1) request.session['deck_page'] = deck_page try: card_page = request.GET.get('cardPage', -1) if card_page == -1: card_page = request.session['card_page'] except KeyError: card_page = request.GET.get('cardPage', 1) request.session['card_page'] = card_page try: wish_page = request.GET.get('wishPage', -1) if wish_page == -1: wish_page = request.session['wish_page'] except KeyError: wish_page = request.GET.get('wishPage', 1) request.session['wish_page'] = wish_page # endregion show_private = int(user_id) == request.user.id # region Cards from session try: user_search_deck_term = request.session['user_search_deck_term'] user_search_deck_cards = request.session['user_search_deck_cards'] user_clear_deck_search = request.session['user_clear_deck_search'] except KeyError: user_search_deck_term = request.session[ 'user_search_deck_term'] = "" user_search_deck_cards = request.session[ 'user_search_deck_cards'] = Deck.objects.get_deck_by_user_term( user_profile.user.username, show_private, "") user_clear_deck_search = request.session[ 'user_clear_deck_search'] = False try: user_search_card_term = request.session['user_search_card_term'] user_search_card_cards = request.session['user_search_card_cards'] user_clear_card_search = request.session['user_clear_card_search'] except KeyError: user_search_card_term = request.session[ 'user_search_card_term'] = "" user_search_card_cards = request.session[ 'user_search_card_cards'] = UserCard.objects.get_user_card( user_id, False, [], False, False, "") user_clear_card_search = request.session[ 'user_clear_card_search'] = False try: user_search_wish_term = request.session['user_search_wish_term'] user_search_wish_cards = request.session['user_search_wish_cards'] user_clear_wish_search = request.session['user_clear_wish_search'] except KeyError: user_search_wish_term = request.session[ 'user_search_wish_term'] = "" user_search_wish_cards = request.session[ 'user_search_wish_cards'] = UserCard.objects.get_user_card( user_id, True, [], False, False, "") user_clear_wish_search = request.session[ 'user_clear_wish_search'] = False # endregion # region Paginators user_deck_list_split = list(user_search_deck_cards.split("},")) if user_deck_list_split[0] == '': user_deck_list_split = [] deck_show = len(user_deck_list_split) > 0 or user_clear_deck_search deck_paginator = Paginator(user_deck_list_split, 5) try: deck_list = deck_paginator.page(deck_page) except PageNotAnInteger: deck_list = deck_paginator.page(1) except EmptyPage: deck_list = deck_paginator.page(deck_paginator.num_pages) user_card_list_split = list(user_search_card_cards.split("},")) if user_card_list_split[0] == '': user_card_list_split = [] card_show = len(user_card_list_split) > 0 or user_clear_card_search card_paginator = Paginator(user_card_list_split, 5) try: card_list = card_paginator.page(card_page) except PageNotAnInteger: card_list = card_paginator.page(1) except EmptyPage: card_list = card_paginator.page(card_paginator.num_pages) user_wish_card_list_split = list(user_search_wish_cards.split("},")) if user_wish_card_list_split[0] == '': user_wish_card_list_split = [] wish_show = user_wish_card_list_split.__len__( ) > 0 or user_clear_wish_search wish_paginator = Paginator(user_wish_card_list_split, 5) try: wish_list = wish_paginator.page(wish_page) except PageNotAnInteger: wish_list = wish_paginator.page(1) except EmptyPage: wish_list = wish_paginator.page(wish_paginator.num_pages) o_player = not str(request.user.id) == user_id # endregion friend_obj = user_profile_obj.get_user_friends() pending_obj = user_profile_obj.get_user_pending() follower_obj = user_profile_obj.get_user_followers() font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'user_profile_obj': user_profile_obj, 'has_friend': len(friend_obj) > 0, 'friend_obj': friend_obj, 'has_pending': len(pending_obj) > 0, 'pending_obj': pending_obj, 'has_follower': len(follower_obj) > 0, 'follower_obj': follower_obj, 'o_player': o_player, 'user_id': user_id, 'deckPage': deck_page, 'deck_list': deck_list, 'user_search_deck_term': user_search_deck_term, 'clear_deck_search': user_clear_deck_search, 'deckShow': deck_show, 'cardPage': card_page, 'card_list': card_list, 'user_search_card_term': user_search_card_term, 'clear_card_search': user_clear_card_search, 'cardShow': card_show, 'wish_page': wish_page, 'wish_list': wish_list, 'user_search_wish_term': user_search_wish_term, 'clear_wish_search': user_clear_wish_search, 'wishShow': wish_show, } return render(request, 'Users/user_profile.html', context)
def get(self, request): SessionManager.clear_other_session_data(request, SessionManager.UserCard) user_id = request.GET.get('user_id', -1) wish = False if request.GET.get('wish', 'False') == 'True': wish = True init_mana_list = Symbol.get_base_symbols() try: search_term = request.session[str(self.term)] selected_mana = request.session[str(self.mana)] card_list = request.session[str(self.cards)] clear_search = request.session[str(self.clear)] except KeyError: search_term = request.session[str(self.term)] = "" selected_mana = request.session[str(self.mana)] = [] card_list = request.session[str( self.cards)] = UserCard.objects.get_user_card( user_id, wish, [], False, False, "") clear_search = request.session[str(self.clear)] = False mana_list = [] for init_mana in init_mana_list: if init_mana.symbol in selected_mana: mana_list.append({ 'symbol': init_mana.symbol, 'checked': True, 'image_url': init_mana.image_url, 'id': init_mana.id }) else: mana_list.append({ 'symbol': init_mana.symbol, 'checked': False, 'image_url': init_mana.image_url, 'id': init_mana.id }) card_list_split = list(card_list.split("},")) if card_list_split[0] == '': card_list_split = [] page = request.GET.get('page', 1) paginator = Paginator(card_list_split, 20) try: cards = paginator.page(page) except PageNotAnInteger: cards = paginator.page(1) except EmptyPage: cards = paginator.page(paginator.num_pages) font_family = UserProfile.get_font(request.user) should_translate = UserProfile.get_translate(request.user) context = { 'font_family': font_family, 'should_translate': should_translate, 'pages': cards, 'search_Term': search_term, 'mana_list': mana_list, 'user_card_list_clear': clear_search, 'user_id': str(user_id), 'wish': str(wish) } return render(request, 'Users/Profile/ProfileCards/user_card_list.html', context)