Example #1
0
    def pull_character(self, info):
        """This always updates all information on the character, so that we do not end up with
        inconsistencies. There is some weirdness that, if a user already has a key with full
        permissions, and adds a limited one, we'll erase information on that character. We should
        probably check for and refresh info from the most-permissioned key instead of this."""
        from brave.core.character.model import EVEAlliance, EVECorporation, EVECharacter
        try:
            char = EVECharacter(identifier=info.characterID).save()
        except NotUniqueError:
            char = EVECharacter.objects(identifier=info.characterID)[0]

            if self.owner != char.owner:
                log.warning(
                    "Security violation detected. Multiple accounts trying to register character %s, ID %d. Actual owner is %s. User adding this character is %s.",
                    char.name, info.characterID,
                    EVECharacter.objects(
                        identifier=info.characterID).first().owner, self.owner)
                self.violation = "Character"
                return

        if self.mask.has_access(EVECharacterKeyMask.CHARACTER_SHEET):
            info = api.char.CharacterSheet(self, characterID=info.characterID)
        elif self.mask.has_access(EVECharacterKeyMask.CHARACTER_INFO_PUBLIC):
            info = api.eve.CharacterInfo(self, characterID=info.characterID)

        char.corporation, char.alliance = self.get_membership(info)

        char.name = info.name if 'name' in info else info.characterName
        char.owner = self.owner
        if self not in char.credentials:
            char.credentials.append(self)
        char.race = info.race if 'race' in info else None
        char.bloodline = (info.bloodLine if 'bloodLine' in info else
                          info.bloodline if 'bloodline' in info else None)
        char.ancestry = info.ancestry if 'ancestry' in info else None
        char.gender = info.gender if 'gender' in info else None
        char.security = info.security if 'security' in info else None
        char.titles = [
            strip_tags(i.titleName) for i in info.corporationTitles.row
        ] if 'corporationTitles' in info else []
        char.roles = [i.roleName for i in info.corporationRoles.row
                      ] if 'corporationRoles' in info else []

        char.save()
        return char