mtg-web/decks/views.py

48 lines
1.7 KiB
Python
Raw Normal View History

from django.http import Http404
2010-08-26 03:43:19 +00:00
from django.shortcuts import render_to_response
from mtgweb.analyzer.models import Deck
2010-09-22 18:22:21 +00:00
from mtgweb.lib.mtg import mtg
from pygooglechart import PieChart3D
2010-08-26 03:43:19 +00:00
def index(request):
decks = Deck.objects.all()
return render_to_response('decks/index.html', {'decks': decks})
def detail(request, id):
try:
deck = Deck.objects.get(pk=id)
except Deck.DoesNotExist:
raise Http404
2010-09-22 18:22:21 +00:00
# Generate charts
colors = {
'R': 'FF0000',
'G': '00FF00',
'U': '0000FF',
'W': 'FFFFFF',
'B': '000000',
}
land_chart = PieChart3D(250, 100)
lands = dict([(k, v) for k, v in deck.lands().items() if v])
land_chart.fill_solid(PieChart3D.BACKGROUND, 'FFFFFF00')
land_chart.add_data(lands.values())
land_chart.set_pie_labels([mtg.Mana.types[m] for m in lands.keys()])
land_chart.set_colours([colors[m] for m in lands.keys()])
symbol_chart = PieChart3D(250, 100)
symbols = dict([(k, v) for k, v in deck.symbols().items() if v])
symbol_chart.fill_solid(PieChart3D.BACKGROUND, 'FFFFFF00')
symbol_chart.add_data(symbols.values())
symbol_chart.set_pie_labels([mtg.Mana.types[m] for m in symbols.keys()])
symbol_chart.set_colours([colors[m] for m in symbols.keys()])
curve = deck.mana_curve()
for i in range(max(curve.keys()) + 1):
if i not in curve:
curve[i] = 0
return render_to_response('decks/detail.html', {
'deck': deck,
'land_chart': land_chart,
'symbol_chart': symbol_chart,
'curve': curve})