Skip to content

Commit

Permalink
Add ExclusionWordAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Jun 28, 2024
1 parent 5de4a31 commit 54c2da8
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 54c2da8

Please sign in to comment.