def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone",None)
        name_suggest_fields = kwargs.pop('name_suggest_fields',[])
        separator = kwargs.pop('separator','-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super(AdminConceptForm, self).__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__
            self.fields['deprecated'] = forms.ModelMultipleChoiceField(
                    required=False,
                    label="Supersedes",
                    queryset=self.itemtype.objects.all(),
                )
            if self.instance.get_autocomplete_name() in autocomplete_light.registry.keys():
                # if there is an autocomplete for this item, then replace it
                # TODO: when autocomplete respects queryset these can be done automatically
                self.fields['deprecated'].widget = autocomplete_light.MultipleChoiceWidget(self.instance.get_autocomplete_name())
            self.fields['deprecated'].initial = self.instance.supersedes.all()

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(name_suggest_fields=name_suggest_fields,separator=separator)
        self.fields['workgroup'].queryset = self.request.user.profile.editable_workgroups.all()
        self.fields['workgroup'].initial = self.request.user.profile.activeWorkgroup
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone", None)
        name_suggest_fields = kwargs.pop('name_suggest_fields', [])
        separator = kwargs.pop('separator', '-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super(AdminConceptForm, self).__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__
            self.fields['deprecated'] = forms.ModelMultipleChoiceField(
                required=False,
                label="Supersedes",
                queryset=self.itemtype.objects.all(),
                widget=ConceptAutocompleteSelectMultiple(
                    model=self._meta.model))
            self.fields['deprecated'].initial = self.instance.supersedes.all()

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(
                name_suggest_fields=name_suggest_fields, separator=separator)
        self.fields[
            'workgroup'].queryset = self.request.user.profile.editable_workgroups.all(
            )
Ejemplo n.º 3
0
 def get_form_kwargs(self):
     kwargs = super().get_form_kwargs()
     kwargs.update({
         'user': self.request.user,
         'initial': concept_to_clone_dict(self.item)
     })
     return kwargs
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone", None)
        name_suggest_fields = kwargs.pop('name_suggest_fields', [])
        separator = kwargs.pop('separator', '-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super(AdminConceptForm, self).__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__
            self.fields['deprecated'] = forms.ModelMultipleChoiceField(
                required=False,
                label="Supersedes",
                queryset=self.itemtype.objects.all(),
            )
            if self.instance.get_autocomplete_name(
            ) in autocomplete_light.registry.keys():
                # if there is an autocomplete for this item, then replace it
                # TODO: when autocomplete respects queryset these can be done automatically
                self.fields[
                    'deprecated'].widget = autocomplete_light.MultipleChoiceWidget(
                        self.instance.get_autocomplete_name())
            self.fields['deprecated'].initial = self.instance.supersedes.all()

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(
                name_suggest_fields=name_suggest_fields, separator=separator)
        self.fields[
            'workgroup'].queryset = self.request.user.profile.editable_workgroups.all(
            )
Ejemplo n.º 5
0
def clone_item(request, iid, *args, **kwargs):
    item_to_clone = get_object_or_404(MDR._concept, pk=iid).item
    if not user_can_edit(request.user, item_to_clone):
        if request.user.is_anonymous():
            return redirect(
                reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied
    base_form = MDRForms.wizards.subclassed_modelform(item_to_clone.__class__)
    if request.method == 'POST':  # If the form has been submitted...
        form = base_form(request.POST, user=request.user)

        if form.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                new_clone = form.save()
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment(
                    "Cloned from %s (id: %s)" %
                    (item_to_clone.name, str(item_to_clone.pk)))
                return HttpResponseRedirect(url_slugify_concept(new_clone))
    else:
        form = base_form(initial=concept_to_clone_dict(item_to_clone),
                         user=request.user)
    return render(request, "aristotle_mdr/create/clone_item.html", {
        "item": item_to_clone,
        "form": form
    })
    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        initial = concept_to_clone_dict(self.item)

        from aristotle_mdr.contrib.custom_fields.models import CustomValue
        for custom_val in CustomValue.objects.get_item_allowed(
                self.item, self.request.user):
            initial[custom_val.field.form_field_name] = custom_val.content

        kwargs.update({'initial': initial})
        return kwargs
Ejemplo n.º 7
0
    def test_clone(self):
        from aristotle_mdr.utils import concept_to_clone_dict

        # Does cloning an item prepopulate everythin?
        self.login_editor()
        oc = models.ObjectClass.objects.create(name="OC1",workgroup=self.wg1)
        prop = models.Property.objects.create(name="Prop1",workgroup=self.wg1)
        dec = models.DataElementConcept.objects.create(name="DEC1",objectClass=oc,property=prop,workgroup=self.wg1)

        response = self.client.get(reverse("admin:aristotle_mdr_dataelementconcept_add")+"?clone=%s"%dec.id)
        self.assertResponseStatusCodeEqual(response,200)
        self.assertEqual(response.context['adminform'].form.initial,concept_to_clone_dict(dec))
    def test_clone(self):
        from aristotle_mdr.utils import concept_to_clone_dict

        # Does cloning an item prepopulate everythin?
        self.login_editor()
        oc = models.ObjectClass.objects.create(name="OC1",workgroup=self.wg1)
        prop = models.Property.objects.create(name="Prop1",workgroup=self.wg1)
        dec = models.DataElementConcept.objects.create(name="DEC1",objectClass=oc,property=prop,workgroup=self.wg1)

        response = self.client.get(reverse("admin:aristotle_mdr_dataelementconcept_add")+"?clone=%s"%dec.id)
        self.assertResponseStatusCodeEqual(response,200)
        self.assertEqual(response.context['adminform'].form.initial,concept_to_clone_dict(dec))
    def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone", None)
        name_suggest_fields = kwargs.pop('name_suggest_fields', [])
        separator = kwargs.pop('separator', '-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super().__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(name_suggest_fields=name_suggest_fields, separator=separator)
        self.fields['workgroup'].queryset = self.request.user.profile.editable_workgroups.all()
    def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone", None)
        name_suggest_fields = kwargs.pop('name_suggest_fields', [])
        separator = kwargs.pop('separator', '-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super().__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(name_suggest_fields=name_suggest_fields, separator=separator)
        self.fields['workgroup'].queryset = self.request.user.profile.editable_workgroups.all()
def clone_item(request, iid, *args, **kwargs):
    item_to_clone = get_object_or_404(MDR._concept, pk=iid).item
    if not user_can_edit(request.user, item_to_clone):
        if request.user.is_anonymous():
            return redirect(reverse('friendly_login') + '?next=%s' % request.path)
        else:
            raise PermissionDenied
    base_form = MDRForms.wizards.subclassed_modelform(item_to_clone.__class__)
    if request.method == 'POST':  # If the form has been submitted...
        form = base_form(request.POST, user=request.user)

        if form.is_valid():
            with transaction.atomic(), reversion.revisions.create_revision():
                new_clone = form.save()
                reversion.revisions.set_user(request.user)
                reversion.revisions.set_comment("Cloned from %s (id: %s)" % (item_to_clone.name, str(item_to_clone.pk)))
                return HttpResponseRedirect(url_slugify_concept(new_clone))
    else:
        form = base_form(initial=concept_to_clone_dict(item_to_clone), user=request.user)
    return render(request, "aristotle_mdr/create/clone_item.html", {"item": item_to_clone, "form": form})
Ejemplo n.º 12
0
    def __init__(self, *args, **kwargs):

        self.request = kwargs.pop('request', None)
        clone = self.request.GET.get("clone", None)
        name_suggest_fields = kwargs.pop('name_suggest_fields', [])
        separator = kwargs.pop('separator', '-')
        if clone:
            item_to_clone = MDR._concept.objects.filter(id=clone).first().item
            kwargs['initial'] = concept_to_clone_dict(item_to_clone)

        super(AdminConceptForm, self).__init__(*args, **kwargs)
        if self.instance and not clone:
            self.itemtype = self.instance.__class__
            self.fields['deprecated'] = forms.ModelMultipleChoiceField(
                required=False,
                label="Supersedes",
                queryset=self.itemtype.objects.all(),
                widget=ConceptAutocompleteSelectMultiple(model=self._meta.model)
            )
            self.fields['deprecated'].initial = self.instance.supersedes.all()

        if name_suggest_fields:
            self.fields['name'].widget = widgets.NameSuggestInput(name_suggest_fields=name_suggest_fields, separator=separator)
        self.fields['workgroup'].queryset = self.request.user.profile.editable_workgroups.all()
Ejemplo n.º 13
0
 def get_form_kwargs(self):
     kwargs = super(CloneItemView, self).get_form_kwargs()
     kwargs.update({
         'initial': concept_to_clone_dict(self.item_to_clone)
     })
     return kwargs
Ejemplo n.º 14
0
 def get_form_kwargs(self):
     kwargs = super(CloneItemView, self).get_form_kwargs()
     kwargs.update({'initial': concept_to_clone_dict(self.item_to_clone)})
     return kwargs