Skip to content

Commit

Permalink
Merge branch 'develop' into feature/services-api-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j authored Aug 26, 2024
2 parents 63f2007 + b618f46 commit bbff1d2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions services/admin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
7 changes: 7 additions & 0 deletions smbackend_turku/importers/divisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bbff1d2

Please sign in to comment.