summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
authorCefin <kevon@tuta.io>2021-11-30 15:03:59 +0000
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-07-08 09:58:49 +0200
commit5606a70f7b500db3b4de3196d78bd19fb4fa57b7 (patch)
tree7372f7a6c9a7a86b0b2094698915f2060fb9a2b9 /ishtar_common/views.py
parentde735baa576e415ea6f78c8665e17f2a20c68a38 (diff)
downloadIshtar-5606a70f7b500db3b4de3196d78bd19fb4fa57b7.tar.bz2
Ishtar-5606a70f7b500db3b4de3196d78bd19fb4fa57b7.zip
rapid action on document add document with parent source #5172 part two todo: refactoring
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py28
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