diff options
| author | Cefin <kevon@tuta.io> | 2021-12-01 15:34:19 +0000 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:49 +0200 | 
| commit | dedcccd75354b011adb7f4a9073f0a61ea1d652a (patch) | |
| tree | c4539e4b7a39bb996150ca2b19995a80a07b17aa /ishtar_common/views.py | |
| parent | 5606a70f7b500db3b4de3196d78bd19fb4fa57b7 (diff) | |
| download | Ishtar-dedcccd75354b011adb7f4a9073f0a61ea1d652a.tar.bz2 Ishtar-dedcccd75354b011adb7f4a9073f0a61ea1d652a.zip  | |
rapid action on document add document with parent source with tests #5172 part three
Diffstat (limited to 'ishtar_common/views.py')
| -rw-r--r-- | ishtar_common/views.py | 19 | 
1 files changed, 9 insertions, 10 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 7368f3fab..19fc9f848 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2100,13 +2100,13 @@ class DocumentCreateView(DocumentFormMixin, CreateView):      def get_form_kwargs(self):          kwargs = super(DocumentCreateView, self).get_form_kwargs()          initial = kwargs.get("initial", {}) -        document = '' -        value = '' +        document_parent = None +        value = None          if self.kwargs.get("pk"):              try: -                document = models.Document.objects.get(pk=self.kwargs.get("pk")) -                assert check_permission(self.request, "document/create", document.pk) +                document_parent = models.Document.objects.get(pk=self.kwargs.get("pk")) +                assert check_permission(self.request, "document/create", document_parent.pk)              except (AssertionError, models.Document.DoesNotExist):                  raise Http404() @@ -2119,16 +2119,15 @@ class DocumentCreateView(DocumentFormMixin, CreateView):                      continue                  initial[related_key] = str(item.pk) -            if document: -                value = getattr(document, related_key) +        if document_parent: +            for k in models.Document.RELATED_MODELS: +                value = getattr(document_parent, k)                  if hasattr(value, "all"):                      value = ",".join([str(v.pk) for v in value.all()])                  if hasattr(value, "pk"):                      value = value.pk -            initial[related_key] = value - -        if document: -            initial["source"] = document.pk +                initial[k] = value +            initial["source"] = document_parent.pk          if initial:              kwargs["initial"] = initial  | 
