Skip to content
Snippets Groups Projects
Select Git revision
  • 382c7e016f73c95e25c5882bf26cfb808f11eac8
  • main default protected
2 results

main.py

Blame
  • Forked from SOFT Core / SOFT 161 and 162 / REST Webservices in Class
    Source project has a limited visibility.
    main.py 1.02 KiB
    from kivy.app import App
    from kivy.uix.label import Label
    from kivy.logger import Logger
    
    from json import dumps
    
    from openmrs import RESTConnection
    
    
    class RestApp(App):
        def load_locations(self):
            self.root.ids.results.clear_widgets()
            openmrs_connection = RESTConnection('localhost', 8080, 'admin', 'Admin123')
            openmrs_connection.send_request('location', None, None, self.on_locations_loaded,
                                            self.on_locations_not_loaded, self.on_locations_not_loaded)
    
        def on_locations_loaded(self, _, response):
            print(dumps(response, indent=4, sort_keys=True))
            results_layout = self.root.ids.results
            for result in response['results']:
                results_layout.add_widget(Label(text=result['display']))
    
        def on_locations_not_loaded(self, _, error):
            self.root.ids.results.add_widget(Label(text='[Failed to load locations]'))
            Logger.error(f'{self.__class__.__name__}: {error}')
    
    
    if __name__ == '__main__':
        app = RestApp()
        app.run()