This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
132 lines (110 loc) · 2.95 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from playhouse.shortcuts import model_to_dict
from pyplanet.apps.core.maniaplanet.models import Map
from pyplanet.views.generics import ManualListView
class TopRanksView(ManualListView):
title = 'Top ranked players on the server'
icon_style = 'Icons128x128_1'
icon_substyle = 'Statistics'
def __init__(self, app, player, top_ranks):
"""
Init topsums list view.
:param player: Player instance.
:param app: App instance.
:type player: pyplanet.apps.core.maniaplanet.models.Player
:type app: apps.rankings.Rankings
"""
super().__init__(self)
self.app = app
self.player = player
self.manager = app.context.ui
self.provide_search = False
self.top_ranks = top_ranks
async def get_data(self):
data = list()
for idx, rank in enumerate(self.top_ranks):
data.append(dict(
rank=idx+1,
player_nickname=rank.player.nickname,
average='{:0.2f}'.format((rank.average / 10000))
))
return data
async def destroy(self):
self.top_ranks = None
await super().destroy()
def destroy_sync(self):
self.top_ranks = None
super().destroy_sync()
async def get_fields(self):
return [
{
'name': '#',
'index': 'rank',
'sorting': False,
'searching': False,
'width': 10,
'type': 'label'
},
{
'name': 'Player',
'index': 'player_nickname',
'sorting': False,
'searching': False,
'width': 80,
'type': 'label'
},
{
'name': 'Average',
'index': 'average',
'sorting': False,
'searching': False,
'width': 25,
'type': 'label'
}
]
class NoRanksView(ManualListView):
model = Map
title = 'Non-ranked maps on this server'
icon_style = 'Icons128x128_1'
icon_substyle = 'Browse'
def __init__(self, app, player, ranked_maps):
"""
Init no-rank list view.
:param player: Player instance.
:param app: App instance.
:type player: pyplanet.apps.core.maniaplanet.models.Player
"""
super().__init__(self)
self.app = app
self.player = player
self.manager = app.context.ui
self.ranked_maps = ranked_maps
async def get_fields(self):
return [
{
'name': 'Name',
'index': 'name',
'sorting': True,
'searching': True,
'search_strip_styles': True,
'width': 90,
'type': 'label',
'action': self.action_jukebox if ('jukebox' in self.app.instance.apps.apps) else None
},
{
'name': 'Author',
'index': 'author_login',
'sorting': True,
'searching': True,
'search_strip_styles': True,
'width': 45,
},
]
async def get_data(self):
data = list()
non_ranked_maps = [map for map in self.app.instance.map_manager.maps if map.id not in [ranked_map.id for ranked_map in self.ranked_maps]]
for non_ranked_map in non_ranked_maps:
map_dict = model_to_dict(non_ranked_map)
data.append(map_dict)
return data
async def action_jukebox(self, player, values, map_info, **kwargs):
await self.app.instance.apps.apps['jukebox'].add_to_jukebox(player, await self.app.instance.map_manager.get_map(map_info['uid']))