Move API key percentage to the model

This commit is contained in:
2011-07-19 09:48:53 +01:00
parent 9a13bb547b
commit ae3f5e5675
4 changed files with 28 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
from django.db import models
from django.contrib.auth.models import Group
from eve_api.models import EVEAPIModel
from eve_api.app_defines import *
class EVEPlayerCorporation(EVEAPIModel):
"""
@@ -29,6 +30,27 @@ class EVEPlayerCorporation(EVEAPIModel):
group = models.ForeignKey(Group, blank=True, null=True)
@property
def directors(self):
""" Return a queryset of corporate Directors """
return self.eveplayercharacter_set.filter(roles__name="roleDirector")
@property
def api_keys(self):
""" Returns the number of characters with stored API keys """
return self.eveplayercharacter_set.filter(eveaccount__isnull=False).count()
@property
def api_key_coverage(self):
""" Returns the percentage coverage of API keys for the corporation's members """
# Check if we have a full director key, see if we can base our assumptions off what is in auth already
if self.directors.filter(eveaccount__isnull=False, eveaccount__api_keytype=API_KEYTYPE_FULL).count():
membercount = self.eveplayercharacter_set.count()
else:
membercount = self.member_count
return (float(self.api_keys) / membercount) * 100
@models.permalink
def get_absolute_url(self):
return ('eveapi-corporation', [self.pk])