diff options
Diffstat (limited to 'ishtar_common/views.py')
-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 |