def post_update(self, settings): if settings.enable_polling: from email_client import Client self.client = Client() self.client.start() elif 'client' in self.__dict__: self.client.exit()
class AppSettingsModelView(ModelView): datamodel = SQLAInterface(AppSettings) base_permissions = ['can_list', 'can_show', 'can_edit'] edit_form_extra_fields = { 'service_account_password': PasswordField( 'Password', description='Service Account Password', validators=[validators.Required()])} description_columns = { 'accounts_to_check': 'Comma seperated list of email accounts that ' \ 'the automated email poller will check.' \ ' Note: email poller account must have permissions to view those' \ 'shared mailboxes.', 'inbox_filter': 'MS API filter applied to emails to narrow the list' \ 'for processing.' \ 'Reference: https://msdn.microsoft.com/en-us/office/office365/' \ 'api/complex-types-for-mail-contacts-calendar', 'email_polling_interval': 'How often to poll emails (seconds)', 'enable_polling': 'If checked, automatic emails will be ' \ 'automatically polled.', 'enable_auto_processing': 'If checked, each email collected will ' \ 'be automatically processed by all registered and enabled ' \ 'actions.', 'service_account_username': '******', 'service_account_password': '******', 'admin_email_addresses': 'System alerts and errors will be sent here' } label_columns = { 'accounts_to_check': 'Get Emails From', 'inbox_filter': 'Email Filter', 'email_polling_interval': 'Check Email Interval', 'enable_polling': 'Enable Automatic Email Checking', 'enable_auto_processing': 'Enable Automatic Email Actions'} list_columns = [ 'accounts_to_check', 'inbox_filter', 'email_polling_interval', 'enable_auto_processing'] edit_fieldsets = [ ('Account Info', {'fields': [ 'service_account_username', 'service_account_password']}), ('Alerts', {'fields': ['admin_email_addresses']}), ('Polling', {'fields': [ 'accounts_to_check', 'inbox_filter', 'enable_polling', 'email_polling_interval']}) ] show_fieldsets = [ ('Account Info', {'fields': ['service_account_username']}), ('Alerts', {'fields': ['admin_email_addresses']}), ('Polling', {'fields': [ 'accounts_to_check', 'inbox_filter', 'enable_polling', 'email_polling_interval']}) ] def post_update(self, settings): if settings.enable_polling: from email_client import Client self.client = Client() self.client.start() elif 'client' in self.__dict__: self.client.exit()