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"> <table class="table">
<tr> <tr>
<td class="text-center"><img class="ra-avatar" <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> </td>
</tr> </tr>
<tr> <tr>
@ -102,8 +102,7 @@
{% for ownership in request.user.character_ownerships.all %} {% for ownership in request.user.character_ownerships.all %}
{% with ownership.character as char %} {% with ownership.character as char %}
<tr> <tr>
<td class="text-center"><img class="ra-avatar img-circle" <td class="text-center"><img class="ra-avatar img-circle" src="{{ char.portrait_url_32 }}">
src="https://image.eveonline.com/Character/{{ char.character_id }}_32.jpg">
</td> </td>
<td class="text-center">{{ char.character_name }}</td> <td class="text-center">{{ char.character_name }}</td>
<td class="text-center">{{ char.corporation_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_'): if item.startswith('portrait_url_'):
size = item.strip('portrait_url_') size = item.strip('portrait_url_')
return self.portrait_url(size) return self.portrait_url(size)
return super(CorpMember, self).__getattr__(item) return self.__getattribute__(item)

View File

@ -9,9 +9,9 @@
<tr> <tr>
<td class="text-center col-lg-6 <td class="text-center col-lg-6
{% if corpstats.corp.alliance %}{% else %}col-lg-offset-3{% endif %}"><img {% 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 %} {% 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> </td>
{% endif %} {% endif %}
</tr> </tr>
@ -70,6 +70,7 @@
{% for alt in main.alts %} {% for alt in main.alts %}
{% if forloop.first %} {% if forloop.first %}
<tr> <tr>
<th></th>
<th class="text-center">{% trans "Character" %}</th> <th class="text-center">{% trans "Character" %}</th>
<th class="text-center">{% trans "Corporation" %}</th> <th class="text-center">{% trans "Corporation" %}</th>
<th class="text-center">{% trans "Alliance" %}</th> <th class="text-center">{% trans "Alliance" %}</th>
@ -77,10 +78,15 @@
</tr> </tr>
{% endif %} {% endif %}
<tr> <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.character_name }}</td>
<td class="text-center" style="width:30%">{{ alt.corporation_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: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 }}/" <a href="https://zkillboard.com/character/{{ alt.character_id }}/"
class="label label-danger" target="_blank"> class="label label-danger" target="_blank">
{% trans "Killboard" %} {% trans "Killboard" %}

View File

@ -35,6 +35,15 @@ class EveAllianceInfo(models.Model):
def __str__(self): def __str__(self):
return self.alliance_name 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): class EveCorporationInfo(models.Model):
corporation_id = models.CharField(max_length=254, unique=True) corporation_id = models.CharField(max_length=254, unique=True)
@ -60,6 +69,15 @@ class EveCorporationInfo(models.Model):
def __str__(self): def __str__(self):
return self.corporation_name 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): class EveCharacter(models.Model):
character_id = models.CharField(max_length=254, unique=True) character_id = models.CharField(max_length=254, unique=True)
@ -107,3 +125,12 @@ class EveCharacter(models.Model):
def __str__(self): def __str__(self):
return self.character_name 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)