diff options
author | Cefin <kevon@tuta.io> | 2021-11-30 15:03:59 +0000 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:49 +0200 |
commit | 5606a70f7b500db3b4de3196d78bd19fb4fa57b7 (patch) | |
tree | 7372f7a6c9a7a86b0b2094698915f2060fb9a2b9 | |
parent | de735baa576e415ea6f78c8665e17f2a20c68a38 (diff) | |
download | Ishtar-5606a70f7b500db3b4de3196d78bd19fb4fa57b7.tar.bz2 Ishtar-5606a70f7b500db3b4de3196d78bd19fb4fa57b7.zip |
rapid action on document add document with parent source #5172 part two todo: refactoring
-rw-r--r-- | ishtar_common/views.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 485facd75..7368f3fab 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2100,12 +2100,15 @@ class DocumentCreateView(DocumentFormMixin, CreateView): def get_form_kwargs(self): kwargs = super(DocumentCreateView, self).get_form_kwargs() initial = kwargs.get("initial", {}) + document = '' + value = '' - try: - document = models.Document.objects.get(pk=self.kwargs.get("pk")) - assert check_permission(self.request, "document/create", document.pk) - except (AssertionError, models.Document.DoesNotExist): - raise Http404() + 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) + except (AssertionError, models.Document.DoesNotExist): + raise Http404() for related_key in models.Document.RELATED_MODELS_ALT: model = models.Document._meta.get_field(related_key).related_model @@ -2116,13 +2119,16 @@ class DocumentCreateView(DocumentFormMixin, CreateView): continue initial[related_key] = str(item.pk) - value = getattr(document, related_key) - if hasattr(value, "all"): - value = ",".join([str(v.pk) for v in value.all()]) - if hasattr(value, "pk"): - value = value.pk + if document: + value = getattr(document, related_key) + 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 - initial["source"] = document.pk + + if document: + initial["source"] = document.pk if initial: kwargs["initial"] = initial |