Exemplo n.º 1
0
def addDataElementsToDSS(request, dss_id):
    dss = get_object_or_404(models.DataSetSpecification, id=dss_id)
    if not user_can_edit(request.user, dss):
        raise PermissionDenied
    qs = aristotle_models.DataElement.objects.filter().visible(request.user)
    if request.method == 'POST':
        form = forms.AddDataElementsToDSSForm(request.POST,
                                              user=request.user,
                                              qs=qs,
                                              dss=dss)
        if form.is_valid():
            inclusion = form.cleaned_data['inclusion']
            maxOccurs = form.cleaned_data['maximum_occurrences']
            with reversion.revisions.create_revision():
                for de in form.cleaned_data['dataElements']:
                    dss.addDataElement(data_element=de,
                                       maximum_occurrences=maxOccurs,
                                       inclusion=inclusion)
                dss.save()
                reversion.set_comment('Added data elements')
            return HttpResponseRedirect(
                reverse("aristotle_mdr:item", args=[dss.id]))
    else:
        form = forms.AddDataElementsToDSSForm(user=request.user,
                                              qs=qs,
                                              dss=dss)

    return render(request, "aristotle_dse/actions/addDataElementsToDSS.html", {
        "item": dss,
        "form": form,
    })
def addDataElementsToDSS(request, dss_id):
    dss = get_object_or_404(aristotle_dse.models.DataSetSpecification,
                            id=dss_id)
    if not user_can_edit(request.user, dss):
        raise PermissionDenied
    qs = aristotle.models.DataElement.objects.filter().visible(request.user)
    if request.method == 'POST':
        form = forms.AddDataElementsToDSSForm(request.POST,
                                              user=request.user,
                                              qs=qs,
                                              dss=dss)
        if form.is_valid():
            cardinality = form.cleaned_data['cardinality']
            maxOccurs = form.cleaned_data['maximum_occurances']
            for de in form.cleaned_data['dataElements']:
                dss.addDataElement(data_element=de,
                                   maximum_occurances=maxOccurs,
                                   cardinality=cardinality)
            return HttpResponseRedirect(
                reverse("aristotle_mdr:item", args=[dss.id]))
    else:
        form = forms.AddDataElementsToDSSForm(user=request.user,
                                              qs=qs,
                                              dss=dss)

    return render(request, "aristotle_dse/actions/addDataElementsToDSS.html", {
        "item": dss,
        "form": form,
    })