finished conversion to tailwind
This commit is contained in:
parent
6e2843c60e
commit
d62956d465
50 changed files with 2490 additions and 1273 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.1.2 on 2025-03-07 01:04
|
||||
# Generated by Django 5.1.2 on 2025-03-09 05:08
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ from django.utils.safestring import mark_safe
|
|||
register = template.Library()
|
||||
|
||||
@register.inclusion_tag("templatetags/card_badge.html")
|
||||
def card_badge(card, quantity=1, show_single_count=True):
|
||||
def card_badge(card, quantity=1):
|
||||
return {
|
||||
'card': card,
|
||||
'quantity': quantity,
|
||||
'decks': card.decks.all() if card else None,
|
||||
'dropdown': card is None,
|
||||
'show_single_count': show_single_count,
|
||||
'num_decks': card.decks.count() if card else None,
|
||||
}
|
||||
|
||||
@register.filter
|
||||
|
|
@ -23,6 +22,6 @@ def card_badge_inline(card, quantity=1):
|
|||
'card': card,
|
||||
'quantity': quantity,
|
||||
'decks': card.decks.all() if card else None,
|
||||
'dropdown': card is None,
|
||||
'num_decks': card.decks.count() if card else None,
|
||||
})
|
||||
return mark_safe(html)
|
||||
|
|
@ -6,22 +6,24 @@ register = template.Library()
|
|||
@register.inclusion_tag('templatetags/card_multiselect.html')
|
||||
def card_multiselect(field_name, label, placeholder, card_filter=None, selected_values=None, cache_timeout=86400, cache_key="available_cards_options"):
|
||||
"""
|
||||
Renders a multiselect field for choosing cards, storing the card ID only as the option's value and
|
||||
the quantity in a dedicated data attribute.
|
||||
|
||||
Renders a multiselect field for choosing cards while supporting quantity data.
|
||||
|
||||
Updated to allow `card_filter` to be either a dictionary (of lookup parameters) or a QuerySet.
|
||||
This is useful when you want to limit available cards based on your new trades models (e.g. showing only
|
||||
cards that appear in active trade offers).
|
||||
|
||||
Parameters:
|
||||
- field_name: The name attribute for the select tag.
|
||||
- label: Label text to show above the selector.
|
||||
- placeholder: Placeholder text to show in the select.
|
||||
- card_filter: (Optional) A dictionary of filter parameters to apply on the Card query.
|
||||
- selected_values: (Optional) A list of selected card values; if a value includes a quantity
|
||||
it should be in the format "card_id:quantity".
|
||||
- card_filter: (Optional) A dictionary of filter parameters or a QuerySet to obtain the available Card objects.
|
||||
- selected_values: (Optional) A list of selected values; if a value includes a quantity it should be in the format "card_id:quantity".
|
||||
- cache_timeout: (Optional) Cache timeout (in seconds) for the options block.
|
||||
- cache_key: (Optional) Cache key—by default both select fields use the same key so that caching is shared.
|
||||
- cache_key: (Optional) Cache key.
|
||||
"""
|
||||
if selected_values is None:
|
||||
selected_values = []
|
||||
# Map the selected values into a dictionary: { card_id (str): quantity (str) }
|
||||
# Create a mapping {card_id: quantity}
|
||||
selected_cards = {}
|
||||
for val in selected_values:
|
||||
parts = str(val).split(':')
|
||||
|
|
@ -29,11 +31,16 @@ def card_multiselect(field_name, label, placeholder, card_filter=None, selected_
|
|||
quantity = parts[1] if len(parts) > 1 else "1"
|
||||
selected_cards[card_id] = quantity
|
||||
|
||||
# If a card_filter is provided, use it; otherwise retrieve all cards.
|
||||
if card_filter:
|
||||
available_cards_qs = Card.objects.filter(**card_filter)
|
||||
else:
|
||||
# Determine how to obtain the available cards.
|
||||
# If card_filter is not provided, or is None, fall back to all cards.
|
||||
if card_filter is None:
|
||||
available_cards_qs = Card.objects.all()
|
||||
# If card_filter is a dict, treat it as mapping lookup parameters.
|
||||
elif isinstance(card_filter, dict):
|
||||
available_cards_qs = Card.objects.filter(**card_filter)
|
||||
# Otherwise assume it's already a QuerySet.
|
||||
else:
|
||||
available_cards_qs = card_filter
|
||||
|
||||
available_cards = list(
|
||||
available_cards_qs.order_by("name", "rarity__pk")
|
||||
|
|
@ -41,19 +48,17 @@ def card_multiselect(field_name, label, placeholder, card_filter=None, selected_
|
|||
.prefetch_related("decks")
|
||||
)
|
||||
|
||||
# Loop through available cards and set styling, plus attach pre‑selected quantity
|
||||
for card in available_cards:
|
||||
# Apply styling based on deck count.
|
||||
deck_count = card.decks.count()
|
||||
if deck_count == 1:
|
||||
card.style = f"background-color: {card.decks.all()[0].hex_color}; color: white;"
|
||||
elif deck_count == 2:
|
||||
decks = card.decks.all()
|
||||
card.style = f"background: linear-gradient(to right, {decks[0].hex_color}, {decks[1].hex_color}); color: white;"
|
||||
elif deck_count >= 3:
|
||||
decks = card.decks.all()
|
||||
card.style = f"background: linear-gradient(to right, {decks[0].hex_color}, {decks[1].hex_color}, {decks[2].hex_color}); color: white;"
|
||||
# decks = list(card.decks.all())
|
||||
# deck_count = len(decks)
|
||||
# if deck_count == 1:
|
||||
# card.style = f"background-color: {decks[0].hex_color}; color: white;"
|
||||
# elif deck_count == 2:
|
||||
# card.style = f"background: linear-gradient(to right, {decks[0].hex_color}, {decks[1].hex_color}); color: white;"
|
||||
# elif deck_count >= 3:
|
||||
# card.style = f"background: linear-gradient(to right, {decks[0].hex_color}, {decks[1].hex_color}, {decks[2].hex_color}); color: white;"
|
||||
|
||||
# Attach selected_quantity only if the card is pre‑selected.
|
||||
pk_str = str(card.pk)
|
||||
if pk_str in selected_cards:
|
||||
card.selected_quantity = selected_cards[pk_str]
|
||||
|
|
@ -64,7 +69,7 @@ def card_multiselect(field_name, label, placeholder, card_filter=None, selected_
|
|||
'label': label,
|
||||
'available_cards': available_cards,
|
||||
'placeholder': placeholder,
|
||||
# For caching/selection checks, pass a list of the pre‑selected card IDs.
|
||||
# Pass just the list of pre‑selected card IDs for caching/selection logic in the template.
|
||||
'selected_values': list(selected_cards.keys()),
|
||||
'cache_timeout': cache_timeout,
|
||||
'cache_key': cache_key,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue