root / snf-astakos-app / astakos / im / tables.py @ 5550bcfb
History | View | Annotate | Download (1.5 kB)
1 |
import django_tables2 as tables |
---|---|
2 |
|
3 |
from django.utils.translation import ugettext as _ |
4 |
from django_tables2 import A |
5 |
from astakos.im.models import * |
6 |
|
7 |
DEFAULT_DATE_FORMAT = "d/m/Y"
|
8 |
|
9 |
|
10 |
MEMBER_STATUS_DISPLAY = { |
11 |
100: _('Owner'), |
12 |
0: _('Requested'), |
13 |
1: _('Pending'), |
14 |
2: _('Accepted'), |
15 |
3: _('Removing'), |
16 |
4: _('Removed'), |
17 |
-1: _('Unregistered'), |
18 |
} |
19 |
|
20 |
class UserProjectApplicationsTable(tables.Table): |
21 |
|
22 |
def __init__(self, *args, **kwargs): |
23 |
self.user = None |
24 |
|
25 |
if 'request' in kwargs and kwargs.get('request').user: |
26 |
self.user = kwargs.get('request').user |
27 |
|
28 |
if 'user' in kwargs: |
29 |
self.user = kwargs.pop('user') |
30 |
|
31 |
super(UserProjectApplicationsTable, self).__init__(*args, **kwargs) |
32 |
|
33 |
|
34 |
name = tables.LinkColumn('astakos.im.views.project_detail', args=(A('pk'),)) |
35 |
issue_date = tables.DateColumn(format=DEFAULT_DATE_FORMAT) |
36 |
start_date = tables.DateColumn(format=DEFAULT_DATE_FORMAT) |
37 |
state = tables.Column(verbose_name="Status")
|
38 |
members_count = tables.Column(verbose_name="Enrolled", default=0) |
39 |
membership_status = tables.Column(verbose_name="My status", empty_values=(),
|
40 |
orderable=False)
|
41 |
|
42 |
def render_membership_status(self, *args, **kwargs): |
43 |
return MEMBER_STATUS_DISPLAY.get(kwargs.get('record').member_status(self.user)) |
44 |
|
45 |
class Meta: |
46 |
model = ProjectApplication |
47 |
fields = ('name', 'membership_status', 'issue_date', 'start_date', |
48 |
'state', 'members_count') |
49 |
|