Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/search exclusionword admin #365

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading