Ability mana symbols

This commit is contained in:
Correl Roush 2010-09-21 20:14:10 -04:00
parent 9371e834c7
commit 44a67916cc
3 changed files with 18 additions and 4 deletions

View file

@ -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})

View file

@ -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;

View file

@ -27,9 +27,11 @@
</div>
<div class="text">
<ul>
{% autoescape off %}
{% for ability in abilities %}
<li>{{ ability }}</li>
{% endfor %}
{% endautoescape %}
</ul>
</div>
{% if card.toughness > '0' %}