From 6721662e3d51d2ee738d633d4f54db48ad46d20e Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Mon, 17 Jul 2017 03:59:45 +0100 Subject: [PATCH] Redesigned the deck display --- web/templates/include/account_tab_deck.html | 3 +- web/templates/ownedcards.html | 50 ++++++++++++++++++--- web/templates/profile.html | 2 +- web/views.py | 38 ++++++++++------ 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/web/templates/include/account_tab_deck.html b/web/templates/include/account_tab_deck.html index af820f81..b08f7e2c 100644 --- a/web/templates/include/account_tab_deck.html +++ b/web/templates/include/account_tab_deck.html @@ -33,5 +33,6 @@ {% endif %} {% endif %} +
{% include 'ownedcards.html' with cards=account.deck %} -{% include 'include/_account_tab_ownedcardsload.html' %} +
diff --git a/web/templates/ownedcards.html b/web/templates/ownedcards.html index de17246b..1e0893a5 100644 --- a/web/templates/ownedcards.html +++ b/web/templates/ownedcards.html @@ -1,16 +1,51 @@ {% load imageurl %} {% load i18n %} {% load mod %} +{% spaceless %} {% with show_delete=True size=100 %} + {% if cards %} -{% for card in cards %}{% if card|is_int %}{{ card }}{% else %}{# size, classes, show_staff, show_delete, nolink, no_details #} + +{% if card.card.is_special and card.card.round_card_idolized_image %}{{ card.card }} +{% elif not card.idolized and card.card.round_card_image %}{{ card.card }} +{% elif card.idolized and card.prefer_unidolized_image and card.card.round_card_image %}{{ card.card }} +{% elif card.idolized and card.card.round_card_idolized_image %}{{ card.card }} +{% else %}
+{% endif %} +{% if show_delete and user.is_staff and show_staff %}
{% csrf_token %}{% if account and account.language == 'EN' and not card|is_int and not card.card.video_story and card.idolized %} {% endif %}{% if account and account.language == 'JP' and not card|is_int and not card.card.japanese_video_story and not card.card.video_story and card.idolized %}{% endif %}
+{% endif %} +{% endif %} +{% endfor %} + {% else %}
{% if is_me %} @@ -25,3 +60,4 @@
{% endif %} {% endwith %} +{% endspaceless %} \ No newline at end of file diff --git a/web/templates/profile.html b/web/templates/profile.html index 3ad8fb30..d60b2ff3 100644 --- a/web/templates/profile.html +++ b/web/templates/profile.html @@ -275,7 +275,7 @@

{% trans 'Reported as a fake account' %} {% if not preferences.private or is_me %} {% trans 'Significant Cards' %} - {{ account.deck_total_sr }} SR {% trans ',' %} {{ account.deck_total_ssr }} SSR {% trans 'and' %} {{ account.deck_total_ur }} UR + {{ account.deck_total_sr }} SR{% trans ',' %} {{ account.deck_total_ssr }} SSR{% trans ',' %} {% trans 'and' %} {{ account.deck_non_promo_ur }} UR (+ {{ account.deck_promo_ur }} {% trans 'Promo' %}) {% endif %} diff --git a/web/views.py b/web/views.py index a6a47c33..1a89c558 100644 --- a/web/views.py +++ b/web/views.py @@ -890,18 +890,30 @@ def profile(request, username): accounts_ids = ','.join([str(account.id) for account in context['user_accounts']]) if accounts_ids: cursor = connection.cursor() - query = 'SELECT c.rarity, o.owner_account_id, COUNT(c.rarity) FROM api_ownedcard AS o JOIN api_card AS c WHERE o.card_id=c.id AND o.owner_account_id IN (' + accounts_ids + ') AND o.stored=\'Deck\' GROUP BY c.rarity, o.owner_account_id' + query = 'SELECT c.rarity, o.owner_account_id, c.is_promo, COUNT(c.rarity) FROM api_ownedcard AS o JOIN api_card AS c WHERE o.card_id=c.id AND o.owner_account_id IN (' + accounts_ids + ') AND o.stored=\'Deck\' GROUP BY c.rarity, o.owner_account_id, c.is_promo' cursor.execute(query) deck_stats = cursor.fetchall() for account in context['user_accounts']: # Set stats - try: account.deck_total_sr = (s[2] for s in deck_stats if s[0] == 'SR' and s[1] == account.id).next() - except StopIteration: account.deck_total_sr = 0 - try: account.deck_total_ssr = (s[2] for s in deck_stats if s[0] == 'SSR' and s[1] == account.id).next() - except StopIteration: account.deck_total_ssr = 0 - try: account.deck_total_ur = (s[2] for s in deck_stats if s[0] == 'UR' and s[1] == account.id).next() - except StopIteration: account.deck_total_ur = 0 - account.deck_total = sum([s[2] for s in deck_stats if s[1] == account.id]) + account.deck_non_promo_r = countCards(deck_stats, account, 'R', False) + account.deck_promo_r = countCards(deck_stats, account, 'R', True) + account.deck_total_r = account.deck_non_promo_r + account.deck_promo_r + + account.deck_non_promo_sr = countCards(deck_stats, account, 'SR', False) + account.deck_promo_sr = countCards(deck_stats, account, 'SR', True) + account.deck_total_sr = account.deck_non_promo_sr + account.deck_promo_sr + + account.deck_non_promo_ssr = countCards(deck_stats, account, 'SSR', False) + account.deck_promo_ssr = countCards(deck_stats, account, 'SSR', True) + account.deck_total_ssr = account.deck_non_promo_ssr + account.deck_promo_ssr + + account.deck_non_promo_ur = countCards(deck_stats, account, 'UR', False) + account.deck_promo_ur = countCards(deck_stats, account, 'UR', True) + account.deck_total_ur = account.deck_non_promo_ur + account.deck_promo_ur + + account.deck_total = sum([s[3] for s in deck_stats if s[1] == account.id]) + account.deck_total_n = account.deck_total - account.deck_total_r - account.deck_total_sr - account.deck_total_ssr - account.deck_total_ur + # Get opened tab if 'show' + str(account.id) in request.GET and request.GET['show' + str(account.id)] in models.ACCOUNT_TAB_DICT: account.opened_tab = request.GET['show' + str(account.id)] @@ -991,6 +1003,11 @@ def profile(request, username): context['deck_links'] = web_raw.deck_links return render(request, 'profile.html', context) +def countCards(deck_stats, account, rarity, promo): + try: ret = (s[3] for s in deck_stats if s[0] == rarity and s[1] == account.id and s[2] == promo).next() + except StopIteration: ret = 0 + return ret + def _ajaxaccounttab_ownedcards(tab, request, account, more): """ SQL Queries @@ -1028,10 +1045,6 @@ def _ajaxaccounttab_ownedcards(tab, request, account, more): account.album = album[:settings.CARDS_LIMIT] elif tab == 'deck': account.deck = ownedcards.filter(stored='Deck').order_by('-card__rarity', '-idolized', '-card__attribute', '-card__id') - if more: - account.deck = account.deck[settings.CARDS_LIMIT:] - else: - account.deck = account.deck[:settings.CARDS_LIMIT] elif tab == 'wishlist': account.wishlist = ownedcards.filter(stored='Favorite').order_by('-card__rarity', '-idolized', 'card__id') account.total_cards = account.wishlist.count() @@ -3337,4 +3350,3 @@ def drown(request): def cardstrength(request): context = globalContext(request) - return render(request, 'cardstrength.html', context)