Skip to content

Commit

Permalink
Merge pull request #365 from City-of-Turku/feature/search-exclusionwo…
Browse files Browse the repository at this point in the history
…rd-admin

Feature/search exclusionword admin
  • Loading branch information
juuso-j authored Aug 26, 2024
2 parents f6230a7 + 54c2da8 commit 96386b3
Showing 1 changed file with 26 additions and 0 deletions.
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)

0 comments on commit 96386b3

Please sign in to comment.