Projet

Général

Profil

Télécharger (1,43 ko) Statistiques
| Branche: | Tag: | Révision:

root / uauth / organization / views.py @ 836b9f76

1
from django.utils.translation import ugettext as _
2
from django.core.urlresolvers import reverse_lazy
3

    
4
from django.views.generic.base import TemplateView
5
from django.views.generic.list import ListView
6

    
7
from django_tables2 import RequestConfig
8

    
9
from .models import LocalAccount, Organization
10
from .tables import AccountTable
11

    
12

    
13
class OrganizationMixin(object):
14

    
15
    def get_queryset(self):
16
        qs = super(OrganizationMixin, self).get_queryset()
17
        return qs.filter(organization__slug=self.kwargs['organization_slug'])
18

    
19
    def get_success_url(self):
20
        return reverse_lazy('manage-users', kwargs={'organization_slug': self.kwargs['organization_slug']})
21

    
22
    def get_context_data(self, *args, **kwargs):
23
        ctx = super(OrganizationMixin, self).get_context_data(*args, **kwargs)
24
        ctx['organization'] = Organization.objects.get(slug=self.kwargs['organization_slug'])
25
        return ctx
26

    
27
class ManageView(TemplateView):
28
    template_name = 'organization/manage.html'
29

    
30
manage = ManageView.as_view()
31

    
32
class UsersPageView(OrganizationMixin, ListView):
33
    template_name = 'organization/users.html'
34
    model = LocalAccount
35

    
36
    def get_context_data(self, *args, **kwargs):
37
        context = super(UsersPageView, self).get_context_data(*args, **kwargs)
38
        table = AccountTable(context['object_list'])
39
        RequestConfig(self.request).configure(table)
40
        context['table'] = table
41
        return context
42

    
43
users = UsersPageView.as_view()
(8-8/8)