Esempio n. 1
0
    def create(kls, request):
        username, api_key = (request.POST.get("username", None), 
                             request.POST.get("api_key", None))
        if None in (username, api_key):
            return rc.BAD_REQUEST

        user = UserProfile.find(username)
        if user:
            if user.verified and user.api_key == api_key:
                form = JobSubmitForm(request.POST)
                if not form.is_valid():
                    return rc.BAD_REQUEST
                cd = form.cleaned_data
                func, args, ctx = (cd["func"], 
                                   json.loads(cd["args"]),
                                   json.loads(cd["ctx"]))

                job = {"func": func, "args": args, "ctx": ctx}
                c = get_controller()
              
                job_doc = Job.objects.create(job=job, 
                                             remaining=len(job["args"]),
                                             owner=username,
                                             assigned_to=c.get_name())
                
                redisClient.lpush(c.get_name(), 
                                  json.dumps(
                                    {"job_id": job_doc.job_id,
                                     "job": job}))

                return HttpResponse(json.dumps({"job_id": job_doc.job_id}), 
                                                content_type="application/json")
        return rc.FORBIDDEN
Esempio n. 2
0
    def read(kls, request, job_id=None, spew_all=False):
        username, api_key = (request.GET.get("username", None), 
                             request.GET.get("api_key", None))
        if None in (username, api_key):
            return rc.BAD_REQUEST

        user = UserProfile.find(username)
        if user:
            if user.verified and user.api_key == api_key:
                if spew_all:
                    ret = map(Job.get_restricted, Job.objects.filter(owner=username))
                else:
                    if job_id:
                        ret = Job.objects.get(job_id=job_id).get_restricted()
                return HttpResponse(json.dumps(ret), content_type="application/json")
        return rc.FORBIDDEN