Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / tables.py @ 5d87753f

History | View | Annotate | Download (2.4 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
from django.utils.safestring import mark_safe
7

    
8
DEFAULT_DATE_FORMAT = "d/m/Y"
9

    
10

    
11
MEMBER_STATUS_DISPLAY = {
12
    100: _('Owner'),
13
      0: _('Requested'),
14
      1: _('Pending'),
15
      2: _('Accepted'),
16
      3: _('Removing'),
17
      4: _('Removed'),
18
     -1: _('Unregistered'),
19
}
20

    
21
class UserProjectApplicationsTable(tables.Table):
22

    
23
    def __init__(self, *args, **kwargs):
24
        self.user = None
25

    
26
        if 'request' in kwargs and kwargs.get('request').user:
27
            self.user = kwargs.get('request').user
28

    
29
        if 'user' in kwargs:
30
            self.user = kwargs.pop('user')
31

    
32
        super(UserProjectApplicationsTable, self).__init__(*args, **kwargs)
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
                                  sortable=False)
40
    membership_status = tables.Column(verbose_name=_("My status"), empty_values=(),
41
                                      orderable=False)
42

    
43

    
44
    def render_membership_status(self, *args, **kwargs):
45
        return MEMBER_STATUS_DISPLAY.get(kwargs.get('record').member_status(self.user))
46

    
47
    class Meta:
48
        model = ProjectApplication
49
        fields = ('name', 'membership_status', 'issue_date', 'start_date',
50
                  'state', 'members_count')
51
        attrs = {'id': 'projects-list', 'class': 'my-projects alt-style'}
52
        caption = _('My projects')
53
        template = "im/table_render.html"
54

    
55

    
56
class ProjectApplicationMembersTable(tables.Table):
57
    name = tables.Column(accessor="person.last_name", verbose_name=_('Name'))
58
    status = tables.Column(accessor="state", verbose_name=_('Status'))
59

    
60

    
61
    def render_name(self, value, record, *args, **kwargs):
62
        return record.person.realname
63

    
64
    def render_status(self, value, *args, **kwargs):
65
        return MEMBER_STATUS_DISPLAY.get(value, 'Unknown')
66

    
67
    class Meta:
68
        template = "im/table_render.html"
69
        model = ProjectMembership
70
        fields = ('name', 'status')
71
        attrs = {'id': 'members-table', 'class': 'members-table alt-style'}
72