Made cards database driven

This commit is contained in:
Correl Roush 2010-09-17 17:44:54 -04:00
parent 8e1bba2ceb
commit ccff6b2c88
2 changed files with 12 additions and 13 deletions

View file

@ -1,8 +1,11 @@
# Create your views here. # Create your views here.
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from mtgweb.analyzer.models import Card
from mtgweb.lib.mtg.mtg import ManaCost
import mtgweb.lib.mtg.database as database import mtgweb.lib.mtg.database as database
def display(request, name): def display(request, name):
db = database.TextDB('/home/correlr/code/mtgweb/lib/mtg/db.txt') card = Card.objects.get(name=name)
card = db.getCard(name.replace('_', ' ').strip()) cost = ManaCost(str(card.cost))
return render_to_response('cards/view.html', {'card': card}) abilities = [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

@ -65,21 +65,17 @@
<div class="title"> <div class="title">
<span class="name">{{ card.name|title }}</span> <span class="name">{{ card.name|title }}</span>
<span class="cost"> <span class="cost">
{% if card.cost %} {% include 'cards/manacost.html' %}
{% with card.cost as cost %}
{% include 'cards/manacost.html' %}
{% endwith %}
{% endif %}
</span> </span>
</div> </div>
<div class="picture"></div> <div class="picture"></div>
<div class="info"> <div class="info">
<span class="type"> <span class="type">
{{ card.type|title }} {{ card.type|title }}
{% if card.attributes %} &mdash;
&mdash; {% for attr in card.attributes.all %}
{{ card.attributes|join:" "|title }} {{ attr|title }}
{% endif %} {% endfor %}
</span> </span>
<span class="rarity {{ card.rarity }}"> <span class="rarity {{ card.rarity }}">
{% for key, rarity in card.rarities.items %} {% for key, rarity in card.rarities.items %}
@ -89,7 +85,7 @@
</div> </div>
<div class="text"> <div class="text">
<ul> <ul>
{% for ability in card.text %} {% for ability in abilities %}
<li>{{ ability }}</li> <li>{{ ability }}</li>
{% endfor %} {% endfor %}
</ul> </ul>