diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4fe59d640..aa138c41a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -30,7 +30,7 @@ jobs: python-version: 3.10.0 - name: Install required Ubuntu packages run: | - sudo apt-get update && sudo apt-get -y --no-install-recommends install gdal-bin voikko-fi libvoikko-dev + sudo apt-get update && sudo apt-get -y --no-install-recommends install gdal-bin voikko-fi libvoikko-dev gettext sudo apt-get install redis-server - name: Create needed postgis extensions run: | @@ -40,6 +40,9 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + - name: Compile messages + run: | + python manage.py compilemessages - name: Run Python side code neatness tests run: | flake8 diff --git a/services/admin.py b/services/admin.py index 8f233996d..46b722274 100644 --- a/services/admin.py +++ b/services/admin.py @@ -1,7 +1,12 @@ +from django import forms +from django.conf import settings from django.contrib import admin +from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ from modeltranslation.admin import TranslationAdmin from services.models.notification import Announcement, ErrorMessage +from services.models.search_rule import ExclusionWord class NotificationAdmin(TranslationAdmin): @@ -10,5 +15,26 @@ class NotificationAdmin(TranslationAdmin): list_filter = ("active",) +class ExlusionWordForm(forms.ModelForm): + + def clean(self): + cleaned_data = super().clean() + accepted_language_shorts = [lang[0] for lang in settings.LANGUAGES] + if cleaned_data.get("language_short") not in accepted_language_shorts: + raise ValidationError( + _("Language short must be one of") + + f":{' ,'.join(accepted_language_shorts)}" + ) + return cleaned_data + + +class ExclusionWordAdmin(admin.ModelAdmin): + list_display = ("word", "language_short") + + model = ExclusionWord + form = ExlusionWordForm + + +admin.site.register(ExclusionWord, ExclusionWordAdmin) admin.site.register(Announcement, NotificationAdmin) admin.site.register(ErrorMessage, NotificationAdmin) diff --git a/smbackend_turku/importers/divisions.py b/smbackend_turku/importers/divisions.py index f53b0d685..7c65a3e5c 100644 --- a/smbackend_turku/importers/divisions.py +++ b/smbackend_turku/importers/divisions.py @@ -45,6 +45,7 @@ def __init__(self, logger=None, importer=None): self.logger = logger self.importer = importer self.muni_data_path = "data" + self.imported_geometries = {} def _import_division(self, muni, div, type_obj, syncher, parent_dict, feat): check_turku_boundary = div.get("check_turku_boundary", True) @@ -240,10 +241,16 @@ def _import_division(self, muni, div, type_obj, syncher, parent_dict, feat): except AdministrativeDivisionGeometry.DoesNotExist: geom_obj = AdministrativeDivisionGeometry(division=obj) + # If the geometry is in multiple featureMembers, combine the geometries + if full_id in self.imported_geometries.keys(): + geom = geom.union(self.imported_geometries[full_id].boundary) geom_obj.boundary = geom geom_obj.save() + self.imported_geometries[full_id] = geom_obj def _import_one_division_type(self, muni, div): + self.imported_geometries = {} + def make_div_id(obj): if "parent" in div: return "%s-%s" % (obj.parent.origin_id, obj.origin_id)