From 8b173f3397fd7f82cdc1b7377d1b62d5eec0eb14 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 21 Dec 2021 10:04:46 +0100 Subject: Syndication - fix tests --- ishtar_common/admin.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'ishtar_common/admin.py') diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py index 5c2f33aa1..b7de250c6 100644 --- a/ishtar_common/admin.py +++ b/ishtar_common/admin.py @@ -44,7 +44,7 @@ from django.contrib.gis.geos import GEOSGeometry, MultiPolygon from django.contrib.gis.gdal.error import GDALException from django.contrib.gis.geos.error import GEOSException from django.core.cache import cache -from django.core.exceptions import FieldError +from django.core.exceptions import FieldError, FieldDoesNotExist from django.core.serializers import serialize from django.db.models.fields import ( BooleanField, @@ -2186,14 +2186,15 @@ def update_types_from_source(modeladmin, request, queryset): send_error_message( request, str(_("Response of {} is not a valid JSON message.")).format(curl), - return_url, ) continue result = source.update_matches(content) if result.get("created", None): created += result['created'] if result.get("updated", None): - updated += result['updated'] + updated += result["updated"] + if result.get("deleted", None): + deleted += result["deleted"] if result.get("search_model do not exist", None): missing_models += result["search_model do not exist"] if result.get("type do not exist", None): @@ -2214,10 +2215,10 @@ def update_types_from_source(modeladmin, request, queryset): messages.add_message( request, messages.INFO, - str(_(f"{result['deleted']} matches deleted")), + str(_(f"{deleted} matches deleted")), ) if missing_models: - missing_models = ", ".join(missing_models) + missing_models = ", ".join(set(missing_models)) messages.add_message( request, messages.INFO, @@ -2228,7 +2229,7 @@ def update_types_from_source(modeladmin, request, queryset): ), ) if missing_types: - missing_types = ", ".join(result["type do not exist"]) + missing_types = ", ".join(set(missing_types)) messages.add_message( request, messages.INFO, @@ -2360,11 +2361,11 @@ class ApiSheetFilterForm(forms.ModelForm): models_rest.ApiSearchModel.objects, label=_("API - Remote access - Search model"), ) - key = forms.ChoiceField( + key = forms.CharField( label=_("Key"), initial="-", - choices=(("-", "-"),), help_text=_("Save first to choose a key"), + max_length=200, ) class Meta: @@ -2381,9 +2382,21 @@ class ApiSheetFilterForm(forms.ModelForm): query_dict._mutable = True query_dict.setlist("api_search_model", [instance.api_search_model.pk]) query_dict._mutable = False - self.fields["api_search_model"].widget.attrs = {'disabled': 'disabled'} - self.fields["key"].help_text = "" - self.fields["key"].choices = [(k, k) for k in instance.get_keys()] + self.fields["api_search_model"].widget.attrs = {"disabled": "disabled"} + keys = instance.get_keys() + model = instance.api_search_model.content_type.model_class() + help_text = [] + for key in keys: + try: + field = model._meta.get_field(key) + except FieldDoesNotExist: + field = None + if field and getattr(field, "verbose_name", None): + key += f" ({field.verbose_name})" + help_text.append(key) + self.fields["key"].help_text = str(_("Available keys: ")) + " ; ".join( + help_text + ) class ApiSheetFilterAdmin(admin.ModelAdmin): -- cgit v1.2.3