diff options
| -rw-r--r-- | ishtar_common/models.py | 27 | ||||
| -rw-r--r-- | ishtar_common/models_rest.py | 19 | 
2 files changed, 39 insertions, 7 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index c1a53213f..1f0fd6095 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -113,10 +113,7 @@ from ishtar_common.models_imports import (      TargetKeyGroup,      ValueFormater,  ) -from ishtar_common.models_rest import ( -    ApiUser, -    ApiSearchModel -) +from ishtar_common.models_rest import ApiUser, ApiSearchModel  from ishtar_common.utils import (      get_cache, @@ -354,7 +351,7 @@ class HistoryModel(models.Model):          if not models.endswith(".models"):              models += ".models"          models = import_module(models) -        model = getattr(models, self.__class__.__name__[len("Historical"):]) +        model = getattr(models, self.__class__.__name__[len("Historical") :])          field = getattr(model, key)          if hasattr(field, "rel"):              field = field.rel @@ -1724,6 +1721,24 @@ class CustomFormJsonField(models.Model):          ) +class SheetFilter(models.Model): +    key = models.CharField(_("Key"), max_length=200) + +    class Meta: +        abstract = True + +    def get_template(self): +        raise NotImplemented() + +    def get_keys(self): +        tpl = os.path.abspath( +            os.path.join(settings.ROOT_PATH, "..", self.get_template()) +        ) +        r = re.compile("item\.([_a-zA-Z])+") +        with open(tpl, "r") as fle: +            return list(set(r.findall(fle.read()))) + +  class GlobalVar(models.Model, Cached):      slug = models.SlugField(_("Variable name"), unique=True)      description = models.TextField( @@ -3658,7 +3673,7 @@ class Document(      COL_LABELS = {          "authors__cached_label": _("Authors"),          "complete_identifier": _("Identifier"), -        "source_type__label": _("Type") +        "source_type__label": _("Type"),      }      CACHED_LABELS = ["cache_related_label"] diff --git a/ishtar_common/models_rest.py b/ishtar_common/models_rest.py index 40398bca7..e16d37a90 100644 --- a/ishtar_common/models_rest.py +++ b/ishtar_common/models_rest.py @@ -2,7 +2,6 @@ import datetime  import os  import tempfile -from django.apps import apps  from django.conf import settings  from django.contrib.auth.models import User  from django.contrib.contenttypes.models import ContentType @@ -34,6 +33,12 @@ MAIN_CONTENT_TYPES = APP_CONTENT_TYPES + [      ("archaeological_warehouse", "container"),  ] +MAIN_MODELS = dict( +    [(model_name, app_name) for app_name, model_name in MAIN_CONTENT_TYPES] +) + + +  class ApiUser(models.Model):      user_ptr = models.OneToOneField( @@ -64,6 +69,18 @@ class ApiSearchModel(models.Model):          verbose_name_plural = _("API - Remote access - Search models") +class ApiSheetFilter(models.Model): +    api_search_model = models.ForeignKey(ApiSearchModel, on_delete=models.CASCADE) + +    class Meta: +        verbose_name = _("API - Remote access - Sheet filter") +        verbose_name_plural = _("API - Remote access - Sheet filters") + +    def get_template(self): +        ct = self.api_search_model.content_type +        return f"{ct.app_label}/templatestemplates/ishtar/sheet_{ct.model}.html" + +  class ApiExternalSource(models.Model):      url = models.URLField(verbose_name=_("URL"))      name = models.CharField(verbose_name=_("Name"), max_length=200) | 
