Example #1
0
def update_character_associations(user):
    LOG.debug("Updating character ownerships for '%s'..." % user.username)
    eve_accounts = []
    invalid_api_keys = []
    new_characters = set()
    new_corps = set()
    skills = []

    # get all the user's registered api credentials
    for api_key in user.eve_accounts.all():
        try:
            conn = api.connect_user(api_key)
            for char in api.get_account_characters(api_key):
                try:
                    member = Member.objects.get(characterID=char.characterID)
                except Member.DoesNotExist:
                    member = Member(characterID=char.characterID,
                                    name=char.name)

                char_info = conn.eve.CharacterInfo(
                    characterID=member.characterID)
                set_char_info_attributes(member, char_info)
                # This also sets employment history.
                # TODO 1 move employment history into separate function
                # TODO 2 optimizie; only check if corp has changed, and add history records in save_all below.
                sheet = conn.char.CharacterSheet(
                    characterID=member.characterID)
                set_extended_char_attributes(member, sheet)
                skills.extend(get_character_skills(member, sheet))

                if not member in new_characters:
                    corp = get_corp(char.corporationID)
                    if member.corp != corp:
                        member.corp = corp
                        new_corps.add(corp)
                    new_characters.add(member)

            api_key.is_valid = True
        except api.AuthenticationError, e:
            LOG.warning("%s (user: '******' keyID: %d)" %
                        (str(e), user.username, api_key.keyID))
            api_key.is_valid = False
            api_key.error = str(e)
            invalid_api_keys.append(api_key)
        except api.Error, e:
            # for all other errors, we abort the operation so that
            # character associations are not deleted by mistake and
            # therefore, that users find themselves with no access :)
            LOG.error("%d: %s (user: '******' keyID: %d)" %
                      (e.code, str(e), user.username, api_key.keyID))
            raise
Example #2
0
def parseOneMember(member, my_corp):
    try:
        location = CelestialObject.objects.get(
            itemID=member.locationID).itemName
    except CelestialObject.DoesNotExist:
        location = str(member.locationID)
    try:
        mem = Member.objects.get(characterID=member.characterID)
        mem.corp = my_corp
        mem.nickname = member.title
        mem.baseID = member.baseID
        mem.corpDate = timezone.make_aware(member.startDateTime, timezone.utc)
        mem.lastLogin = timezone.make_aware(member.logonDateTime, timezone.utc)
        mem.lastLogoff = timezone.make_aware(member.logoffDateTime,
                                             timezone.utc)
        mem.location = location
        mem.locationID = member.locationID
        mem.ship = member.shipType
        return mem
    except Member.DoesNotExist:
        return Member(corp=my_corp,
                      characterID=member.characterID,
                      name=member.name,
                      nickname=member.title,
                      baseID=member.baseID,
                      corpDate=timezone.make_aware(member.startDateTime,
                                                   timezone.utc),
                      lastLogin=timezone.make_aware(member.logonDateTime,
                                                    timezone.utc),
                      lastLogoff=timezone.make_aware(member.logoffDateTime,
                                                     timezone.utc),
                      location=location,
                      locationID=member.locationID,
                      ship=member.shipType)
Example #3
0
File: users.py Project: evecm/ecm
def update_character_associations(user):
    LOG.debug("Updating character ownerships for '%s'..." % user.username)
    eve_accounts = []
    invalid_api_keys = []
    new_characters = set()
    new_corps = set()
    skills = []
    
    # get all the user's registered api credentials
    for api_key in user.eve_accounts.all():
        try:
            conn = api.connect_user(api_key)
            for char in api.get_account_characters(api_key):
                try:
                    member = Member.objects.get(characterID=char.characterID)
                except Member.DoesNotExist:
                    member = Member(characterID=char.characterID,
                                    name=char.name)

                char_info = conn.eve.CharacterInfo(characterID=member.characterID)
                set_char_info_attributes(member, char_info)
                    # This also sets employment history.
                    # TODO 1 move employment history into separate function
                    # TODO 2 optimizie; only check if corp has changed, and add history records in save_all below.
                sheet = conn.char.CharacterSheet(characterID=member.characterID)
                set_extended_char_attributes(member, sheet)
                skills.extend(get_character_skills(member, sheet))

                if not member in new_characters:
                    corp = get_corp(char.corporationID)
                    if member.corp != corp:
                        member.corp = corp
                        new_corps.add(corp)
                    new_characters.add(member)
                
            api_key.is_valid = True
        except api.AuthenticationError, e:
            LOG.warning("%s (user: '******' keyID: %d)" % (str(e), user.username, api_key.keyID))
            api_key.is_valid = False
            api_key.error = str(e)
            invalid_api_keys.append(api_key)
        except api.Error, e:
            # for all other errors, we abort the operation so that
            # character associations are not deleted by mistake and
            # therefore, that users find themselves with no access :)
            LOG.error("%d: %s (user: '******' keyID: %d)" % (e.code, str(e), user.username, api_key.keyID))
            raise
Example #4
0
def get_char(characterID):
    api_conn = api.eveapi.EVEAPIConnection()
    char = api_conn.eve.CharacterInfo(characterID = characterID)
    try:
        corp = Corporation.objects.get(corporationID = char.corporationID)
    except Corporation.DoesNotExist:
        corp = get_corp(char.corporationID)
    LOG.info("Adding new Player: "+ char.characterName)
    mem = Member()
    mem.characterID = char.characterID
    mem.name = char.characterName
    mem.race = char.race
    mem.bloodline = char.bloodline
    mem.corp = corp
    mem.corpDate = char.corporationDate
    mem.securityStatus = char.securityStatus
    mem.save()
    return mem
Example #5
0
def details(request, characterID):
    avg_session = {
      'sessionlength': 0,
      '30days': 0,
      '7days': 0,
    }
    now = timezone.now()
    try:
        member = Member.objects.get(characterID=int(characterID))
        try:
            member.base = CelestialObject.objects.get(itemID=member.baseID).itemName
        except CelestialObject.DoesNotExist:
            member.base = str(member.baseID)

        member.color = ColorThreshold.get_access_color(member.accessLvl)
        member.roles_no_director = member.roles.exclude(roleID=1) # exclude 'director'

        query = MemberSession.objects.filter(character_id=member.characterID).order_by('session_begin')
        query_30 = query.filter(session_begin__gt=now - timedelta(30))
        query_7 = query.filter(session_begin__gt=now - timedelta(7))

        session_len = query.aggregate(len=Avg('session_seconds'))['len'] or 0
        session_len_30 = query_30.aggregate(len=Avg('session_seconds'))['len'] or 0
        session_len_7 = query_7.aggregate(len=Avg('session_seconds'))['len'] or 0

        # Totals
        total = query.aggregate(len=Sum('session_seconds'))['len'] or 0
        lastWeek = query_7.aggregate(len=Sum('session_seconds'))['len'] or 0
        lastMonth = query_30.aggregate(len=Sum('session_seconds'))['len'] or 0


        loginhistory = query.order_by('-session_begin')[:10]

        avg_session['sessionlength'] = timedelta(seconds=session_len)
        avg_session['30days'] = timedelta(seconds=session_len_30)
        avg_session['7days'] = timedelta(seconds=session_len_7)

        if member.corp_id == Corporation.objects.mine().corporationID:
            member.date = UpdateDate.get_latest(Member)
        else:
            try:
                d = MemberDiff.objects.filter(member=member, new=False).order_by("-id")[0]
                member.date = d.date
            except IndexError:
                member.date = 0
        skills, skill_count, skillpoint_count = get_skills(member)
    except Member.DoesNotExist:
        member = Member(characterID=int(characterID), name="???")
    
    try:
        killboardUrl = Setting.get('corp_killboard_url')
    except Setting.DoesNotExist:
        killboardUrl = None
    
    data = {
        'member'             : member,
        'killboardUrl'       : killboardUrl,
        'sessiondata'        : avg_session,
        'lastWeek'           : lastWeek,
        'lastMonth'          : lastMonth,
        'total'              : total,
        'logins'             : loginhistory,
        'skills_tree'        : json.dumps(skills),
        'skill_count'        : skill_count,
        'skillpoint_count'   : print_integer(skillpoint_count),
        'datatables_defaults': DATATABLES_DEFAULTS,
        'access_columns'     : ACCESS_CHANGES_COLUMNS,
        'sorting'            : [[2, 'desc']],
    }
    return render_to_response("ecm/hr/members/details.html", data, Ctx(request))
Example #6
0
def get_char(characterID):
    api_conn = api.eveapi.EVEAPIConnection()
    char = api_conn.eve.CharacterInfo(characterID=characterID)
    try:
        corp = Corporation.objects.get(corporationID=char.corporationID)
    except Corporation.DoesNotExist:
        corp = get_corp(char.corporationID)
    LOG.info("Adding new Player: " + char.characterName)
    mem = Member()
    mem.characterID = char.characterID
    mem.name = char.characterName
    mem.race = char.race
    mem.bloodline = char.bloodline
    mem.corp = corp
    mem.corpDate = char.corporationDate
    mem.securityStatus = char.securityStatus
    mem.save()
    return mem