Calculate the "director" flag from roles

This commit is contained in:
2011-03-15 17:00:08 +00:00
parent 06ff735b45
commit d33b85899c
2 changed files with 9 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from eve_api.app_defines import *
from eve_api.models import EVEAPIModel
@@ -27,11 +28,17 @@ class EVEPlayerCharacter(EVEAPIModel):
help_text="The last time this character logged into EVE")
last_logoff = models.DateTimeField(blank=True, null=True, verbose_name="Last Logoff Date/Time",
help_text="The last time this character logged off EVE")
director = models.BooleanField(blank=False, default=False, verbose_name="Director",
help_text="This character is a Director of the associated corporation")
roles = models.ManyToManyField('eve_api.EVEPlayerCharacterRole', blank=True, null=True,
help_text="Roles associated with this character")
skills = models.ManyToManyField('eve_api.EVESkill', through='eve_api.EVEPlayerCharacterSkill')
@property
def director(self):
try:
self.roles.get(name="roleDirector")
return True
except ObjectDoesNotExist:
return False
def __unicode__(self):
if self.name:

View File

@@ -138,15 +138,12 @@ def import_eve_character_func(character_id, api_key=None, user_id=None, logger=l
charskillobj.save()
# Process the character's roles
pchar.director = False
pchar.roles.clear()
roles = values.get('corporationRoles', None)
if roles and len(roles):
for r in roles:
role, created = EVEPlayerCharacterRole.objects.get_or_create(roleid=r['roleID'], name=r['roleName'])
pchar.roles.add(role)
if r['roleName'] == 'roleDirector':
pchar.director = True
if values['gender'] == 'Male':
pchar.gender = API_GENDER_MALE