Exemple #1
0
    def load_scene(self, client, scene_name, params = None):
        """Either renders the template to confirm loading up a region, or handle the scene loading process ifself

        :param Client client: The requesting client
        :param str scene_name: The scene's name to operate on
        :param dict params: Optional; contains the form parameters
        :return: dict - Status and Html-layout data response
        """
        if params == None:
            regions = Regions.get_regions()
            selection = []
            for region in regions:
                selection.append((region['RegionUUID'],region['name']))
            form = LoadSceneForm(choices=selection,initial={'scene_name':scene_name})
            dialog = render_to_string("opensim/load_scene_confirmation.html", {'form':form})
            defer.returnValue({'data':{'dom':{'dialog':dialog}}})
        else:
            response = {'status':{}}
            region = Regions.get_region(params['region_uuid'])
            service_client = HWIOS.pb_server.search_service(region['service_uuid'])
            result = yield service_client['client'].load_scene(region['service_uuid'],params['region_uuid'], params['scene_name'])
            if 'loaded' in result:
                if result['loaded']:
                    response = {
                        'status':{
                            'code':'RESTORE_MADE',
                            'i18n':_('Succesfully restored scene %(scene)s in region %(region)s...') % {'scene':params['scene_name'],'region':region['name']},
                            'type': HWIOS.ws_realm._t['notify-info']
                        }
                    }
            else:
                if 'RADMIN_FAILED' in result['status']['code']:
                    response = {
                        'status':{
                            'code':'RADMIN_FAILED',
                            'i18n':_(result['status']['feedback']),
                            'type': HWIOS.ws_realm._t['notify-error']
                        }
                    }
                elif 'error' in result:
                    if result['error'] == 'SIM_OFFLINE':
                        response = {
                            'status':{
                                'code':'RESTORE_FAILED',
                                'i18n':_('Restore failed! Region must be online when loading a scene...'),
                                'type': HWIOS.ws_realm._t['notify-error']
                            }
                        }
                    elif result['error'] == 'radmin response timed out':
                        response = {
                            'status':{
                                'code':'RESTORE_RUNNING',
                                'i18n':_('Loading this OAR may take a while. Check the console for the current progress...'),
                                'type': HWIOS.ws_realm._t['notify-info']
                            }
                        }
            main = render_to_string("opensim/read_regions.html", {'region_services': Regions().get_region_services(),'scenes':Scenes.get_scenes()})
            response.update({'data':{'dom':{'main':main}}})
            defer.returnValue(response)