Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesigned the deck display #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/templates/include/account_tab_deck.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
</div>
{% endif %}
{% endif %}
<div style="max-height:calc(100vh - 92px);overflow-y:auto">
{% include 'ownedcards.html' with cards=account.deck %}
{% include 'include/_account_tab_ownedcardsload.html' %}
</div>
50 changes: 43 additions & 7 deletions web/templates/ownedcards.html
Original file line number Diff line number Diff line change
@@ -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 %}<a href="/cards/{{ card }}/" target="_blank" class="album-empty">{{ card }}</a>{% else %}{# size, classes, show_staff, show_delete, nolink, no_details #}<a href="{{ card.card|singlecardurl }}" class="owned_card{% if show_staff %} staff{% endif %}"><div class="owned_card_details" style="display: none"><div class="fontx2 color-{{ card.card.attribute }}">{% if card.stored == 'Deck' %}
<i class="flaticon-deck"></i>{% elif card.stored == 'Album' %}<i class="flaticon-album"></i>{% elif card.stored == 'Box' %}<i class="flaticon-present"></i>{% elif card.stored == 'Favorite' %}<i class="flaticon-star"></i>{% endif %}
{% if card.idolized %}<i class="flaticon-idolized"></i>{% endif %}
{% for card in cards %}

{% if card|is_int %}
<a href="/cards/{{ card }}/" target="_blank" class="album-empty">{{ card }}</a>
{% else %}

{% if card.stored == 'Deck' %}
{% if card.card.rarity == 'UR' and forloop.counter == 1 %}
<div style="text-align:left"><span style="font-size:30px"><b>{{account.deck_non_promo_ur}}</b> UR</span> {% if account.deck_promo_ur %} (+ <b>{{account.deck_promo_ur}}</b> {% trans 'Promo' %}){% endif %}</div><hr>
{% elif card.card.rarity == 'SSR' and forloop.counter == account.deck_total_ur|add:1 %}
<div style="text-align:left"><span style="font-size:30px"><b>{{account.deck_non_promo_ssr}}</b> SSR</span> {% if account.deck_promo_ssr %} (+ <b>{{account.deck_promo_ssr}}</b> {% trans 'Promo' %}){% endif %}</div><hr>
{% elif card.card.rarity == 'SR' and forloop.counter == account.deck_total_ur|add:account.deck_total_ssr|add:1 %}
<div style="text-align:left"><span style="font-size:30px"><b>{{account.deck_non_promo_sr}}</b> SR</span> {% if account.deck_promo_sr %} (+ <b>{{account.deck_promo_sr}}</b> {% trans 'Promo' %}){% endif %}</div><hr>
{% elif forloop.counter == account.deck_total_ur|add:account.deck_total_ssr|add:account.deck_total_sr|add:1 %}
<div style="text-align:left"><span style="font-size:30px"><b>{{account.deck_non_promo_r}}</b> R</span> {% if account.deck_promo_r %} (+ <b>{{account.deck_promo_r}}</b> {% trans 'Promo' %}){% endif %}</div><hr>
{% elif forloop.counter == account.deck_total_ur|add:account.deck_total_ssr|add:account.deck_total_sr|add:account.deck_total_r|add:1 %}
<div style="text-align:left;font-size:30px"><b>{{account.deck_total_n}}</b> N</div><hr>
{% endif %}
{% endif %}

{# size, classes, show_staff, show_delete, nolink, no_details #}<a href="{{ card.card|singlecardurl }}" class="owned_card{% if show_staff %} staff{% endif %}"><div class="owned_card_details" style="display: none"><div class="fontx2 color-{{ card.card.attribute }}">
<i class="{% if card.stored == 'Deck' %}flaticon-deck{% elif card.stored == 'Album' %}flaticon-album{% elif card.stored == 'Box' %}flaticon-present{% elif card.stored == 'Favorite' %}flaticon-star{% endif %}" style="padding:0px 3px 0px 3px"></i>
{% if card.idolized %}<i class="flaticon-idolized" style="padding:0px 3px 0px 3px"></i>{% endif %}
{% if card.stored == 'Deck' %}
{% if card.max_level %}<i class="flaticon-max-level"></i>{% endif %}
{% if card.max_bond %}<i class="flaticon-max-bond"></i>{% endif %}
{% if card.skill > 1 %}<span><i class="flaticon-skill"></i><small><span class="tiny">{{ card.skill }}</span></small></span>{% endif %}
{% if card.skill_slots != card.card.min_skill_slot %}<span><i class="flaticon-combo"></i><small><span class="tiny">{{ card.skill_slots }}</span></small></span>{% endif %}{% endif %}</div></div>{% if card.card.is_special and card.card.round_card_idolized_image %}<img src="{% imageurl card=card.card image='round_card_idolized_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">{% elif not card.idolized and card.card.round_card_image %}<img src="{% imageurl card=card.card image='round_card_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">{% elif card.idolized and card.prefer_unidolized_image and card.card.round_card_image %}<img src="{% imageurl card=card.card image='round_card_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">{% elif card.idolized and card.card.round_card_idolized_image %}<img class="{{ classes }}" src="{% imageurl card=card.card image='round_card_idolized_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">{% else %}<div class="circled_card_{{ size }} {{ card.card.attribute }} {{ card.card.rarity }} hover" style="background-image: url('{% if not card.idolized and card.card.card_image %}{% imageurl card=card.card image='card_image' %}{% else %}{% imageurl card=card.card image='card_idolized_image' %}{% endif %}');"></div>{% endif %}{% if show_delete and user.is_staff and show_staff %}<form method="post" action="/ajax/deletecard/{{ card.pk }}/" role="form" class="delete">{% csrf_token %}<button type="submit" class="btn btn-danger">X</button>{% if account and account.language == 'EN' and not card|is_int and not card.card.video_story and card.idolized %} <i class="flaticon-pause fontx1-5"></i>{% 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 %}<i class="flaticon-JP fontx1-5"></i>{% endif %}</form>{% endif %}</a>{% endif %}{% endfor %}
{% if card.max_level %}<i class="flaticon-max-level" style="padding:0px 3px 0px 3px"></i>{% endif %}
{% if card.max_bond %}<i class="flaticon-max-bond" style="padding:0px 3px 0px 3px"></i>{% endif %}
{% if card.skill > 1 %}<span><i class="flaticon-skill" style="padding:0px 3px 0px 3px"></i><small><span class="tiny">{{ card.skill }}</span></small></span>{% endif %}
{% if card.skill_slots != card.card.min_skill_slot %}<span><i class="flaticon-combo" style="padding:0px 3px 0px 3px"></i><small><span class="tiny">{{ card.skill_slots }}</span></small></span>{% endif %}{% endif %}
</div></div>

{% if card.card.is_special and card.card.round_card_idolized_image %}<img src="{% imageurl card=card.card image='round_card_idolized_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">
{% elif not card.idolized and card.card.round_card_image %}<img src="{% imageurl card=card.card image='round_card_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">
{% elif card.idolized and card.prefer_unidolized_image and card.card.round_card_image %}<img src="{% imageurl card=card.card image='round_card_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">
{% elif card.idolized and card.card.round_card_idolized_image %}<img class="{{ classes }}" src="{% imageurl card=card.card image='round_card_idolized_image' %}" alt="{{ card.card }}" height="{{ size }}" style="display: inline-block">
{% else %}<div class="circled_card_{{ size }} {{ card.card.attribute }} {{ card.card.rarity }} hover" style="background-image: url('{% if not card.idolized and card.card.card_image %}{% imageurl card=card.card image='card_image' %}{% else %}{% imageurl card=card.card image='card_idolized_image' %}{% endif %}');"></div>
{% endif %}
{% if show_delete and user.is_staff and show_staff %}<form method="post" action="/ajax/deletecard/{{ card.pk }}/" role="form" class="delete">{% csrf_token %}<button type="submit" class="btn btn-danger">X</button>{% if account and account.language == 'EN' and not card|is_int and not card.card.video_story and card.idolized %} <i class="flaticon-pause fontx1-5"></i>{% 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 %}<i class="flaticon-JP fontx1-5"></i>{% endif %}</form>
{% endif %}</a>
{% endif %}
{% endfor %}

{% else %}
<div class="alert alert-warning">
{% if is_me %}
Expand All @@ -25,3 +60,4 @@
</div>
{% endif %}
{% endwith %}
{% endspaceless %}
2 changes: 1 addition & 1 deletion web/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ <h3 class="text-danger">{% trans 'Reported as a fake account' %}
{% if not preferences.private or is_me %}
<tr>
<th>{% trans 'Significant Cards' %}</th>
<td><strong>{{ account.deck_total_sr }} SR</strong> {% trans ',' %} <strong>{{ account.deck_total_ssr }} SSR</strong> {% trans 'and' %} <strong>{{ account.deck_total_ur }} UR</strong><span class="hidden deck_total_value">{{ account.deck_total }}</span></td>
<td><strong>{{ account.deck_total_sr }} SR</strong>{% trans ',' %} <strong>{{ account.deck_total_ssr }} SSR</strong>{% trans ',' %} {% trans 'and' %} <strong>{{ account.deck_non_promo_ur }} UR</strong> (+ <strong>{{ account.deck_promo_ur }}</strong> {% trans 'Promo' %})<span class="hidden deck_total_value">{{ account.deck_total }}</span></td>
</tr>
{% endif %}
<tr>
Expand Down
38 changes: 25 additions & 13 deletions web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -3337,4 +3350,3 @@ def drown(request):

def cardstrength(request):
context = globalContext(request)
return render(request, 'cardstrength.html', context)