Skip to content

Commit

Permalink
Add map to map folder cache (to ensure it showing on refresh) when ad…
Browse files Browse the repository at this point in the history
…ding current map. (#1147)
  • Loading branch information
TheMaximum committed Mar 3, 2022
1 parent fc1dd95 commit 0afb99a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pyplanet/apps/contrib/jukebox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,9 @@ async def get_data(self):

self.title = 'Folder: ' + self.folder_info['name']

karma = any(f['index'] == "karma" for f in self.fields)
length = any(f['index'] == "local_record" for f in self.fields)

items = []
for item in self.map_list:
dict_item = model_to_dict(item)
if length:
dict_item['local_record'] = times.format_time((item.local['first_record'].score if hasattr(item, 'local') and item.local['first_record'] else 0))
if karma and 'karma' in self.app.instance.apps.apps:
dict_item['karma'] = (await self.app.instance.apps.apps['karma'].get_map_karma(item))['map_karma']
items.append(dict_item)
items.append(await self.map_to_dict(item))

self.cache = items
return self.cache
Expand Down Expand Up @@ -439,6 +431,10 @@ async def action_add_current(self, player, values, **kwargs):
)
await map_in_folder.save()

# Add the map to the cache to show it on refresh.
if self.cache:
self.cache.append(await self.map_to_dict(self.app.instance.map_manager.current_map))

await show_alert(player, 'Map has been added to the folder!', 'sm')
await self.refresh(player)

Expand All @@ -456,6 +452,15 @@ async def action_rename(self, player, values, **kwargs):

await self.display(player)

async def map_to_dict(self, map):
dict_item = model_to_dict(map)
if any(f['index'] == "local_record" for f in self.fields):
dict_item['local_record'] = times.format_time((map.local['first_record'].score if hasattr(map, 'local') and map.local['first_record'] else 0))
if any(f['index'] == "karma" for f in self.fields) and 'karma' in self.app.instance.apps.apps:
dict_item['karma'] = (await self.app.instance.apps.apps['karma'].get_map_karma(map))['map_karma']

return dict_item


class FolderListView(ManualListView):
title = 'Maplist folders'
Expand Down

0 comments on commit 0afb99a

Please sign in to comment.