Allow eveapi_refresh to be called via XHR and return a JSON representation of the key

This commit is contained in:
2010-10-29 11:03:08 +01:00
parent c28d72f0ad
commit d66f3b4a9f

View File

@@ -3,12 +3,13 @@ import random
import re import re
import unicodedata import unicodedata
from django.http import HttpResponseRedirect, Http404 from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.template import RequestContext from django.template import RequestContext
from django.core import serializers
from eve_api.api_exceptions import APIAuthException, APINoUserIDException from eve_api.api_exceptions import APIAuthException, APINoUserIDException
from eve_api.api_puller.accounts import import_eve_account from eve_api.api_puller.accounts import import_eve_account
@@ -96,6 +97,7 @@ def eveapi_del(request, userid=0):
@login_required @login_required
def eveapi_refresh(request, userid=0): def eveapi_refresh(request, userid=0):
if userid > 0 : if userid > 0 :
try: try:
acc = EVEAccount.objects.get(id=userid) acc = EVEAccount.objects.get(id=userid)
@@ -104,6 +106,12 @@ def eveapi_refresh(request, userid=0):
else: else:
import_eve_account(acc.api_key, acc.api_user_id, force_cache=True) import_eve_account(acc.api_key, acc.api_user_id, force_cache=True)
request.user.get_profile().update_access() request.user.get_profile().update_access()
print request.GET
if request.is_ajax():
acc = EVEAccount.objects.get(id=userid)
return HttpResponse(serializers.serialize('json', [acc]), mimetype='application/javascript')
else:
request.user.message_set.create(message="Key %s has been refreshed from the EVE API." % acc.api_user_id) request.user.message_set.create(message="Key %s has been refreshed from the EVE API." % acc.api_user_id)
return HttpResponseRedirect(reverse('sso.views.profile')) return HttpResponseRedirect(reverse('sso.views.profile'))