コード例 #1
0
ファイル: views.py プロジェクト: rwblair/expfactory-docker
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
ファイル: views.py プロジェクト: expfactory/expfactory-docker
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()
コード例 #3
0
def clone_hit(request, bid, hid):
    mturk_permission = check_mturk_access(request)
    if not mturk_permission:
        return HttpResponseForbidden()

    new_hit = get_object_or_404(HIT, pk=hid)
    new_hit.pk = None
    form = HITForm(instance=new_hit)
    form.helper.form_action = reverse('new_hit', args=[bid])

    battery = Battery.objects.get(pk=bid)
    header_text = "%s HIT" % (battery.name)

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

    return render(request, "turk/new_hit.html", context)
コード例 #4
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()