from django.contrib import admin
from .models import *
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from import_export.admin import ImportExportModelAdmin
from .forms import *
# Register your models here.


class TitleAdmin(ImportExportModelAdmin):
    list_display = ('libelle', )
    search_fields = ('libelle', )


class UserAdmin(ImportExportModelAdmin, BaseUserAdmin):
    # The forms to add and change user instances
    form = UserChangeForm
    add_form = UserCreationForm

    # The fields to be used in displaying the User model.
    # These override the definitions on the base UserAdmin
    # that reference specific fields on auth.User.
    list_display = ('id','nom', 'prenoms', 'sexe', 'datenaiss', 'lieunaiss', 'phone', 'email', 'is_superuser')
    list_filter = ('is_superuser',)
    fieldsets = (
        ("Connexion", {'fields': ('email', 'password')}),
        ('Information personnelle', {'fields': ('avatar', 'nom', 'prenoms', 'sexe', 'datenaiss', 'lieunaiss', 'phone')}),
    )
    # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
    # overrides get_fieldsets to use this attribute when creating a user.
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('nom', 'prenoms', 'sexe', 'datenaiss', 'lieunaiss', 'phone', 'email', 'password1', 'password2'),
        }),
    )
    search_fields = ('nom', 'prenoms', 'sexe', 'datenaiss', 'lieunaiss', 'phone', 'email',)
    ordering = ('-id','nom', 'prenoms', 'sexe', 'datenaiss', 'lieunaiss', 'phone', 'email',)
    filter_horizontal = ()








TITLE = "USP Note manager"

admin.site.site_header = TITLE
admin.site.site_title = TITLE

admin.site.register(User, UserAdmin)

admin.site.register(Domaine, TitleAdmin)
#admin.site.register(Specialite, TitleAdmin)
admin.site.register(Mention, TitleAdmin)
admin.site.register(Ufr, TitleAdmin)
#admin.site.register(Niveau, TitleAdmin)
admin.site.register(Parcours, TitleAdmin)
admin.site.register(Semestre, TitleAdmin)
admin.site.register(Session, TitleAdmin)
admin.site.register(Salle)
admin.site.register(Evaluation)
admin.site.register(Note)
admin.site.register(Deliberation)
admin.site.register(DeliberationUe)
#admin.site.register(TypeEvaluation)
admin.site.register(Csv,CsvAdmin)
#admin.site.register(Grade)
#admin.site.register(GradeMentionUfr)
#admin.site.register(ParcoursSemestre)
# admin.site.register(Etudiant)
# admin.site.register(Enseignant)
admin.site.register(Reclamations)
admin.site.register(EnseignantUfr)
admin.site.register(Niveau,TitleAdmin)
admin.site.register(NiveauEtudiant)
admin.site.register(EmploiDuTemps)
admin.site.register(EmploiDuTemps2)
admin.site.register(Jour)
admin.site.register(EdtJour)
admin.site.register(Validite)
admin.site.register(SyllabusEcue)
admin.site.register(SyllabusUe)
admin.site.register(CategorieUe)
admin.site.register(Role)
admin.site.register(SeanceCours)
admin.site.register(InactiveUe)
admin.site.register(TypeDemandeActes)
admin.site.register(DemandeActes)
admin.site.register(TypeDocument)
admin.site.register(Document)
admin.site.register(PvArchive)
admin.site.register(Reinscription)
admin.site.register(ReponseDemandeActes)
admin.site.register(Compensation)
admin.site.register(GroupTravail)
admin.site.register(GroupEtudiant)
admin.site.register(GroupEnseignant)
admin.site.register(PsPJoint)
admin.site.register(PsTypeCours)
admin.site.register(PsCours)
admin.site.register(PsLogiciel)
admin.site.register(PsPublication)
admin.site.register(PsTypePublication)
admin.site.register(PsTypePublication2)
admin.site.register(PsGroupeRech)
admin.site.register(FlashInfo)
admin.site.register(Sondage)
admin.site.register(Personnel)
admin.site.register(Service)
admin.site.register(ResponsableService)
admin.site.register(PersonnelService)
admin.site.register(Direction)
admin.site.register(PsCours2)
admin.site.register(TypeEvaluation)
admin.site.register(Presence)

admin.site.register(AnonymatValidation)
# admin.site.register(ParcoursSemestreUe)

@admin.register(Annee)
class AnneeAdmin(ImportExportModelAdmin):
    list_display = ('libelle', 'status')
    search_fields = ('status', 'libelle', )

@admin.register(ParcoursSemestre)
class ParcoursSemestre(ImportExportModelAdmin):
    list_display = ('parcours', 'semestre','gradeMentionUfr')
    search_fields = ('parcours', 'semestre','gradeMentionUfr' )

@admin.register(Grade)
class Grade(ImportExportModelAdmin):
    list_display = ('libelle',)
    search_fields = ('libelle',)

@admin.register(GradeMentionUfr)
class GradeMentionUfr(ImportExportModelAdmin):
    list_display = ('grade','mention')
    search_fields = ('grade','mention')


@admin.register(Ue)
class UeAdmin(ImportExportModelAdmin):
    list_display = ('code', 'libelle','niveau','semestre')
    search_fields = ('code', 'libelle','niveau','semestre')

@admin.register(ParcoursSemestreUe)
class ParcoursSemestreUeAdmin(ImportExportModelAdmin):
    list_display = ('annee', 'ue','parcoursSemestre')
    search_fields = ('annee', 'ue', 'parcoursSemestre', )

@admin.register(EtudiantUe)
class EtudiantUeAdmin(ImportExportModelAdmin):
    list_display = ('etudiant', 'parcoursSemestreUe')
    search_fields = ('etudiant', 'parcoursSemestreUe', )



@admin.register(EnseignantUe)
class EnseignantUeAdmin(ImportExportModelAdmin):
    list_display = ('annee', 'enseignant', 'ecue')
    search_fields = ('annee', 'enseignant', 'ecue')


@admin.register(Ecue)
class EcueAdmin(ImportExportModelAdmin):
    list_display = ('code', 'libelle', 'credit')
    search_fields = ('code', 'libelle', 'credit')


@admin.register(Enseignant)
class EnseignantAdmin(ImportExportModelAdmin):
    list_display = ("id","nom", "prenoms", "email")
    ordering = ('-id',)
    search_fields = ('email',)

@admin.register(Etudiant)
class EnseignantAdmin(ImportExportModelAdmin):
    list_display = ("id","nce","nom", "prenoms", "email",'ufr')
    ordering = ('-id',)
    search_fields = ('email','ufr')