import django_filters
from dal import autocomplete

from vocabs.models import SkosConcept
from vocabs.filters import generous_concept_filter
from entities.models import (
    Place, AlternativeName, Institution, Person, PersonPerson
)


class PersonPersonListFilter(django_filters.FilterSet):
    source = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('source').help_text,
        label=PersonPerson._meta.get_field('source').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    target = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('target').help_text,
        label=PersonPerson._meta.get_field('target').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    rel_type = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=PersonPerson._meta.get_field('rel_type').help_text,
        label=PersonPerson._meta.get_field('rel_type').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/fam-rel-type",
            )
        )

    class Meta:
        model = PersonPerson
        fields = "__all__"


class PersonListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('name').help_text,
        label=Person._meta.get_field('name').verbose_name
        )
    name_start = django_filters.CharFilter(
        field_name='name',
        lookup_expr='startswith',
        help_text=Person._meta.get_field('name').help_text,
        label=Person._meta.get_field('name').verbose_name
        )
    forename = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('forename').help_text,
        label=Person._meta.get_field('forename').verbose_name
        )
    written_name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('written_name').help_text,
        label=Person._meta.get_field('written_name').verbose_name
        )
    profession = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=Person._meta.get_field('profession').help_text,
        label=Person._meta.get_field('profession').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/profession",
            )
        )

    class Meta:
        model = Person
        fields = "__all__"


class InstitutionListFilter(django_filters.FilterSet):
    written_name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('written_name').help_text,
        label=Institution._meta.get_field('written_name').verbose_name
        )
    alt_names = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('alt_names').help_text,
        label=Institution._meta.get_field('alt_names').verbose_name
        )
    authority_url = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('authority_url').help_text,
        label=Institution._meta.get_field('authority_url').verbose_name
        )
    location = django_filters.ModelMultipleChoiceFilter(
        queryset=Place.objects.all(),
        help_text=Institution._meta.get_field('location').help_text,
        label=Institution._meta.get_field('location').verbose_name
        )

    class Meta:
        model = Institution
        fields = [
            'id', 'written_name', 'authority_url', 'location'
        ]


class PlaceListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Place._meta.get_field('name').help_text,
        label=Place._meta.get_field('name').verbose_name
        )
    geonames_id = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Place._meta.get_field('geonames_id').help_text,
        label=Place._meta.get_field('geonames_id').verbose_name
        )
    alt_names = django_filters.ModelMultipleChoiceFilter(
        queryset=AlternativeName.objects.all(),
        help_text=Place._meta.get_field('alt_names').help_text,
        label=Place._meta.get_field('alt_names').verbose_name
        )
    part_of = django_filters.ModelMultipleChoiceFilter(
        queryset=Place.objects.all(),
        help_text=Place._meta.get_field('part_of').help_text,
        label=Place._meta.get_field('part_of').verbose_name
        )

    class Meta:
        model = Place
        fields = [
            'id'
        ]


class AlternativeNameListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=AlternativeName._meta.get_field('name').help_text,
        label=AlternativeName._meta.get_field('name').verbose_name
        )

    class Meta:
        model = AlternativeName
        fields = [
            'id'
        ]


class PersonPersonListFilter(django_filters.FilterSet):
    source = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('source').help_text,
        label=PersonPerson._meta.get_field('source').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    target = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('target').help_text,
        label=PersonPerson._meta.get_field('target').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    rel_type = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=PersonPerson._meta.get_field('rel_type').help_text,
        label=PersonPerson._meta.get_field('rel_type').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/fam-rel-type",
            )
        )

    class Meta:
        model = PersonPerson
        fields = "__all__"

import django_filters
from dal import autocomplete

from vocabs.models import SkosConcept
from vocabs.filters import generous_concept_filter
from entities.models import (
    Place, AlternativeName, Institution, Person, PersonPerson
)


class PersonPersonListFilter(django_filters.FilterSet):
    source = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('source').help_text,
        label=PersonPerson._meta.get_field('source').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    target = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('target').help_text,
        label=PersonPerson._meta.get_field('target').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    rel_type = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=PersonPerson._meta.get_field('rel_type').help_text,
        label=PersonPerson._meta.get_field('rel_type').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/fam-rel-type",
            )
        )

    class Meta:
        model = PersonPerson
        fields = "__all__"


class PersonListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('name').help_text,
        label=Person._meta.get_field('name').verbose_name
        )
    name_start = django_filters.CharFilter(
        field_name='name',
        lookup_expr='startswith',
        help_text=Person._meta.get_field('name').help_text,
        label=Person._meta.get_field('name').verbose_name
        )
    forename = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('forename').help_text,
        label=Person._meta.get_field('forename').verbose_name
        )
    written_name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Person._meta.get_field('written_name').help_text,
        label=Person._meta.get_field('written_name').verbose_name
        )
    profession = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=Person._meta.get_field('profession').help_text,
        label=Person._meta.get_field('profession').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/profession",
            )
        )

    class Meta:
        model = Person
        fields = "__all__"


class InstitutionListFilter(django_filters.FilterSet):
    written_name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('written_name').help_text,
        label=Institution._meta.get_field('written_name').verbose_name
        )
    alt_names = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('alt_names').help_text,
        label=Institution._meta.get_field('alt_names').verbose_name
        )
    authority_url = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Institution._meta.get_field('authority_url').help_text,
        label=Institution._meta.get_field('authority_url').verbose_name
        )
    location = django_filters.ModelMultipleChoiceFilter(
        queryset=Place.objects.all(),
        help_text=Institution._meta.get_field('location').help_text,
        label=Institution._meta.get_field('location').verbose_name
        )

    class Meta:
        model = Institution
        fields = [
            'id', 'written_name', 'authority_url', 'location'
        ]


class PlaceListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Place._meta.get_field('name').help_text,
        label=Place._meta.get_field('name').verbose_name
        )
    geonames_id = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=Place._meta.get_field('geonames_id').help_text,
        label=Place._meta.get_field('geonames_id').verbose_name
        )
    alt_names = django_filters.ModelMultipleChoiceFilter(
        queryset=AlternativeName.objects.all(),
        help_text=Place._meta.get_field('alt_names').help_text,
        label=Place._meta.get_field('alt_names').verbose_name
        )
    part_of = django_filters.ModelMultipleChoiceFilter(
        queryset=Place.objects.all(),
        help_text=Place._meta.get_field('part_of').help_text,
        label=Place._meta.get_field('part_of').verbose_name
        )

    class Meta:
        model = Place
        fields = [
            'id'
        ]


class AlternativeNameListFilter(django_filters.FilterSet):
    name = django_filters.CharFilter(
        lookup_expr='icontains',
        help_text=AlternativeName._meta.get_field('name').help_text,
        label=AlternativeName._meta.get_field('name').verbose_name
        )

    class Meta:
        model = AlternativeName
        fields = [
            'id'
        ]


class PersonPersonListFilter(django_filters.FilterSet):
    source = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('source').help_text,
        label=PersonPerson._meta.get_field('source').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    target = django_filters.ModelMultipleChoiceFilter(
        queryset=Person.objects.all(),
        help_text=PersonPerson._meta.get_field('target').help_text,
        label=PersonPerson._meta.get_field('target').verbose_name,
        widget=autocomplete.Select2Multiple(
            url="/entities-ac/person-autocomplete",
            )
        )
    rel_type = django_filters.ModelMultipleChoiceFilter(
        queryset=SkosConcept.objects.all(),
        help_text=PersonPerson._meta.get_field('rel_type').help_text,
        label=PersonPerson._meta.get_field('rel_type').verbose_name,
        method=generous_concept_filter,
        widget=autocomplete.Select2Multiple(
            url="/vocabs-ac/concept-by-colleciton-ac/fam-rel-type",
            )
        )

    class Meta:
        model = PersonPerson
        fields = "__all__"
