summaryrefslogtreecommitdiff
path: root/ishtar_common/models_imports.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-07-21 15:10:19 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-10-15 19:32:59 +0200
commitb2b4cc8cca4203bc941c7531e41c8ccd9e8678ab (patch)
treec76a08780545904d822b69da38d8e2d5eaf4e7f9 /ishtar_common/models_imports.py
parent16146deb2e76bb77f9566e0c3d5f21fd98d0f65c (diff)
downloadIshtar-b2b4cc8cca4203bc941c7531e41c8ccd9e8678ab.tar.bz2
Ishtar-b2b4cc8cca4203bc941c7531e41c8ccd9e8678ab.zip
✨ GIS API: get data sources list
Diffstat (limited to 'ishtar_common/models_imports.py')
-rw-r--r--ishtar_common/models_imports.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py
index 99d7e9fd6..5eb633e63 100644
--- a/ishtar_common/models_imports.py
+++ b/ishtar_common/models_imports.py
@@ -149,6 +149,7 @@ class ImporterModel(models.Model):
IMPORT_TYPES = (
("tab", _("Table")),
("gis", _("GIS")),
+ ("qgs", _("QGIS")),
)
IMPORT_TYPES_DICT = dict(IMPORT_TYPES)
@@ -227,6 +228,14 @@ class ImporterType(models.Model):
verbose_name = _("Importer - Type")
verbose_name_plural = _("Importer - Types")
ordering = ("name",)
+ # own is defined by users
+ # change permission need view permission
+ permissions = (
+ ("view_gis_importer", "Can export to QGIS"),
+ ("view_own_gis_importer", "Can export own to QGIS"),
+ ("change_gis_importer", "Can import from QGIS"),
+ ("change_own_gis_importer", "Can import own to QGIS"),
+ )
ADMIN_SECTION = _("Imports")
def natural_key(self):
@@ -235,11 +244,30 @@ class ImporterType(models.Model):
def __str__(self):
return self.name
+ def clean(self):
+ if self.type == "qgs" and not self.is_template:
+ raise ValidationError(
+ "QGIS importers should at least can be exported. Check the \"Can be "
+ "exported\" case.")
+
def is_own(self, ishtar_user):
return bool(
self.__class__.objects.filter(pk=self.pk, users__pk=ishtar_user.pk).count()
)
+ @classmethod
+ def q_qgis_importers(cls, ishtaruser):
+ """
+ Return QGIS importer query
+ """
+ # filter available according to permissions
+ q = cls.objects.filter(type="qgs", is_template=True, available=True)
+ if not ishtaruser.is_superuser and not ishtaruser.has_permission("change_gis_importer"):
+ if not ishtaruser.has_permission("change_own_gis_importer"):
+ return q.filter(pk__isnull=True)
+ q = q.filter(users__pk=ishtaruser.pk)
+ return q
+
@property
def type_label(self):
if self.type in IMPORT_TYPES_DICT: