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.DestinatarioOfferta)
class DestinatarioOffertaAdmin(ImportExportModelAdmin):
    # resource = resources.DestinatarioOffertaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.GruppoOfferte)
class GruppoOfferteAdmin(ImportExportModelAdmin):
    # resource = resources.GruppoOfferteResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.Offerta)
class OffertaAdmin(ImportExportModelAdmin):
    # resource = resources.OffertaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.AgenteOfferta)
class AgenteOffertaAdmin(ImportExportModelAdmin):
    # resource = resources.AgenteOffertaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.ParteEconomicaOfferta)
class ParteEconomicaOffertaAdmin(ImportExportModelAdmin):
    # resource = resources.ParteEconomicaOffertaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


@admin.register(models.TipologiaOfferta)
class TipologiaOffertaAdmin(ImportExportModelAdmin):
    # resource = resources.TipologiaOffertaResource
    # list_per_page = 15
    # paginator = CachingPaginator
    # show_full_result_count = False
    pass


