# -*- coding: utf-8 -*-
"""
Created on Apr 19, 2016

@author: noob
"""

from common.models import UploadToken
from django.http import HttpResponseBadRequest
from api.views.base import ApiJob


class CheckUploadToken(ApiJob):
    def get(self, request, job):
        try:
            upload_token = request.GET.get('upload_token', '')
            assert upload_token
            UploadToken.objects.get(job=job.n, token=upload_token)
            return True
        except AssertionError:
            return HttpResponseBadRequest()
        except UploadToken.DoesNotExist:
            return False
