mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Optimize the character list view
This commit is contained in:
17
sso/views.py
17
sso/views.py
@@ -4,7 +4,7 @@ import re
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
@@ -41,21 +41,10 @@ def profile(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def characters(request, charid=0):
|
def characters(request, charid=0):
|
||||||
if charid:
|
if charid:
|
||||||
try:
|
character = get_object_or_404(EVEPlayerCharacter, id=charid)
|
||||||
character = EVEPlayerCharacter.objects.get(id=charid)
|
|
||||||
except EVEPlayerCharacter.DoesNotExist:
|
|
||||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
|
||||||
return render_to_response('sso/character.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('sso/character.html', locals(), context_instance=RequestContext(request))
|
||||||
try:
|
|
||||||
eveaccounts = EVEAccount.objects.filter(user=request.user).all()
|
|
||||||
characters = []
|
|
||||||
for acc in eveaccounts:
|
|
||||||
chars = acc.characters.all()
|
|
||||||
for char in chars:
|
|
||||||
characters.append({'id': char.id, 'name': char.name, 'corp': char.corporation })
|
|
||||||
except EVEAccount.DoesNotExist:
|
|
||||||
characters = []
|
|
||||||
|
|
||||||
|
characters = EVEPlayerCharacter.objects.select_related('corporation', 'corporation__alliance').filter(eveaccount__user=request.user).only('id', 'name', 'corporation__name', 'corporation__alliance__name')
|
||||||
return render_to_response('sso/characterlist.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('sso/characterlist.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
<tr><th>Character Name</th><th>Corporation</th><th>Alliance</th></tr>
|
<tr><th>Character Name</th><th>Corporation</th><th>Alliance</th></tr>
|
||||||
{% for char in characters %}
|
{% for char in characters %}
|
||||||
<tr><td><a href="{% url sso.views.characters char.id %}">{{ char.name }}</a></td>
|
<tr><td><a href="{% url sso.views.characters char.id %}">{{ char.name }}</a></td>
|
||||||
<td>{{ char.corp }}</td>
|
<td>{{ char.corporation }}</td>
|
||||||
<td>{% if char.corp.alliance %}{{ char.corp.alliance }}{% endif %}</td>
|
<td>{% if char.corporation.alliance %}{{ char.corporation.alliance }}{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user