Corrections

This commit is contained in:
Adarnof 2016-02-07 17:28:16 +00:00
parent 2d2afa79eb
commit 2bf133ceee
2 changed files with 28 additions and 30 deletions

View File

@ -1,6 +1,5 @@
from django.conf import settings from django.conf import settings
from celery.task import periodic_task 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 User
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
@ -248,7 +247,7 @@ def remove_from_databases(user, groups, syncgroups):
def assign_corp_group(auth): def assign_corp_group(auth):
corp_group = None corp_group = None
if auth.main_character_id: if auth.main_char_id:
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): if EveCharacter.objects.filter(character_id=auth.main_char_id).exists():
char = EveCharacter.objects.get(character_id=auth.main_char_id) char = EveCharacter.objects.get(character_id=auth.main_char_id)
corpname = generate_corp_group_name(char.corporation_name) 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) logger.debug("DiscordAuthToken failed validation. Deleting %s" % auth)
auth.delete() auth.delete()
@shared_task
def refresh_api(api_key_pair): def refresh_api(api_key_pair):
logger.debug("Running update on api key %s" % api_key_pair.api_id) logger.debug("Running update on api key %s" % api_key_pair.api_id)
user = api_key_pair.user user = api_key_pair.user
@ -444,32 +442,32 @@ def refresh_api(api_key_pair):
elif full == False: 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)) 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 still_valid = False
if still_valid == None: if still_valid == None:
if api_key_pair.error_count >= 3: 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) logger.info("API key %s has incurred 3 or more errors. Assuming invalid." % api_key_pair.api_id)
still_valid = False still_valid = False
if 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) 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_characters_by_api_id(api_key_pair.api_id, user.id)
EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
elif still_valid == True: elif still_valid == True:
if api_key_pair.error_count != 0: if api_key_pair.error_count != 0:
logger.info("Clearing error count for api %s as it passed validation" % api_key_pair.api_id) 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.error_count = 0
api_key_pair.save() api_key_pair.save()
logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id) logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
# Update characters # Update characters
characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key) characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key)
EveManager.update_characters_from_list(characters) EveManager.update_characters_from_list(characters)
new_character = False new_character = False
for char in characters.result: for char in characters.result:
# Ensure we have a model for all characters on key # Ensure we have a model for all characters on key
if not EveManager.check_if_character_exist(characters.result[char]['name']): if not EveManager.check_if_character_exist(characters.result[char]['name']):
new_character = True 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'])) 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: if new_character:
logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id)) 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) EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
else: else:
logger.debug("API key %s is no longer valid; it and its characters will be deleted." % api_key_pair.api_id) 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) EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)

View File

@ -163,7 +163,7 @@ def corp_stats_view(request):
return render_to_response('registered/corpstats.html', None, context_instance=RequestContext(request)) return render_to_response('registered/corpstats.html', None, context_instance=RequestContext(request))
@login_required @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)) 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(): if EveApiKeyPair.objects.filter(api_id=api_id).exists():
api_key_pair = EveApiKeyPair.objects.get(api_id=api_id) api_key_pair = EveApiKeyPair.objects.get(api_id=api_id)