from import_export.admin import ImportExportModelAdmin
from django.contrib import admin
# from django.core.cache import cache
# from django.core.paginator import Paginator
from . import models
from . import resources


# # Modified version of a GIST I found in a SO thread
# # cfr. http://masnun.rocks/2017/03/20/django-admin-expensive-count-all-queries/
# class CachingPaginator(Paginator):
#     def _get_count(self):
#         if not hasattr(self, "_count"):
#             self._count = None
#         if self._count is None:
#             try:
#                 key = "adm:{0}:count".format(hash(self.object_list.query.__str__()))
#                 self._count = cache.get(key, -1)
#                 if self._count == -1:
#                     self._count = super().count
#                     cache.set(key, self._count, 60)
#             except:
#                 self._count = len(self.object_list)
#         return self._count
#     count = property(_get_count)

# # Main reusable Admin class for only viewing
# class ViewAdminMixin(admin.ModelAdmin):
#     def has_add_permission(self, request):
#         return False
#
#     def has_change_permission(self, request, obj=None):
#         return False
#
#     def has_delete_permission(self, request, obj=None):
#         return False

# --------------- FINE PREFISSO TEMPLATE ---------------


@admin.register(models.BMCModelloDiBusiness)
class BMCModelloDiBusinessAdmin(ImportExportModelAdmin):
    # resource = resources.BMCModelloDiBusinessResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCPartnerChiave)
class BMCPartnerChiaveAdmin(ImportExportModelAdmin):
    # resource = resources.BMCPartnerChiaveResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCSegmentiDiClientela)
class BMCSegmentiDiClientelaAdmin(ImportExportModelAdmin):
    # resource = resources.BMCSegmentiDiClientelaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCRelazioneConCliente)
class BMCRelazioneConClienteAdmin(ImportExportModelAdmin):
    # resource = resources.BMCRelazioneConClienteResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCAttivitaChiave)
class BMCAttivitaChiaveAdmin(ImportExportModelAdmin):
    # resource = resources.BMCAttivitaChiaveResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCPropostaDiValore)
class BMCPropostaDiValoreAdmin(ImportExportModelAdmin):
    # resource = resources.BMCPropostaDiValoreResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCRisorsaChiave)
class BMCRisorsaChiaveAdmin(ImportExportModelAdmin):
    # resource = resources.BMCRisorsaChiaveResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCFlussoDiRicavi)
class BMCFlussoDiRicaviAdmin(ImportExportModelAdmin):
    # resource = resources.BMCFlussoDiRicaviResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.BMCCanaleDiDistribuzione)
class BMCCanaleDiDistribuzioneAdmin(ImportExportModelAdmin):
    # resource = resources.BMCCanaleDiDistribuzioneResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass
