def post(self, request, *args, **kwargs):
        form = self.get_form()
        slot_formset = None

        if form.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                item = form.save(commit=False)

                has_change_comments = form.data.get('change_comments', False)
                change_comments = form.data.get('change_comments', "")
                if self.slots_active:
                    slot_formset = self.get_slots_formset()(request.POST,
                                                            request.FILES,
                                                            item.concept)
                    if slot_formset.is_valid():

                        # Save the slots
                        slot_formset.save()

                        # Save the change comments
                        if not has_change_comments:
                            change_comments += construct_change_message(
                                request, form, [slot_formset])
                    else:
                        return self.form_invalid(form,
                                                 slots_FormSet=slot_formset)

                if self.identifiers_active:
                    id_formset = self.get_identifier_formset()(request.POST,
                                                               request.FILES,
                                                               item.concept)
                    if id_formset.is_valid():

                        # Save the slots
                        id_formset.save()

                        if not has_change_comments:
                            change_comments += construct_change_message(
                                request, form, [id_formset])
                    else:
                        return self.form_invalid(form,
                                                 identifier_FormSet=id_formset)

                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(change_comments)
                form.save_m2m()
                item.save()
                return HttpResponseRedirect(url_slugify_concept(self.item))

        return self.form_invalid(form)
예제 #2
0
    def post(self, request, *args, **kwargs):
        form = self.get_form()
        slot_formset = None

        if form.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                item = form.save(commit=False)
                slot_formset = self.get_slots_formset()(request.POST, request.FILES, item.concept)

                if slot_formset.is_valid():

                    # Save the slots
                    slot_formset.save()

                    # Save the change comments
                    reversion.revisions.set_user(request.user)
                    change_comments = form.data.get('change_comments', None)
                    if not change_comments:
                        change_comments = construct_change_message(request, form, [slot_formset])
                    reversion.revisions.set_comment(change_comments)

                    item.save()
                    return HttpResponseRedirect(url_slugify_concept(self.item))

        return self.form_invalid(form, slot_formset)
예제 #3
0
def edit_item(request, iid, *args, **kwargs):
    item = get_object_or_404(MDR._concept, pk=iid).item
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous():
            return redirect(reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied

    base_form = MDRForms.wizards.subclassed_edit_modelform(item.__class__)
    if request.method == 'POST':  # If the form has been submitted...
        form = base_form(request.POST, instance=item, user=request.user)
        new_wg = request.POST.get('workgroup', None)
        workgroup_changed = not(str(item.workgroup.pk) == (new_wg))

        if form.is_valid():
            workgroup_changed = item.workgroup.pk != form.cleaned_data['workgroup'].pk

            with transaction.atomic(), reversion.revisions.create_revision():
                change_comments = form.data.get('change_comments', None)
                item = form.save()
                reversion.revisions.set_user(request.user)
                if not change_comments:
                    change_comments = construct_change_message(request, form, None)
                reversion.revisions.set_comment(change_comments)
                return HttpResponseRedirect(url_slugify_concept(item))
    else:
        form = base_form(instance=item, user=request.user)
    return render(request, "aristotle_mdr/actions/advanced_editor.html", {"item": item, "form": form})
예제 #4
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST requests, instantiating a form instance with the passed
        POST variables and then checked for validity.
        """
        form = self.get_form()
        GenericFormSet = self.get_formset()
        self.formset = GenericFormSet(self.request.POST, self.request.FILES)
        formset = self.formset
        if formset.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                self.item.save(
                )  # do this to ensure we are saving reversion records for the value domain, not just the values
                formset.save(commit=False)
                for form in formset.forms:
                    if form['id'].value() not in [
                            deleted_record['id'].value()
                            for deleted_record in formset.deleted_forms
                    ]:
                        # Don't immediately save, we need to attach the parent object
                        value = form.save(commit=False)
                        setattr(value, self.model_to_add_field, self.item)
                        value.save()
                for obj in formset.deleted_objects:
                    obj.delete()
                # formset.save(commit=True)
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(
                    construct_change_message(request, None, [formset]))

            return HttpResponseRedirect(self.get_success_url())
        else:
            return self.form_invalid(form)
예제 #5
0
def edit_item(request,iid,*args,**kwargs):
    item = get_object_or_404(MDR._concept,pk=iid).item
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous():
            return redirect(reverse('django.contrib.auth.views.login')+'?next=%s' % request.path)
        else:
            raise PermissionDenied

    base_form = MDRForms.wizards.subclassed_edit_modelform(item.__class__)
    if request.method == 'POST': # If the form has been submitted...
        form = base_form(request.POST,instance=item,user=request.user)

        if form.is_valid():
            with transaction.atomic(), reversion.create_revision():
                change_comments = form.data.get('change_comments',None)
                item = form.save()
                reversion.set_user(request.user)
                if not change_comments:
                    change_comments = construct_change_message(request,form,None)
                reversion.set_comment(change_comments)
                return HttpResponseRedirect(url_slugify_concept(item))
    else:
        form = base_form(instance=item,user=request.user)
    return render(request,"aristotle_mdr/actions/advanced_editor.html",
            {"item":item,
             "form":form,
                }
            )
def editInclusionOrder(request, dss_id, inc_type):
    if inc_type not in ['cluster', 'data_element']:
        raise Http404
    item = get_object_or_404(aristotle_dse.models.DataSetSpecification, pk=dss_id)
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous():
            return redirect(reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied

    item_type, field_name = {
        'cluster': (aristotle_dse.models.DSSClusterInclusion, 'child'),
        'data_element': (aristotle_dse.models.DSSDEInclusion, 'data_element'),
        }.get(inc_type)

    num_values = item_type.objects.filter(dss=item.id).count()
    if num_values > 0:
        extra = 0
    else:
        extra = 1

    ValuesFormSet = modelformset_factory(
        item_type,
        formset=HiddenOrderModelFormSet,
        can_order=True,
        fields=('id',),
        extra=extra
    )

    if request.method == 'POST':
        formset = ValuesFormSet(request.POST, request.FILES)
        if formset.is_valid():
            with transaction.atomic(), reversion.create_revision():
                item.save()  # do this to ensure we are saving reversion records for the DSS, not just the values
                formset.save(commit=False)
                for form in formset.forms:
                    if form['id'].value() not in [deleted_record['id'].value() for deleted_record in formset.deleted_forms]:
                        inc = item_type.objects.get(pk=form['id'].value())
                        if inc.dss != item:
                            raise PermissionDenied
                        inc.order = form['ORDER'].value()
                        # inc.maximum_occurances = form['maximum_occurances'].value()
                        # value = form.save(commit=False) #Don't immediately save, we need to attach the value domain
                        # value.dss = item
                        inc.save()
                for obj in formset.deleted_objects:
                    obj.delete()
                reversion.set_user(request.user)
                reversion.set_comment(construct_change_message(request, None, [formset, ]))

                return redirect(reverse("aristotle_mdr:item", args=[item.id]))
    else:
        formset = ValuesFormSet(
            queryset=item_type.objects.filter(dss=item.id),
        )
    return render(
        request,
        "aristotle_dse/actions/edit_inclusion_order.html",
        {'item': item, 'formset': formset, 'include_type': inc_type, 'value_model': item_type, }
    )
예제 #7
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST requests, instantiating a form instance with the passed
        POST variables and then checked for validity.
        """
        form = self.get_form()
        GenericFormSet = self.get_formset()
        self.formset = GenericFormSet(self.request.POST, self.request.FILES)
        formset = self.formset
        if formset.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                self.item.save()  # do this to ensure we are saving reversion records for the value domain, not just the values
                formset.save(commit=False)
                for form in formset.forms:
                    all_blank = not any(form[f].value() for f in form.fields if f is not self.ordering_field)
                    if all_blank:
                        continue
                    if form["id"].value() not in [
                        deleted_record["id"].value() for deleted_record in formset.deleted_forms
                    ]:
                        # Don't immediately save, we need to attach the parent object
                        value = form.save(commit=False)
                        setattr(value, self.model_to_add_field, self.item)
                        if self.ordering_field:
                            setattr(value, self.ordering_field, form.cleaned_data["ORDER"])
                        value.save()
                for obj in formset.deleted_objects:
                    obj.delete()
                # formset.save(commit=True)
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(construct_change_message(request, None, [formset]))

            return HttpResponseRedirect(self.get_success_url())
        else:
            return self.form_invalid(form)
    def post(self, request, *args, **kwargs):
        form = self.get_form()
        slot_formset = None

        if form.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                item = form.save(commit=False)
                slot_formset = self.get_slots_formset()(request.POST,
                                                        request.FILES,
                                                        item.concept)

                if slot_formset.is_valid():

                    # Save the slots
                    slot_formset.save()

                    # Save the change comments
                    reversion.revisions.set_user(request.user)
                    change_comments = form.data.get('change_comments', None)
                    if not change_comments:
                        change_comments = construct_change_message(
                            request, form, [slot_formset])
                    reversion.revisions.set_comment(change_comments)

                    item.save()
                    return HttpResponseRedirect(url_slugify_concept(self.item))

        return self.form_invalid(form, slot_formset)
예제 #9
0
def valuedomain_value_edit(request, iid, value_type):
    item = get_object_or_404(MDR.ValueDomain, pk=iid).item
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous():
            return redirect(reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied
    value_model = {
        'permissible': MDR.PermissibleValue,
        'supplementary': MDR.SupplementaryValue
    }.get(value_type, None)
    if not value_model:
        raise Http404

    num_values = value_model.objects.filter(valueDomain=item.id).count()
    if num_values > 0:
        extra = 0
    else:
        extra = 1
    ValuesFormSet = modelformset_factory(
        value_model,
        can_delete=True,  # dont need can_order is we have an order field
        fields=('order', 'value', 'meaning'),
        extra=extra
        )
    if request.method == 'POST':
        formset = ValuesFormSet(request.POST, request.FILES)
        if formset.is_valid():
                with transaction.atomic(), reversion.revisions.create_revision():
                    item.save()  # do this to ensure we are saving reversion records for the value domain, not just the values
                    formset.save(commit=False)
                    for form in formset.forms:
                        if form['value'].value() == '' and form['meaning'].value() == '':
                            continue  # Skip over completely blank entries.
                        if form['id'].value() not in [deleted_record['id'].value() for deleted_record in formset.deleted_forms]:
                            value = form.save(commit=False)  # Don't immediately save, we need to attach the value domain
                            value.valueDomain = item
                            value.save()
                    for obj in formset.deleted_objects:
                        obj.delete()
                    # formset.save(commit=True)
                    reversion.revisions.set_user(request.user)
                    reversion.revisions.set_comment(construct_change_message(request, None, [formset]))

                return redirect(reverse("aristotle_mdr:item", args=[item.id]))
    else:
        formset = ValuesFormSet(
            queryset=value_model.objects.filter(valueDomain=item.id),
            initial=[{'order': num_values, 'value': '', 'meaning': ''}]
            )
    return render(
        request,
        "aristotle_mdr/actions/edit_value_domain_values.html",
        {'item': item, 'formset': formset, 'value_type': value_type, 'value_model': value_model}
    )
예제 #10
0
def valuedomain_value_edit(request, iid, value_type):
    item = get_object_or_404(MDR.ValueDomain, pk=iid).item
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous():
            return redirect(reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied
    value_model = {
        'permissible': MDR.PermissibleValue,
        'supplementary': MDR.SupplementaryValue
    }.get(value_type, None)
    if not value_model:
        raise Http404

    num_values = value_model.objects.filter(valueDomain=item.id).count()
    if num_values > 0:
        extra = 0
    else:
        extra = 1
    ValuesFormSet = modelformset_factory(
        value_model,
        can_delete=True,  # dont need can_order is we have an order field
        fields=('order', 'value', 'meaning'),
        extra=extra
        )
    if request.method == 'POST':
        formset = ValuesFormSet(request.POST, request.FILES)
        if formset.is_valid():
                with transaction.atomic(), reversion.revisions.create_revision():
                    item.save()  # do this to ensure we are saving reversion records for the value domain, not just the values
                    formset.save(commit=False)
                    for form in formset.forms:
                        if form['value'].value() == '' and form['meaning'].value() == '':
                            continue  # Skip over completely blank entries.
                        if form['id'].value() not in [deleted_record['id'].value() for deleted_record in formset.deleted_forms]:
                            value = form.save(commit=False)  # Don't immediately save, we need to attach the value domain
                            value.valueDomain = item
                            value.save()
                    for obj in formset.deleted_objects:
                        obj.delete()
                    # formset.save(commit=True)
                    reversion.revisions.set_user(request.user)
                    reversion.revisions.set_comment(construct_change_message(request, None, [formset]))

                return redirect(reverse("aristotle_mdr:item", args=[item.id]))
    else:
        formset = ValuesFormSet(
            queryset=value_model.objects.filter(valueDomain=item.id),
            initial=[{'order': num_values, 'value': '', 'meaning': ''}]
            )
    return render(
        request,
        "aristotle_mdr/actions/edit_value_domain_values.html",
        {'item': item, 'formset': formset, 'value_type': value_type, 'value_model': value_model}
    )
예제 #11
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST requests, instantiating a form instance with the passed
        POST variables and then checked for validity.
        """
        form = self.get_form()
        self.formset = self.get_formset(
            self.request.POST, self.request.FILES,
        )
        if self.formset.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                self.item.save()
                self.formset.save()
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(construct_change_message(request, None, [self.formset]))

            return HttpResponseRedirect(self.get_success_url())
        else:
            return self.form_invalid(form)
예제 #12
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST requests, instantiating a form instance with the passed
        POST variables and then checked for validity.
        """
        form = self.get_form()
        GenericFormSet = self.get_formset()
        self.formset = GenericFormSet(self.request.POST, self.request.FILES)
        formset = self.formset
        if formset.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                ordered_formset_save(formset, self.item, self.model_to_add_field, self.ordering_field)

                # formset.save(commit=True)
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(construct_change_message(request, None, [formset]))

            return HttpResponseRedirect(self.get_success_url())
        else:
            return self.form_invalid(form)
    def post(self, request, *args, **kwargs):
        form = self.get_form()
        slot_formset = None

        new_wg = request.POST.get('workgroup', None)
        old_wg = None
        old_wg_pk = None
        if self.item.workgroup:
            old_wg = self.item.workgroup
            old_wg_pk = str(self.item.workgroup.pk)
        workgroup_changed = not (old_wg_pk == new_wg)

        if form.is_valid():
            workgroup_changed = old_wg != form.cleaned_data['workgroup']

            with transaction.atomic(), reversion.revisions.create_revision():
                item = form.save(commit=False)
                slot_formset = self.get_slots_formset()(request.POST,
                                                        request.FILES,
                                                        item.concept)

                if slot_formset.is_valid():

                    # Save the slots
                    slot_formset.save()

                    # Save the change comments
                    reversion.revisions.set_user(request.user)
                    change_comments = form.data.get('change_comments', None)
                    if not change_comments:
                        change_comments = construct_change_message(
                            request, form, [slot_formset])
                    reversion.revisions.set_comment(change_comments)

                    item.save()
                    return HttpResponseRedirect(url_slugify_concept(self.item))

        return self.form_invalid(form, slot_formset)
예제 #14
0
def editInclusionOrder(request, dss_id, inc_type):
    if inc_type not in ['cluster', 'data_element']:
        raise Http404
    item = get_object_or_404(models.DataSetSpecification, pk=dss_id)
    if not user_can_edit(request.user, item):
        if request.user.is_anonymous:
            return redirect(
                reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied

    item_type, field_name = {
        'cluster': (models.DSSClusterInclusion, 'child'),
        'data_element': (models.DSSDEInclusion, 'data_element'),
    }.get(inc_type)

    num_values = item_type.objects.filter(dss=item.id).count()
    if num_values > 0:
        extra = 0
    else:
        extra = 1

    values_formset = modelformset_factory(item_type,
                                          formset=HiddenOrderModelFormSet,
                                          can_order=True,
                                          fields=('id', ),
                                          extra=extra)

    if request.method == 'POST':
        formset = values_formset(request.POST, request.FILES)
        if formset.is_valid():
            with transaction.atomic(), reversion.create_revision():
                item.save(
                )  # do this to ensure we are saving reversion records for the DSS, not just the values
                formset.save(commit=False)
                for form in formset.forms:
                    if form['id'].value() not in [
                            deleted_record['id'].value()
                            for deleted_record in formset.deleted_forms
                    ]:
                        inc = item_type.objects.get(pk=form['id'].value())
                        if inc.dss != item:
                            raise PermissionDenied
                        inc.order = form['ORDER'].value()
                        # inc.maximum_occurrences = form['maximum_occurrences'].value()
                        # value = form.save(commit=False) #Don't immediately save, we need to attach the value domain
                        # value.dss = item
                        inc.save()
                for obj in formset.deleted_objects:
                    obj.delete()
                reversion.set_user(request.user)
                reversion.set_comment(
                    construct_change_message(None, [
                        formset,
                    ]))

                return redirect(reverse("aristotle_mdr:item", args=[item.id]))
    else:
        formset = values_formset(
            queryset=item_type.objects.filter(dss=item.id), )
    return render(
        request, "aristotle_dse/actions/edit_inclusion_order.html", {
            'item': item,
            'formset': formset,
            'include_type': inc_type,
            'value_model': item_type,
        })