tables.py 3.73 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
from django.utils.safestring import mark_safe
Guilhem Saurel's avatar
Guilhem Saurel committed
2
from django.urls import reverse
Guilhem Saurel's avatar
Guilhem Saurel committed
3

Guilhem Saurel's avatar
Guilhem Saurel committed
4
import django_tables2 as tables
Guilhem Saurel's avatar
Guilhem Saurel committed
5

6
from . import models, utils
Guilhem Saurel's avatar
Guilhem Saurel committed
7
8


Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
9
class StrippedTable(tables.Table):
Guilhem Saurel's avatar
Guilhem Saurel committed
10
11
    class Meta:
        attrs = {'class': 'table table-striped'}
Guilhem Saurel's avatar
Guilhem Saurel committed
12

Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26

class ForgeTable(StrippedTable):
    class Meta:
        model = models.Forge
        fields = ('name', 'url')


class NamespaceTable(StrippedTable):
    class Meta:
        model = models.Namespace
        fields = ('group', 'name')


class ProjectTable(StrippedTable):
Guilhem Saurel's avatar
Guilhem Saurel committed
27
    commits_since = tables.Column(accessor='commits_since', orderable=False)
28
    repos = tables.Column(accessor='repos', orderable=False)
29
30
    issues = tables.Column(accessor='open_issues', orderable=False)
    pr = tables.Column(accessor='open_pr', orderable=False)
31
    rpkgs = tables.Column(accessor='rpkgs', orderable=False)
Guilhem Saurel's avatar
Guilhem Saurel committed
32
    badges = tables.Column(accessor='badges', orderable=False)
33

Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
34
35
    class Meta:
        model = models.Project
36
        fields = ('main_namespace', 'name', 'public', 'from_gepetto', 'license', 'homepage', 'updated', 'version')
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
37

Guilhem Saurel's avatar
Guilhem Saurel committed
38
39
40
    def render_name(self, record):
        return record.get_link()

41
42
43
    def render_homepage(self, value):
        return utils.domain_link(value)

Guilhem Saurel's avatar
Guilhem Saurel committed
44

Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
45
class RepoTable(StrippedTable):
Guilhem Saurel's avatar
Guilhem Saurel committed
46
47
    ahead = tables.Column(accessor='ahead', orderable=False)
    behind = tables.Column(accessor='behind', orderable=False)
Guilhem Saurel's avatar
Guilhem Saurel committed
48

Guilhem Saurel's avatar
Guilhem Saurel committed
49
    class Meta:
Guilhem Saurel's avatar
use ndh    
Guilhem Saurel committed
50
        model = models.Repo
Guilhem Saurel's avatar
Guilhem Saurel committed
51
52
53
54
55
56
57
        fields = ('forge', 'namespace', 'license', 'homepage', 'default_branch', 'open_issues', 'open_pr')

    def render_forge(self, value):
        return value.get_link()

    def render_namespace(self, record):
        return mark_safe(f'<a href="{record.url}">{record.namespace}</a>')
Guilhem Saurel's avatar
Guilhem Saurel committed
58
59
60


class BranchTable(StrippedTable):
61
62
    forge = tables.Column(accessor='forge', orderable=False)
    namespace = tables.Column(accessor='namespace', orderable=False)
Guilhem Saurel's avatar
Guilhem Saurel committed
63
64
    ci = tables.Column(accessor='ci', orderable=False)

Guilhem Saurel's avatar
Guilhem Saurel committed
65
66
    class Meta:
        model = models.Branch
Guilhem Saurel's avatar
Guilhem Saurel committed
67
        fields = ('forge', 'namespace', 'name', 'ahead', 'behind', 'updated', 'keep_doc')
68
69
70
71

    def render_name(self, record, value):
        if record.repo is None:
            return value
Guilhem Saurel's avatar
oops    
Guilhem Saurel committed
72
        name = record.name.split('/', maxsplit=2)[2] if '/' in record.name else record.name
73
74
75
76
77
78
79
80
81
82
        return mark_safe(f'<a href="{record.repo.url}/tree/{name}">{name}</a>')

    def render_forge(self, value):
        if value:
            return value.get_link()

    def render_namespace(self, record, value):
        if value:
            return mark_safe(f'<a href="{record.repo.url}">{value}</a>')

Guilhem Saurel's avatar
Guilhem Saurel committed
83
84
85
86
87
    def render_keep_doc(self, record, value):
        url = reverse('admin:rainboard_branch_change', args=[record.id])
        status = {True: '✓', False: '✗'}[value]
        return mark_safe(f'<a href="{url}">{status}</a>')

88
89
90
    # TODO: this works, but we have to hide the pinned from the main dataset
    # def get_top_pinned_data(self):
        # return self.data.data.filter(name__in=models.MAIN_BRANCHES)
91
92
93


class ImageTable(StrippedTable):
Guilhem Saurel's avatar
Guilhem Saurel committed
94
95
    name = tables.Column(accessor='get_image_name', orderable=False)

96
97
    class Meta:
        model = models.Image
Guilhem Saurel's avatar
Guilhem Saurel committed
98
        fields = ('name', 'robotpkg', 'target', 'image', 'py3', 'debug', 'created')
Guilhem Saurel's avatar
Guilhem Saurel committed
99
100
101

    def render_name(self, record, value):
        if value:
Guilhem Saurel's avatar
typo    
Guilhem Saurel committed
102
            return mark_safe(f'<a href="{record.get_image_url()}">{value}</a>')
Guilhem Saurel's avatar
Guilhem Saurel committed
103
104
105
106
107
108
109
110


class ContributorTable(StrippedTable):
    names = tables.Column(accessor='names', orderable=False)
    mails = tables.Column(accessor='mails', orderable=False)

    class Meta:
        model = models.Contributor
Guilhem Saurel's avatar
admin    
Guilhem Saurel committed
111
        fields = ('agreement_signed', 'names', 'mails')
Guilhem Saurel's avatar
Guilhem Saurel committed
112
113
114
115
116
117
118


class ContributorProjectTable(ContributorTable):
    projects = tables.Column(accessor='contributed', orderable=False)

    class Meta:
        fields = ('names', 'mails', 'projects')