# -*- coding:utf-8 -*-

from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
from django.shortcuts import render
from accounts.models import AnconUser
from common.cbv import GridListView
from accounts.decorators import permissions

class UsersList(GridListView):
    """Просмотр списка пользователей.
    """
    @method_decorator(permissions('admin'))
    @method_decorator(never_cache)
    def dispatch(self, *args, **kwargs):
        return super(UsersList, self).dispatch(*args, **kwargs)

    def get(self, request):
        all_users = AnconUser.objects.filter(deleted=False).order_by('pk')
        page_size = self.items_per_page()
        self.context['page_size'] = page_size
        self.context['users'] = self.pagination(all_users, page_size)
        return render(request, 'accounts/manage_users.html', self.context)
