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. # Create your views here.
import re
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from mtgweb.analyzer.models import Card 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 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): def display(request, name):
card = Card.objects.get(name=name) card = Card.objects.get(name=name)
cost = ManaCost(str(card.cost)) 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}) return render_to_response('cards/view.html', {'card': card, 'cost': cost, 'abilities': abilities})

View file

@ -37,8 +37,7 @@ header {
width: 1em; width: 1em;
border-radius: 0.5em; border-radius: 0.5em;
-moz-border-radius: 0.5em; -moz-border-radius: 0.5em;
display: block; display: inline-block;
float: left;
color: #eee; color: #eee;
background-color: gray; background-color: gray;
border: 1px solid black; border: 1px solid black;

View file

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