# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

from django.contrib import admin
from django.forms.models import ModelForm

from weblate.wladmin.models import WeblateModelAdmin
from weblate.lang.models import Plural


class AlwaysChangedModelForm(ModelForm):
    def has_changed(self, *args, **kwargs):
        if self.instance.pk is None:
            return True
        return super(AlwaysChangedModelForm, self).has_changed(*args, **kwargs)


class PluralAdmin(admin.TabularInline):
    model = Plural
    extra = 0
    min_num = 1
    form = AlwaysChangedModelForm


class LanguageAdmin(WeblateModelAdmin):
    list_display = ['name', 'code', 'direction']
    search_fields = ['name', 'code']
    list_filter = ('direction',)
    inlines = [PluralAdmin]
