Skip to content

Commit

Permalink
Fixed (T)MX status view + retrieval of TMX IDs for existing maps (#1224)
Browse files Browse the repository at this point in the history
* Fixed regular expression for retrieving TMX-ID from filename.

* Update (T)MX-IDs for existing maps on the server based on the filename.

* Fixed matching (T)MX data with maps on the server.

* Fixed crash on sorting on (T)MX ID in status view.
  • Loading branch information
TheMaximum committed Nov 5, 2022
1 parent c7e4358 commit b8ada47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
20 changes: 6 additions & 14 deletions pyplanet/apps/contrib/mx/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,23 @@ async def get_fields(self):
'index': 'index',
'sorting': True,
'searching': True,
'width': 15,
'width': 18,
'type': 'label'
},
{
'name': 'Map',
'index': 'map_name',
'sorting': True,
'searching': True,
'width': 91.5,
'type': 'label'
},
{
'name': 'On Server',
'index': 'updated_on_server',
'sorting': True,
'searching': False,
'width': 33,
'width': 114.5,
'type': 'label'
},
{
'name': '{} Version'.format(self.app.site_short_name),
'index': 'mx_version',
'sorting': True,
'searching': False,
'width': 33,
'width': 40,
'type': 'label'
},
{
Expand Down Expand Up @@ -517,7 +509,7 @@ async def get_data(self):
action_update = False

# Get MX information for the map (gets None if it couldn't be found).
mx_map = next((mx_map_info for mx_map_info in mx_maps_info if mx_map_info[0] == item.mx_id), None)
mx_map = next((mx_map_info for mx_map_info in mx_maps_info if str(mx_map_info[0]) == str(item.mx_id)), None)

if mx_map is None:
version_match = 'Not on {}'.format(self.app.site_short_name)
Expand All @@ -538,8 +530,8 @@ async def get_data(self):
action_update = True

action_update_content = '🔁 Update' if action_update else ' -'
items.append({'map_id': item.id, 'index': item.mx_id, 'map_name': item.name, 'version_match': version_match, 'version_match_order': version_match_order,
'updated_on_server': item.updated_at, 'mx_version': mx_version_date, 'action_update': action_update, 'action_update_content': action_update_content})
items.append({'map_id': item.id, 'index': int(item.mx_id), 'map_name': item.name, 'version_match': version_match, 'version_match_order': version_match_order,
'mx_version': mx_version_date, 'action_update': action_update, 'action_update_content': action_update_content})

# Initially sort the maps based on the 'version_match_order': New version -> Not on MX -> Up-to-date.
items.sort(key=lambda x: x['version_match_order'])
Expand Down
12 changes: 8 additions & 4 deletions pyplanet/contrib/map/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, instance):
self._original_ta = None

# Regular Expression to extract the MX-ID from a filename.
self._mx_id_regex = re.compile('(?:PyPlanet-MX\\/)([A-Z]{2})-(\\d+)\\.')
self._mx_id_regex = re.compile('(?:PyPlanet-MX\\/)([A-Z]{2,6})-(\\d+)\\.')

async def on_start(self):
self._instance.signals.listen('maniaplanet:playlist_modified', lambda: '')
Expand Down Expand Up @@ -145,17 +145,21 @@ async def update_list(self, full_update=False, detach_fks=True):
db_uids = [m.uid for m in maps]
diff = [x for x in raw_list if x['UId'] not in db_uids]

# Update existing maps with author nicknames.
for existing_map in [m for m in maps if m.author_nickname is None or len(m.author_nickname) == 0]:
# Update existing maps with author nicknames and (T)MX-IDs.
for existing_map in [m for m in maps if m.author_nickname is None or len(m.author_nickname) == 0 or (m.mx_id is None and "MX" in m.file)]:
details = [m for m in raw_list if m['UId'] == existing_map.uid][0]

# Detect any (T)MX-id from the filename.
mx_id = self._extract_mx_id(details['FileName'])

author_nickname = await self.get_map_author_nickname(details)

map_instance = await Map.get_or_create_from_info(
details['UId'], details['FileName'], details['Name'], details['Author'],
author_nickname=author_nickname, environment=details['Environnement'],
time_gold=details['GoldTime'],
price=details['CopperPrice'], map_type=details['MapType'], map_style=details['MapStyle']
price=details['CopperPrice'], map_type=details['MapType'], map_style=details['MapStyle'],
mx_id=mx_id,
)

maps = [m for m in maps if m.uid != details['UId']]
Expand Down

0 comments on commit b8ada47

Please sign in to comment.