diff options
author | Cefin <kevon@tuta.io> | 2021-11-29 12:07:47 +0000 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:49 +0200 |
commit | de735baa576e415ea6f78c8665e17f2a20c68a38 (patch) | |
tree | d4a1e401fc9c56d3106c36aaa42254605978bc75 /ishtar_common | |
parent | 15f1921fb5fc886024fe004be5a4783bfd0a5533 (diff) | |
download | Ishtar-de735baa576e415ea6f78c8665e17f2a20c68a38.tar.bz2 Ishtar-de735baa576e415ea6f78c8665e17f2a20c68a38.zip |
rapid action add document with parent source #5172
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 12 | ||||
-rw-r--r-- | ishtar_common/urls.py | 7 | ||||
-rw-r--r-- | ishtar_common/views.py | 17 |
3 files changed, 36 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e87e6c5a2..197ac5dcc 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -4210,6 +4210,18 @@ class Document( True, ) ) + can_create_document = self.can_do(request, "add_document") + if can_create_document: + actions += [ + ( + reverse("create-document-source", args=[self.pk]), + _("Add document with source parent"), + "fa fa-plus", + _("Doc./src"), + "", + False, + ) + ] return actions @property diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 7bbdc189f..de881e1ba 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -486,6 +486,13 @@ urlpatterns += [ name="create-document", ), url( + r"document/create/(?P<pk>[0-9-]+)?/$", + check_rights(["add_document", "add_own_document"])( + views.DocumentCreateView.as_view() + ), + name="create-document-source", + ), + url( r"document/edit/$", check_rights(["change_document", "change_own_document"])( views.DocumentSelectView.as_view() diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 1363684a7..485facd75 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -2100,6 +2100,13 @@ class DocumentCreateView(DocumentFormMixin, CreateView): def get_form_kwargs(self): kwargs = super(DocumentCreateView, self).get_form_kwargs() initial = kwargs.get("initial", {}) + + 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 if model.SLUG in self.request.GET: @@ -2108,9 +2115,19 @@ class DocumentCreateView(DocumentFormMixin, CreateView): except model.DoesNotExist: 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 + initial[related_key] = value + initial["source"] = document.pk + if initial: kwargs["initial"] = initial kwargs["user"] = self.request.user + return kwargs |