This commit is contained in:
Correl Roush 2010-08-25 23:43:19 -04:00
parent 2e9451d7ef
commit f18118020c
9 changed files with 135 additions and 3 deletions

0
cards/__init__.py Executable file
View file

3
cards/models.py Executable file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

23
cards/tests.py Executable file
View file

@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

8
cards/views.py Executable file
View file

@ -0,0 +1,8 @@
# Create your views here.
from django.shortcuts import render_to_response
import mtgweb.lib.mtg.database as database
def display(request, name):
db = database.TextDB('/home/correlr/code/mtgweb/lib/mtg/db.txt')
card = db.getCard(name.replace('_', ' ').strip())
return render_to_response('cards/view.html', {'card': card})

View file

@ -1 +1,10 @@
# Create your views here.
from django.shortcuts import render_to_response
import mtgweb.lib.mtg.mtg as mtg
import mtgweb.lib.mtg.database as database
def index(request):
db = database.TextDB('mtgweb/lib/mtg/db.txt')
deck = mtg.Deck()
print db.getCard('Forest')
deck.load('mtgweb/lib/mtg/decks/WhiteBeast.txt', db)
return render_to_response('decks/index.html', {'deck': deck})

View file

@ -11,8 +11,8 @@ MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mtg.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
@ -81,6 +81,7 @@ TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/correlr/code/mtgweb/templates',
)
INSTALLED_APPS = (

80
templates/cards/view.html Executable file
View file

@ -0,0 +1,80 @@
<html>
<head>
<title>Card: {{ card.name }}</title>
<style type="text/css">
.card {
border: 1px solid gray;
background-color: #999;
padding: 3px;
}
.card.R { background-color: red; }
.card.G { background-color: green; }
.card.U { background-color: blue; }
.card.B { background-color: black; }
.card.W { background-color: white; }
.card .title,
.card .info {
border: 1px solid gray;
background-color: #eee;
padding: 3px;
height: 1em;
}
.card .title .name,
.card .info .type {
font-weight: bold;
float: left;
}
.card .title .cost,
.card .info .rarity {
float: right;
}
.card .rarity {
}
.card .rarity.U { color: gray; }
.card .rarity.R { color: darkgoldenrod; }
.card .rarity.M { color: red; }
.card .picture {
height: 5em;
background-color: #ccc;
margin: 5px;
}
.card .text {
margin-top: 5px;
border: 1px solid gray;
background-color: white;
padding: 3px;
}
</style>
</head>
<body>
<div class="card {{ card.colors|join:" " }}">
<div class="title">
<span class="name">{{ card.name|title }}</span>
<span class="cost">{% if card.cost %}{{ card.cost }}{% endif %}</span>
</div>
<div class="picture"></div>
<div class="info">
<span class="type">
{{ card.type|title }}
{% if card.attributes %}
&mdash;
{{ card.attributes|join:" "|title }}
{% endif %}
</span>
<span class="rarity {{ card.rarity }}">
{% for key, rarity in card.rarities.items %}
{% if key == card.rarity %}{{ rarity }}{% endif %}
{% endfor %}
</span>
</div>
<div class="text">
<ul>
{% for ability in card.text %}
<li>{{ ability }}</li>
{% endfor %}
</ul>
</div>
</div>
</body>
</html>

6
templates/decks/index.html Executable file
View file

@ -0,0 +1,6 @@
<html>
<body>
<pre>foobar
</pre>
</body>
</html>

View file

@ -7,6 +7,8 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('',
# Example:
# (r'^mtgweb/', include('mtgweb.foo.urls')),
(r'^cards/(?P<name>.*?)/$', 'mtgweb.cards.views.display'),
(r'^decks/$', 'mtgweb.decks.views.index'),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation: