Пример #1
0
    def handle_settings(self, client, params = None):
        """Either renders the template to change opensim's settings, or handle the update settings process itself

        :param Client client: The requesting client
        :param dict params: Optional; contains the form parameters
        :return: dict - Status and Html-layout data response
        """   
        if params == None:
            response = {'status':{}}
            simulator_form = SimulatorSettingsForm(initial={'master_ini': open("./services/web_ui/dav_store/config/grid_master.ini","r").read()})       
            main = render_to_string("opensim/read_settings.html", {'simulator_form':simulator_form,'map_form':self._get_map_form()})
            return {'data':{'dom':{'main':main}}}
        else:
            if 'master_ini' in params:
                simulator_form = SimulatorSettingsForm(params)
                if simulator_form.is_valid():
                    infile = open("./services/web_ui/dav_store/config/grid_master.ini","w")
                    infile.write(simulator_form.cleaned_data['master_ini'])
                    response = {'status':{
                        'code':'SETTINGS_UPDATE_OK',
                        'i18n':_('Simulator settings succesfully updated'),
                        'type': HWIOS.ws_realm._t['notify-info']
                        }
                    }
                else: 
                    response = {'status':{
                        'code':'INVALID_FORM',
                        'i18n':_('Invalid form'),
                        'type': HWIOS.ws_realm._t['notify-info']
                        }
                    }
            elif 'center_z' in params:
                simulator_form = SimulatorSettingsForm(initial={'master_ini': open("./services/web_ui/dav_store/config/grid_master.ini","r").read()})     
                if 'osm' not in params:
                    params['osm'] = False
                response = {'status':{}}
                map_form = MapSettingsForm(params)
                if map_form.is_valid():
                    service_config = HWIOS.services['tms'].config
                    for section in service_config.sections():
                        for key,value in service_config.items(section):
                            if key in params:
                                service_config.set(section,key,params[key])
                    service_config.write(open(os.path.join(service_config.location,'service.ini'),'wb'))
                    service_config.read(os.path.join(service_config.location,'service.ini'))
                    response['status'] = {
                        'code':'CONFIG_UPDATE_OK',
                        'i18n':_('Configuration updated...'),
                        'type': HWIOS.ws_realm._t['notify-info']
                    }
                else:
                    response['status'] = {
                        'code':'FORM_INVALID',
                        'i18n':_('Invalid form!'),
                        'type': HWIOS.ws_realm._t['notify-warning']
                    }
                Maps.update_client_settings()
            client_response, tpl_params = self._get_settings(client)
            client_response.update(response)
            _target_state = '/opensim/settings/'
            notify_others(client, client_response,'/opensim/settings/modified/', '^/opensim/settings/$', tpl_params, _target_state)
            publish_activity(client.profile, _('OpenSim Settings updated'),'/opensim/settings/',[0,0,4,0,0])
            return client_response