summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms_common.py15
-rw-r--r--ishtar_common/models_common.py4
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_geographic.html6
-rw-r--r--ishtar_common/views.py36
4 files changed, 48 insertions, 13 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 2caf6c1af..11ae2009b 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -2697,6 +2697,9 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
}
def __init__(self, *args, **kwargs):
+ back_url = ""
+ if "back_url" in kwargs:
+ back_url = kwargs.pop("back_url")
main_items_fields = {}
if "main_items_fields" in kwargs:
main_items_fields = kwargs.pop("main_items_fields")
@@ -2713,6 +2716,9 @@ class GISForm(forms.ModelForm, CustomForm, ManageOldType):
self.source_content_type = kwargs.pop("source_content_type", None)
self.source_id = kwargs.pop("source_id", None)
super(GISForm, self).__init__(*args, **kwargs)
+ if back_url:
+ self.fields["back_url"] = forms.CharField(
+ label="", required=False, widget=forms.HiddenInput, initial=back_url)
if not self.fields["import_key"].initial:
self.fields.pop("import_key")
if not self.source_content_type:
@@ -2926,3 +2932,12 @@ class PreGISForm(IshtarForm):
HEADERS = {
"geom_type": FormHeader(_("Type")),
}
+
+ def __init__(self, *args, **kwargs):
+ back_url = ""
+ if "back_url" in kwargs:
+ back_url = kwargs.pop("back_url")
+ super().__init__(*args, **kwargs)
+ if back_url:
+ self.fields["back_url"] = forms.CharField(
+ label="", required=False, widget=forms.HiddenInput, initial=back_url)
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 37ddd11df..19ee2c613 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -4055,6 +4055,10 @@ class MainItem(ShortMenuItem, SerializeItem):
def class_verbose_name(cls):
return cls._meta.verbose_name
+ def get_search_url(self):
+ if self.SLUG:
+ return reverse(self.SLUG + "_search")
+
@classmethod
def get_quick_actions(cls, user, session=None, obj=None):
"""
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
index d1ac63815..295c7ef46 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
@@ -1,4 +1,5 @@
{% load i18n ishtar_helpers window_field %}
+{% with search_url=item.get_search_url %}
<table id='{{window_id}}-geographic-data' class="table table-striped">
<tr>
{% if permission_change_geo %}<th>&nbsp;</th>{% endif %}
@@ -14,7 +15,7 @@
{% for geo in geo_item.geodata.all %}
<tr>
{% if permission_change_geo %}
- <td><a href="{% url 'edit-geo' geo.pk %}">{% if geo|can_edit_item:request %}<i class="fa fa-pencil"></i></a>{% else %}&ndash;{% endif %}</td>
+ <td><a href="{% url 'edit-geo' geo.pk %}{% if search_url %}?back_url={{search_url}}%3Fopen_item={{geo_item.pk}}{% endif %}">{% if geo|can_edit_item:request %}<i class="fa fa-pencil"></i></a>{% else %}&ndash;{% endif %}</td>
{% endif %}
<td>{% if geo.id == geo_item.main_geodata_id %}<i class="fa fa-check-circle text-success" aria-hidden="true"></i>{% else %}&ndash;{% endif %}</td>
<td>{% if geo.data_type %}{{ geo.data_type }}{% else %}-{% endif %}</td>
@@ -29,6 +30,7 @@
</table>
{% if permission_change_geo %}
<div class="text-center">
- <a class="btn btn-success" href="{% url 'create-pre-geo' item.app_label item.model_name item.pk %}"><i class="fa fa-plus"></i> &nbsp;{% trans "geo item" %}</a>
+ <a class="btn btn-success" href="{% url 'create-pre-geo' item.app_label item.model_name item.pk %}{% if search_url %}?back_url={{search_url}}%3Fopen_item={{geo_item.pk}}{% endif %}"><i class="fa fa-plus"></i> &nbsp;{% trans "geo item" %}</a>
</div>
{% endif %}
+{% endwith %} \ No newline at end of file
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 6bfe8c0a5..3ed8ad904 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -25,6 +25,7 @@ import json
import logging
import os
import unicodedata
+import urllib.parse
from django.apps import apps
from django.conf import settings
@@ -2718,6 +2719,19 @@ class GeoPreCreateView(IshtarMixin, LoginRequiredMixin, FormView):
form_class = forms.PreGISForm
template_name = "ishtar/forms/base_form.html"
+ def get(self, request, *args, **kwargs):
+ self.back_url = request.GET.get("back_url")
+ return super().get(request, *args, **kwargs)
+
+ def post(self, request, *args, **kwargs):
+ self.back_url = request.POST.get("back_url")
+ return super().post(request, *args, **kwargs)
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["back_url"] = self.back_url
+ return kwargs
+
def form_valid(self, form):
success_url = reverse(
"create-geo",
@@ -2728,6 +2742,8 @@ class GeoPreCreateView(IshtarMixin, LoginRequiredMixin, FormView):
"geom_type": form.cleaned_data.get("geom_type"),
}
)
+ if self.back_url:
+ success_url += "?back_url=" + urllib.parse.quote(self.back_url)
return HttpResponseRedirect(success_url)
@@ -2736,15 +2752,12 @@ class GeoFormMixin(IshtarMixin, LoginRequiredMixin):
template_name = "ishtar/forms/geo_form.html"
model = models.GeoVectorData
- def _get_source(self, request):
- self.success_url = request.GET.get("source_url")
-
def get(self, request, *args, **kwargs):
- self._get_source(request)
+ self.back_url = request.GET.get("back_url")
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
- self._get_source(request)
+ self.back_url = request.POST.get("back_url")
return super().post(request, *args, **kwargs)
def get_context_data(self, **kwargs):
@@ -2753,9 +2766,14 @@ class GeoFormMixin(IshtarMixin, LoginRequiredMixin):
return data
def get_success_url(self):
- if not self.success_url:
+ if not self.back_url:
return reverse("edit-geo", kwargs={"pk": self.object.pk})
- return f"{self.success_url}?open_item={self.object.pk}"
+ return self.back_url
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["back_url"] = self.back_url
+ return kwargs
class GeoEditView(GeoFormMixin, UpdateView):
@@ -2851,7 +2869,3 @@ class GeoCreateView(GeoFormMixin, CreateView):
kwargs["geom_type"] = self.kwargs.get("geom_type")
kwargs["user"] = self.request.user
return kwargs
-
- def get_context_data(self, **kwargs):
- kwargs = super(GeoCreateView, self).get_context_data(**kwargs)
- return kwargs