From 2bf133ceee5af29cc08443a3ae76b27214ecf461 Mon Sep 17 00:00:00 2001 From: Adarnof Date: Sun, 7 Feb 2016 17:28:16 +0000 Subject: [PATCH] Corrections --- celerytask/tasks.py | 56 ++++++++++++++++++++++----------------------- eveonline/views.py | 2 +- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/celerytask/tasks.py b/celerytask/tasks.py index dd23c544..e75eee2b 100755 --- a/celerytask/tasks.py +++ b/celerytask/tasks.py @@ -1,6 +1,5 @@ from django.conf import settings from celery.task import periodic_task -from celery.task import shared_task from django.contrib.auth.models import User from django.contrib.auth.models import Group @@ -248,7 +247,7 @@ def remove_from_databases(user, groups, syncgroups): def assign_corp_group(auth): corp_group = None - if auth.main_character_id: + if auth.main_char_id: if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): char = EveCharacter.objects.get(character_id=auth.main_char_id) corpname = generate_corp_group_name(char.corporation_name) @@ -395,7 +394,6 @@ def run_discord_token_cleanup(): logger.debug("DiscordAuthToken failed validation. Deleting %s" % auth) auth.delete() -@shared_task def refresh_api(api_key_pair): logger.debug("Running update on api key %s" % api_key_pair.api_id) user = api_key_pair.user @@ -444,32 +442,32 @@ def refresh_api(api_key_pair): elif full == False: logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user)) still_valid = False - if still_valid == None: - if api_key_pair.error_count >= 3: - logger.info("API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id) - still_valid = False - if still_valid == False: - logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id) - EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) - EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) - elif still_valid == True: - if api_key_pair.error_count != 0: - logger.info("Clearing error count for api %s as it passed validation" % api_key_pair.api_id) - api_key_pair.error_count = 0 - api_key_pair.save() - logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id) - # Update characters - characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key) - EveManager.update_characters_from_list(characters) - new_character = False - for char in characters.result: - # Ensure we have a model for all characters on key - if not EveManager.check_if_character_exist(characters.result[char]['name']): - new_character = True - logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name'])) - if new_character: - logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id)) - EveManager.create_characters_from_list(characters, user, api_key_pair.api_key) + if still_valid == None: + if api_key_pair.error_count >= 3: + logger.info("API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id) + still_valid = False + if still_valid == False: + logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id) + EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) + EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) + elif still_valid == True: + if api_key_pair.error_count != 0: + logger.info("Clearing error count for api %s as it passed validation" % api_key_pair.api_id) + api_key_pair.error_count = 0 + api_key_pair.save() + logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id) + # Update characters + characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key) + EveManager.update_characters_from_list(characters) + new_character = False + for char in characters.result: + # Ensure we have a model for all characters on key + if not EveManager.check_if_character_exist(characters.result[char]['name']): + new_character = True + logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name'])) + if new_character: + logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id)) + EveManager.create_characters_from_list(characters, user, api_key_pair.api_key) else: logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api_key_pair.api_id) EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) diff --git a/eveonline/views.py b/eveonline/views.py index 0421ddb0..ff7bf6c1 100755 --- a/eveonline/views.py +++ b/eveonline/views.py @@ -163,7 +163,7 @@ def corp_stats_view(request): return render_to_response('registered/corpstats.html', None, context_instance=RequestContext(request)) @login_required -def user_refresh_api(request, api_id) +def user_refresh_api(request, api_id): logger.debug("user_refresh_api called by user %s for api id %s" % (request.user, api_id)) if EveApiKeyPair.objects.filter(api_id=api_id).exists(): api_key_pair = EveApiKeyPair.objects.get(api_id=api_id)