Centralize portrait/logo URL creation.

This commit is contained in:
Adarnof 2018-02-23 12:45:23 -05:00
parent 36ae2af29b
commit 7a9bb0c84b
4 changed files with 39 additions and 7 deletions

View File

@ -21,7 +21,7 @@
<table class="table">
<tr>
<td class="text-center"><img class="ra-avatar"
src="https://image.eveonline.com/Character/{{ main.character_id }}_128.jpg">
src="{{ main.portrait_url_128 }}">
</td>
</tr>
<tr>
@ -102,8 +102,7 @@
{% for ownership in request.user.character_ownerships.all %}
{% with ownership.character as char %}
<tr>
<td class="text-center"><img class="ra-avatar img-circle"
src="https://image.eveonline.com/Character/{{ char.character_id }}_32.jpg">
<td class="text-center"><img class="ra-avatar img-circle" src="{{ char.portrait_url_32 }}">
</td>
<td class="text-center">{{ char.character_name }}</td>
<td class="text-center">{{ char.corporation_name }}</td>

View File

@ -182,4 +182,4 @@ class CorpMember(models.Model):
if item.startswith('portrait_url_'):
size = item.strip('portrait_url_')
return self.portrait_url(size)
return super(CorpMember, self).__getattr__(item)
return self.__getattribute__(item)

View File

@ -9,9 +9,9 @@
<tr>
<td class="text-center col-lg-6
{% if corpstats.corp.alliance %}{% else %}col-lg-offset-3{% endif %}"><img
class="ra-avatar" src="{{ corpstats.corp_logo }}"></td>
class="ra-avatar" src="{{ corpstats.corp.logo_url_128 }}"></td>
{% if corpstats.corp.alliance %}
<td class="text-center col-lg-6"><img class="ra-avatar" src="{{ corpstats.alliance_logo }}">
<td class="text-center col-lg-6"><img class="ra-avatar" src="{{ corpstats.alliance.logo_url_128 }}">
</td>
{% endif %}
</tr>
@ -70,6 +70,7 @@
{% for alt in main.alts %}
{% if forloop.first %}
<tr>
<th></th>
<th class="text-center">{% trans "Character" %}</th>
<th class="text-center">{% trans "Corporation" %}</th>
<th class="text-center">{% trans "Alliance" %}</th>
@ -77,10 +78,15 @@
</tr>
{% endif %}
<tr>
<td class="text-center" style="width:5%">
<div class="thumbnail" style="border: 0 none; box-shadow: none; background: transparent;">
<img src="https://image.eveonline.com/Character/{{ alt.character_id }}_32.jpg" class="img-circle">
</div>
</td>
<td class="text-center" style="width:30%">{{ alt.character_name }}</td>
<td class="text-center" style="width:30%">{{ alt.corporation_name }}</td>
<td class="text-center" style="width:30%">{{ alt.alliance_name }}</td>
<td class="text-center" style="width:10%">
<td class="text-center" style="width:5%">
<a href="https://zkillboard.com/character/{{ alt.character_id }}/"
class="label label-danger" target="_blank">
{% trans "Killboard" %}

View File

@ -35,6 +35,15 @@ class EveAllianceInfo(models.Model):
def __str__(self):
return self.alliance_name
def logo_url(self, size=32):
return "https://image.eveonline.com/Alliance/%s_%s.png" % (self.alliance_id, size)
def __getattr__(self, item):
if item.startswith('logo_url_'):
size = item.strip('logo_url_')
return self.logo_url(size)
return self.__getattribute__(item)
class EveCorporationInfo(models.Model):
corporation_id = models.CharField(max_length=254, unique=True)
@ -60,6 +69,15 @@ class EveCorporationInfo(models.Model):
def __str__(self):
return self.corporation_name
def logo_url(self, size=32):
return "https://image.eveonline.com/Corporation/%s_%s.png" % (self.corporation_id, size)
def __getattr__(self, item):
if item.startswith('logo_url_'):
size = item.strip('logo_url_')
return self.logo_url(size)
return self.__getattribute__(item)
class EveCharacter(models.Model):
character_id = models.CharField(max_length=254, unique=True)
@ -107,3 +125,12 @@ class EveCharacter(models.Model):
def __str__(self):
return self.character_name
def portrait_url(self, size=32):
return "https://image.eveonline.com/Character/%s_%s.jpg" % (self.character_id, size)
def __getattr__(self, item):
if item.startswith('portrait_url_'):
size = item.strip('portrait_url_')
return self.portrait_url(size)
return self.__getattribute__(item)