Example #1
0
def eveapi_add(request, post_save_redirect='/', template='eve_api/add.html'):
    """ Add a EVE API key to a user's account """

    if request.method == 'POST':
        form = EveAPIForm(request.POST)
        if form.is_valid():
            task = import_apikey_result.delay(api_key=form.cleaned_data['api_key'], api_userid=form.cleaned_data['api_user_id'], user=request.user.id)
            try:
                out = task.wait(10)
            except celery.exceptions.TimeoutError:
                msg = "The addition of your API key is still processing, please check back in a minute or so."
            except DocumentRetrievalError:
                msg = "An issue with the EVE API was encountered while adding your API, please try again later."
            except:
                msg = "An unknown error was encountered while trying to add your API key, please try again later."
            else:
                if out:
                    msg = "Key %d successfully added." % form.cleaned_data['api_user_id']
                else:
                    msg = "An issue was encountered why trying to import key %s, please recheck and try again." % form.cleaned_data['api_user_id']
            messages.success(request, msg, fail_silently=True)
            return redirect(post_save_redirect)
    else:
        form = EveAPIForm(initial={'user': request.user.id }) # An unbound form

    context = {
        'form': form,
    }
    return render_to_response(template, context, context_instance=RequestContext(request))
Example #2
0
 def form_valid(self, form):
     task = import_apikey_result.delay(api_key=form.cleaned_data['api_key'], api_userid=form.cleaned_data['api_user_id'], user=self.request.user.id, retry=False)
     try:
         out = task.wait(10)
     except celery.exceptions.TimeoutError:
         messages.info(self.request, "The addition of your API key is still processing, please check back in a minute or so.")
     except DocumentRetrievalError:
         messages.error(self.request, "An issue with the EVE API was encountered while adding your API, please try again later.")
     except:
         messages.error(self.request, "An unknown error was encountered while trying to add your API key, please try again later.")
     else:
         if out:
             messages.success(self.request, "Key %d successfully added." % form.cleaned_data['api_user_id'])
         else:
             messages.error(self.request, "An issue was encountered while trying to import key %s, Please check that you are using the correct information and try again." % form.cleaned_data['api_user_id'])
     return HttpResponseRedirect(reverse_lazy('sso-profile'))
Example #3
0
 def get(self, request, *args, **kwargs):
     self.object = self.get_object()
     if self.object.user != self.request.user and not request.user.is_superuser:
         return HttpResponseForbidden()
     task = import_apikey_result.delay(api_key=self.object.api_key, api_userid=self.object.api_user_id, force_cache=True, user=self.object.user.id)
     if self.request.is_ajax():
         try:
             acc = task.wait(30)
         except (celery.exceptions.TimeoutError, DocumentRetrievalError):
             acc = EVEAccount.objects.get(pk=self.object.pk)
         ret = []
         if acc:
             ret = [acc]
         return HttpResponse(serializers.serialize('json', ret), mimetype='application/javascript')
     else:
         messages.info(self.request, "Key %s has been queued to be refreshed from the API" % acc.api_user_id)
     return HttpResponseRedirect('/')
Example #4
0
def eveapi_refresh(request, userid, post_save_redirect='/'):
    """ Force refresh a EVE API key """

    acc = get_object_or_404(EVEAccount, pk=userid)
    if acc.user == request.user or request.user.is_superuser:
        task = import_apikey_result.delay(api_key=acc.api_key, api_userid=acc.api_user_id, force_cache=True, user=request.user.id)
        if request.is_ajax():
            try:
                acc = task.wait(30)
            except (celery.exceptions.TimeoutError, DocumentRetrievalError):
                acc = EVEAccount.objects.get(pk=userid)
            ret = []
            if acc:
                ret = [acc]
            return HttpResponse(serializers.serialize('json', ret), mimetype='application/javascript')
        else:
            messages.add_message(request, messages.INFO, "Key %s has been queued to be refreshed from the API" % acc.api_user_id)

    return redirect(post_save_redirect)
Example #5
0
 def form_valid(self, form):
     msg = None
     if form.has_changed() and 'api_key' in form.changed_data:
         print "import"
         task = import_apikey_result.delay(api_key=form.cleaned_data['api_key'], api_userid=form.cleaned_data['api_user_id'], user=form.cleaned_data['user'], retry=False)
         try:
             acc = task.wait(30)
         except celery.exceptions.TimeoutError:
             messages.info(self.request, "The addition of your API key is still processing, please check back in a minute or so.")
         except DocumentRetrievalError:
             messages.error(self.request, "An issue with the EVE API was encountered while adding your API, please try again later.")
         except:
             messages.error(self.request, "An unknown error was encountered while trying to add your API key, please try again later.")
         else:
             if acc:
                 messages.success(self.request, "EVE API key %d successfully updated." % acc.api_user_id)
             else:
                 messages.error(self.request, "An error was encountered while trying to update your API key, Please check your key and try again.", fail_silently=True)
     else:
         if form.has_changed():
             acc = form.save()
             messages.success(self.request, "EVE API key %d successfully updated." % acc.api_user_id)
     return HttpResponseRedirect(self.get_success_url())
Example #6
0
def eveapi_update(request, userid, post_save_redirect='/', template='eve_api/update.html'):
    """ Update a EVE API Key """

    acc = get_object_or_404(EVEAccount, pk=userid)
    if not acc.user == request.user and not request.user.is_staff:
        raise Http404    

    if request.method == 'POST':
        form = EveAPIForm(request.POST, instance=acc)
        if form.is_valid():
            if form.has_changed() and ('api_key' in form.changed_data):
                task = import_apikey_result.delay(api_key=acc.api_key, api_userid=acc.api_user_id, user=request.user.id)
                try:
                    task.wait(30)
                except celery.exceptions.TimeoutError:
                    msg = "The addition of your API key is still processing, please check back in a minute or so."
                except DocumentRetrievalError:
                    msg = "An issue with the EVE API was encountered while adding your API, please try again later."
                except:
                    msg = "An unknown error was encountered while trying to add your API key, please try again later."
                else:
                    msg = "EVE API key %d successfully updated." % acc.api_user_id
            else:
                if form.has_changed():
                    form.save()
                msg = "EVE API key %d successfully updated." % acc.api_user_id

            messages.success(request, msg, fail_silently=True)
            return redirect(post_save_redirect)
    else:
        form = EveAPIForm(instance=acc) # An unbound form

    context = {
        'acc': acc,
        'form': form,
    }
    return render_to_response(template, context, context_instance=RequestContext(request))