1
|
|
|
# coding: utf8 |
2
|
|
|
|
3
|
|
|
""" |
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
5
|
|
|
|
6
|
|
|
Copyright 2014 Crystalnix Limited |
7
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
10
|
|
|
the License at |
11
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
17
|
|
|
License for the specific language governing permissions and limitations under |
18
|
|
|
the License. |
19
|
|
|
""" |
20
|
|
|
|
21
|
|
|
import django_tables2 as tables |
22
|
|
|
from django_tables2 import A |
23
|
|
|
|
24
|
|
|
from omaha.models import AppRequest |
25
|
|
|
from omaha.filters import EVENT_TYPE, EVENT_RESULT |
26
|
|
|
from django.utils.html import format_html |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def get_badge(event): |
30
|
|
|
name = EVENT_TYPE[event.eventtype] |
31
|
|
|
result = EVENT_RESULT[event.eventresult] |
32
|
|
|
badge = 'info' |
33
|
|
|
if 'success' in result: |
34
|
|
|
badge = 'success' |
35
|
|
|
if 'error' in result: |
36
|
|
|
badge = 'important' |
37
|
|
|
return '<p class="badge badge-%s">%s</p>' % (badge, name) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class EventsColumn(tables.Column): |
41
|
|
|
def render(self, record): |
42
|
|
|
res = map(get_badge, record.events.all()) |
43
|
|
|
return format_html(' '.join(res)) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
class AppRequestTable(tables.Table): |
47
|
|
|
id = tables.LinkColumn('omaha_request_detail', args=[A('pk')]) |
48
|
|
|
date = tables.DateTimeColumn(accessor='request.created', format='r', order_by='-request__created') |
49
|
|
|
arch = tables.Column(accessor='request.os.arch') |
50
|
|
|
platform = tables.Column(accessor='request.os.platform') |
51
|
|
|
os = tables.Column(accessor='request.os.version', verbose_name='OS') |
52
|
|
|
sp = tables.Column(accessor='request.os.sp', verbose_name='Service pack') |
53
|
|
|
events = EventsColumn(empty_values=()) |
54
|
|
|
userid = tables.Column(accessor='request.userid', verbose_name='User ID') |
55
|
|
|
ip = tables.Column(accessor='request.ip', verbose_name='User IP') |
56
|
|
|
|
57
|
|
|
class Meta: |
58
|
|
|
model = AppRequest |
59
|
|
|
attrs = {'class': 'paleblue table table-striped table-bordered table-hover table-condensed', |
60
|
|
|
'id': 'apprequest-table'} |
61
|
|
|
fields = ('id', 'version', 'nextversion', 'platform', 'os', 'sp', 'arch', 'date', 'events',) |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
class VersionsTable(tables.Table): |
65
|
|
|
version = tables.Column(orderable=False) |
66
|
|
|
number = tables.Column(orderable=False) |
67
|
|
|
|
68
|
|
|
class Meta: |
69
|
|
|
attrs = {'class': 'paleblue table table-striped table-bordered table-hover table-condensed', |
70
|
|
|
'id': 'versions-table'} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
class VersionsUsageTable(tables.Table): |
74
|
|
|
userid = tables.Column(accessor='request.userid', verbose_name='UserID') |
75
|
|
|
nextversion = tables.Column(verbose_name='Current Version') |
76
|
|
|
last_update = tables.DateTimeColumn(accessor='request.created', order_by='-request__created', |
77
|
|
|
verbose_name='Last update') |
78
|
|
|
ip = tables.Column(accessor='request.ip', verbose_name='IP') |
79
|
|
|
platform = tables.Column(accessor='request.os.platform', verbose_name='Platform') |
80
|
|
|
|
81
|
|
|
class Meta: |
82
|
|
|
model = AppRequest |
83
|
|
|
orderable = True |
84
|
|
|
attrs = {'class': 'paleblue table table-striped table-bordered table-hover table-condensed', |
85
|
|
|
'id': 'usage-table'} |
86
|
|
|
fields = ('userid', 'nextversion', 'last_update', 'ip', 'platform') |
87
|
|
|
|