Syntax issues/problems with Jinja2
Having two seperae issues with jinja2. The first being this page doesn't
seem to want to recognize the index properly for this nested dictionary.
Some info is provided below:
jinja2.exceptions.UndefinedError
UndefinedError: dict object has no element 0
Traceback
File
"/Users/mastergberry/Development/lolsummoners/lol-summoners/lolsummoners/templates/site/profile/ranked_stats.jinja2",
line 44, in block "content"
Display the sourcecode for this frameOpen an interactive python shell in
this frame<td><div class="champion_sprite gtooltip champion{{ championId
}}"></div>{{ champions[(championId)|int]['name'] }}</td>
File
"/Users/mastergberry/Development/lolsummoners/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/environment.py",
line 353, in getitem
Display the sourcecode for this frameOpen an interactive python shell in
this framereturn obj[argument]
>>> print player['ranked_stats'].items()[0]
(u'122', {u'MAX_CHAMPIONS_KILLED': 12, u'TOTAL_TRIPLE_KILLS': 4,
u'TOTAL_MINION_KILLS': 2666, u'TOTAL_DAMAGE_DEALT': 2194168,
u'MOST_SPELLS_CAST': 0, u'TOTAL_SESSIONS_PLAYED': 21,
u'TOTAL_TURRETS_KILLED': 22, u'TOTAL_SESSIONS_WON': 0,
u'TOTAL_MAGIC_DAMAGE_DEALT': 236864, u'TOTAL_DAMAGE_TAKEN': 531607,
u'MOST_CHAMPION_KILLS_PER_SESSION': 12, u'TOTAL_PENTA_KILLS': 0,
u'TOTAL_SESSIONS_LOST': 0, u'TOTAL_QUADRA_KILLS': 0,
u'TOTAL_TIME_SPENT_DEAD': 4023, u'TOTAL_PHYSICAL_DAMAGE_DEALT': 1847576,
u'MAX_NUM_DEATHS': 12, u'TOTAL_DOUBLE_KILLS': 17, u'TOTAL_CHAMPION_KILLS':
148, u'TOTAL_UNREAL_KILLS': 0, u'TOTAL_DEATHS_PER_SESSION': 122,
u'TOTAL_GOLD_EARNED': 216944, u'TOTAL_ASSISTS': 109, u'TOTAL_FIRST_BLOOD':
0})
>>> print player['ranked_stats'].items()[0][0]
122
>>> print champions[122]
{'displayName': u'Darius', 'name': u'Darius', 'title': u'the Hand of Noxus'}
<tbody>
{% for championId, data in
player['ranked_stats'].items() %}
<tr>
<td><div class="champion_sprite
gtooltip champion{{ championId
}}"></div>{{
champions[championId|int]['name']
}}</td>
<td>{{ data['TOTAL_SESSIONS_PLAYED']
}}</td>
<td>{{ (data['TOTAL_CHAMPION_KILLS'] /
data['TOTAL_SESSIONS_PLAYED'])|round(1)
}}/game</td>
<td>{{
(data['TOTAL_DEATHS_PER_SESSION'] /
data['TOTAL_SESSIONS_PLAYED'])|round(1)
}}/game</td>
<td>{{ (data['TOTAL_ASSISTS'] /
data['TOTAL_SESSIONS_PLAYED'])|round(1)
}}/game</td>
<td>{{ (data['TOTAL_MINION_KILLS'] /
data['TOTAL_SESSIONS_PLAYED'])|round(1)
}}/game</td>
</tr>
{% endfor %}
</tbody>
Happy to provide extra info.
Second problem is this data isn't being added properly.
{% set offenseTotal = 0 %}
<div class="mastery_ Offense">
{% for i in range(511, 571, 10) %}
{% set currentMax = i + 4 %}
{% for j in range(i, currentMax) %}
{% if j in page['offensive'] %}
<div class="masterblock {{ "maxrank"
if page['offensive'][j] ==
denominators[j] }}">
<div class="mastery_icon">
<div data="{{ j }}"
id="tra-target-{{ j }}"
class="masterysprite gtooltip
m{{ j }}" ></div>
<div class="master_rank">{{
page['offensive'][j] }}/{{
denominators[j] }}</div>
{# This was a test case and
isn't even working {% set
offenseTotal = (offenseTotal +
1) %} #}
{% set offenseTotal =
offenseTotal +
page['offensive'][j] %}
</div>
</div>
{% elif j not in [521, 534, 554, 561, 563,
564] %}
<div class="masterblock norank">
<div class="mastery_icon">
<div class="masterysprite m{{
j }}" ></div>
<div class="master_rank">0/{{
denominators[j] }}</div>
</div>
</div>
{% else %}
<div class="masterblock"></div>
{% endif %}
{% endfor %}
{% endfor %}
<div class="masterytitle">
Offense : {{ offenseTotal }}
</div>
</div>
Once again happy to provide extra info. Thanks for any guidance!
No comments:
Post a Comment