# Path: td_biblio/models.py
# class Author(AbstractHuman):
#     """Entry author"""
# 
#     class Meta:
#         ordering = ("last_name", "first_name")
#         verbose_name = _("Author")
#         verbose_name_plural = _("Authors")


from operator import methodcaller
from django import forms
from django.core.validators import RegexValidator
from django.utils.translation import ugettext_lazy as _
from td_biblio.models import Author
    def clean(self):
        super(EntryBatchImportForm, self).clean()

        dois = self.cleaned_data.get("dois", [])
        pmids = self.cleaned_data.get("pmids", [])

        if not len(dois) and not len(pmids):
            raise forms.ValidationError(
                _("You need to submit at least one valid DOI or PMID")
            )


class AuthorDuplicatesForm(forms.Form):
    def get_authors_choices():
        return Author.objects.values_list("id", "last_name")

    authors = forms.MultipleChoiceField(
        label=_("Authors pool"),
        help_text=_("Authors to merge"),
        choices=get_authors_choices,
    )

    alias = forms.ChoiceField(
        label=_("Target author"),
        help_text=_("Reference author for which we will define aliases"),
        choices=get_authors_choices,
    )

    def clean_authors(self):
        authors = self.cleaned_data["authors"]

# Path: td_biblio/models.py
# class Author(AbstractHuman):
#     """Entry author"""
# 
#     class Meta:
#         ordering = ("last_name", "first_name")
#         verbose_name = _("Author")
#         verbose_name_plural = _("Authors")


# Path: td_biblio/forms.py
from operator import methodcaller
from django import forms
from django.core.validators import RegexValidator
from django.utils.translation import ugettext_lazy as _
from td_biblio.models import Author

    def clean(self):
        super(EntryBatchImportForm, self).clean()

        dois = self.cleaned_data.get("dois", [])
        pmids = self.cleaned_data.get("pmids", [])

        if not len(dois) and not len(pmids):
            raise forms.ValidationError(
                _("You need to submit at least one valid DOI or PMID")
            )


class AuthorDuplicatesForm(forms.Form):
    def get_authors_choices():
        return Author.objects.values_list("id", "last_name")

    authors = forms.MultipleChoiceField(
        label=_("Authors pool"),
        help_text=_("Authors to merge"),
        choices=get_authors_choices,
    )

    alias = forms.ChoiceField(
        label=_("Target author"),
        help_text=_("Reference author for which we will define aliases"),
        choices=get_authors_choices,
    )

    def clean_authors(self):
        authors = self.cleaned_data["authors"]

        return Author.objects.filter(id__in=authors)