Beispiel #1
0
def add_podcast_status(request, job_id):
    url = request.GET.get("url", "")
    result = update_podcasts.AsyncResult(job_id)
    resp = {"id": str(job_id), "type": "create-podcast", "url": url}

    if not result.ready():
        resp["status"] = "pending"
    elif result.successful():
        resp["status"] = "successful"
        resp["podcast"] = f"/api/2/data/podcast.json?url={url}"
    elif result.failed():
        resp["status"] = "unsuccessful"
        resp["error"] = "feed could not be parsed"

    return JsonResponse(resp)
Beispiel #2
0
def add_podcast_status(request, job_id):
    url = request.GET.get('url', '')
    result = update_podcasts.AsyncResult(job_id)
    resp = {'id': str(job_id), 'type': 'create-podcast', 'url': url}

    if not result.ready():
        resp['status'] = 'pending'
    elif result.successful():
        resp['status'] = 'successful'
        resp['podcast'] = f'/api/2/data/podcast.json?url={url}'
    elif result.failed():
        resp['status'] = 'unsuccessful'
        resp['error'] = 'feed could not be parsed'

    return JsonResponse(resp)
Beispiel #3
0
    def get(self, request, task_id):
        result = update_podcasts.AsyncResult(task_id)

        if not result.ready():
            return self.render_to_response({'ready': False})

        try:
            podcast_ids = result.get()
            podcasts = Podcast.objects.filter(pk__in=podcast_ids)
            messages.success(request, _('%d podcasts added' % len(podcasts)))

        except (UpdatePodcastException, NoEpisodesException) as ex:
            messages.error(request, str(ex))
            podcast = None

        return self.render_to_response({'ready': True, 'podcasts': podcasts})