From 44a67916ccaa83d7c0f85395a456c62638816435 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 21 Sep 2010 20:14:10 -0400 Subject: [PATCH] Ability mana symbols --- cards/views.py | 17 +++++++++++++++-- media/mtg.css | 3 +-- templates/cards/view.html | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cards/views.py b/cards/views.py index c291733..fc55933 100755 --- a/cards/views.py +++ b/cards/views.py @@ -1,11 +1,24 @@ # Create your views here. +import re from django.shortcuts import render_to_response +from django.template.loader import render_to_string from mtgweb.analyzer.models import Card -from mtgweb.lib.mtg.mtg import ManaCost +from mtgweb.lib.mtg.mtg import Mana, ManaCost import mtgweb.lib.mtg.database as database +def prettify_mana(text): + manapattern = r'X?\d*(\((\d+|[{0}])/(\d+|[{0}])\))*[{0}]*'.format(''.join(Mana.types.keys())) + pattern = r'{%s}' % manapattern + while True: + match = re.search(pattern, text) + if not match: + break + text = text[:match.start()] + render_to_string('cards/manacost.html', {'cost': ManaCost(str(match.group(0)))}) + text[match.end():] + return text + + def display(request, name): card = Card.objects.get(name=name) cost = ManaCost(str(card.cost)) - abilities = [ability for ability in card.text.split("\n") if ability] + abilities = [prettify_mana(ability) for ability in card.text.split("\n") if ability] return render_to_response('cards/view.html', {'card': card, 'cost': cost, 'abilities': abilities}) diff --git a/media/mtg.css b/media/mtg.css index 63ecea1..239e6a5 100644 --- a/media/mtg.css +++ b/media/mtg.css @@ -37,8 +37,7 @@ header { width: 1em; border-radius: 0.5em; -moz-border-radius: 0.5em; - display: block; - float: left; + display: inline-block; color: #eee; background-color: gray; border: 1px solid black; diff --git a/templates/cards/view.html b/templates/cards/view.html index d48d927..b04fd96 100644 --- a/templates/cards/view.html +++ b/templates/cards/view.html @@ -27,9 +27,11 @@
{% if card.toughness > '0' %}