44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from django.utils.translation import ugettext as _
|
|
from django.core.urlresolvers import reverse_lazy
|
|
|
|
from django.views.generic.base import TemplateView
|
|
from django.views.generic.list import ListView
|
|
|
|
from django_tables2 import RequestConfig
|
|
|
|
from .models import LocalAccount, Organization
|
|
from .tables import AccountTable
|
|
|
|
|
|
class OrganizationMixin(object):
|
|
|
|
def get_queryset(self):
|
|
qs = super(OrganizationMixin, self).get_queryset()
|
|
return qs.filter(organization__slug=self.kwargs['organization_slug'])
|
|
|
|
def get_success_url(self):
|
|
return reverse_lazy('manage-users', kwargs={'organization_slug': self.kwargs['organization_slug']})
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
ctx = super(OrganizationMixin, self).get_context_data(*args, **kwargs)
|
|
ctx['organization'] = Organization.objects.get(slug=self.kwargs['organization_slug'])
|
|
return ctx
|
|
|
|
class ManageView(TemplateView):
|
|
template_name = 'organization/manage.html'
|
|
|
|
manage = ManageView.as_view()
|
|
|
|
class UsersPageView(OrganizationMixin, ListView):
|
|
template_name = 'organization/users.html'
|
|
model = LocalAccount
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
context = super(UsersPageView, self).get_context_data(*args, **kwargs)
|
|
table = AccountTable(context['object_list'])
|
|
RequestConfig(self.request).configure(table)
|
|
context['table'] = table
|
|
return context
|
|
|
|
users = UsersPageView.as_view()
|