示例#1
0
def multiple_new_hit(request, bid):

    mturk_permission = check_mturk_access(request)

    if mturk_permission == True:
        battery = Battery.objects.get(pk=bid)
        if not request.user.has_perm('battery.edit_battery', battery):
            return HttpResponseForbidden()

        is_owner = battery.owner == request.user

        if request.method == "POST":
            # A hit is generated for each batch
            for x in range(int(request.POST["id_number_batches"])):
                hit = HIT(owner=request.user,battery=battery)
                form = HITForm(request.POST,instance=hit)
                if form.is_valid():
                    hit = form.save(commit=False)
                    hit.title = "%s #%s" %(hit.title,x)
                    hit.save()
            return HttpResponseRedirect(battery.get_absolute_url())
        else:

            context = {"is_owner": is_owner,
                      "header_text":battery.name,
                      "battery":battery,
                      "mturk_permission":mturk_permission}

        return render(request, "turk/multiple_new_hit.html", context)
    else:
        return HttpResponseForbidden()
示例#2
0
def edit_hit(request, bid, hid=None):

    mturk_permission = check_mturk_access(request)

    if mturk_permission:
        battery = Battery.objects.get(pk=bid)
        header_text = "%s HIT" % (battery.name)
        if not request.user.has_perm('battery.edit_battery', battery):
            return HttpResponseForbidden()

        if hid:
            hit = get_hit(hid, request)
            is_owner = battery.owner == request.user
            header_text = hit.title
        else:
            is_owner = True
            hit = HIT(owner=request.user, battery=battery)
        if request.method == "POST":
            if is_owner:
                form = HITForm(request.POST, instance=hit)
            if form.is_valid():
                hit = form.save(commit=False)
                hit.save()
                return HttpResponseRedirect(battery.get_absolute_url())
        else:
            if is_owner:
                form = HITForm(instance=hit)
            else:
                form = HITForm(instance=hit)

        context = {
            "form": form,
            "is_owner": is_owner,
            "header_text": header_text
        }

        return render(request, "turk/new_hit.html", context)
    else:
        return HttpResponseForbidden()
示例#3
0
def edit_hit(request, bid, hid=None):

    mturk_permission = check_mturk_access(request)

    if mturk_permission == True:
        battery = Battery.objects.get(pk=bid)
        header_text = "%s HIT" %(battery.name)
        if not request.user.has_perm('battery.edit_battery', battery):
            return HttpResponseForbidden()

        if hid:
            hit = get_hit(hid,request)
            is_owner = battery.owner == request.user
            header_text = hit.title
        else:
            is_owner = True
            hit = HIT(owner=request.user,battery=battery)
        if request.method == "POST":
            if is_owner:
                form = HITForm(request.POST,instance=hit)
            if form.is_valid():
                hit = form.save(commit=False)
                hit.save()
                return HttpResponseRedirect(battery.get_absolute_url())
        else:
            if is_owner:
                form = HITForm(instance=hit)
            else:
                form = HITForm(instance=hit)

        context = {"form": form,
                   "is_owner": is_owner,
                   "header_text":header_text}

        return render(request, "turk/new_hit.html", context)
    else:
        return HttpResponseForbidden()