Exemplo n.º 1
0
    async def handle_catch_all(self, player, action, values, **kwargs):
        # Filter out the folder selection.
        if not action.startswith('folder_select__'):
            return

        # Fetch the folder from the database.
        try:
            folder = await MapFolder.get(id=action[15:])
        except:
            return  # Ignore exceptions here, could be that the folder has been deleted recently.

        # Check permission on folder.
        if folder.public and player.level < player.LEVEL_ADMIN:
            return
        if not folder.public and folder.player_id != player.id:
            return

        # Check for duplicates.
        existing = await MapInFolder.execute(
            MapInFolder.select(
                MapInFolder).where((MapInFolder.folder == folder)
                                   & (MapInFolder.map_id == self.map_id)))

        if len(existing) > 0:
            await show_alert(player, 'Map already in folder!', 'sm')
            return

        # Add map to folder.
        map_in_folder = MapInFolder(map_id=self.map_id, folder=folder)
        await map_in_folder.save()

        self.response_future.set_result(True)
        self.response_future.done()
Exemplo n.º 2
0
	async def delete_folder(self, player, values, folder_dictionary, view, **kwargs):
		# Check permission on folder.
		if folder_dictionary['type'] == 'auto':
			await show_alert(player, 'You can not remove an auto-folder!', size='sm')
			return

		# Check permission on folder.
		# Masteradmins (level 3) are allowed to delete other folders.
		if folder_dictionary['owner_login'] != player.login and player.level < 3:
			await show_alert(player, 'You can not remove folders made by others!', size='sm')
			return

		# Ask for confirmation.
		cancel = bool(await ask_confirmation(player, 'Are you sure you want to remove folder \'{}\'$z$s?'.format(
			folder_dictionary['name']
		), size='sm'))
		if cancel is True:
			return

		# Remove maps from folder.
		await MapInFolder.execute(
			MapInFolder.delete()
				.where(MapInFolder.folder == folder_dictionary['id'].replace('database_', ''))
		)

		# Remove folder.
		await MapFolder.execute(
			MapFolder.delete()
				.where(MapFolder.id == folder_dictionary['id'].replace('database_', ''))
		)

		# Refresh list.
		await self.refresh(player)
Exemplo n.º 3
0
    async def remove_from_folder(self, player, values, map_dictionary, view,
                                 **kwargs):
        # Check permission on folder.
        if (self.folder_instance.public and player.level < player.LEVEL_ADMIN)\
         or (not self.folder_instance.public and self.folder_instance.player_id != player.id):
            await show_alert(
                player,
                'You are not allowed to remove the map from the folder!',
                size='sm')
            return

        # Ask for confirmation.
        cancel = bool(await ask_confirmation(
            player,
            'Are you sure you want to remove the map \'{}\'$z$s from the folder?'
            .format(map_dictionary['name']),
            size='sm'))
        if cancel is True:
            return

        # Remove from folder.
        await MapInFolder.execute(MapInFolder.delete().where(
            (MapInFolder.map_id == map_dictionary['id'])
            & (MapInFolder.folder_id == self.folder_instance.id)))

        # Refresh list.
        await self.refresh(player)
Exemplo n.º 4
0
    async def action_add_current(self, player, values, **kwargs):
        if self.app.instance.map_manager.current_map.id in [
                m.id for m in self.map_list
        ]:
            await show_alert(player,
                             'The current map is already in this folder!',
                             'sm')
            return

        # Add map to folder.
        map_in_folder = MapInFolder(
            map_id=self.app.instance.map_manager.current_map.id,
            folder=self.folder_instance)
        await map_in_folder.save()

        await show_alert(player, 'Map has been added to the folder!', 'sm')
        await self.display(player)
Exemplo n.º 5
0
	async def action_add_current(self, player, values, **kwargs):
		if self.app.instance.map_manager.current_map.id in [m.id for m in self.map_list]:
			await show_alert(player, 'The current map is already in this folder!', 'sm')
			return

		# Add map to folder.
		map_in_folder = MapInFolder(
			map_id=self.app.instance.map_manager.current_map.id,
			folder=self.folder_instance
		)
		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)