Skip to content
Permalink
Browse files

⚡️ notify users of template's deployment creating process

  • Loading branch information...
trojikman committed Aug 14, 2019
1 parent 026e146 commit fce69a9bc958fbc1e891f3e942f95f3eca2c77a5
Showing with 18 additions and 1 deletion.
  1. +1 −0 saas/__manifest__.py
  2. +9 −0 saas/models/saas_operator.py
  3. +8 −1 saas/models/saas_template.py
@@ -22,6 +22,7 @@
"auth_quick_master",
"queue_job",
"web_editor",
"web_notify",
],
"external_dependencies": {"python": ['slugify'], "bin": []},
"data": [
@@ -103,6 +103,15 @@ def build_post_init(self, build, post_init_action, key_value_dict):
action_ids = self.build_execute_kw(build, 'ir.actions.server', 'create', [action])
self.build_execute_kw(build, 'ir.actions.server', 'run', [action_ids])

def notify_users(self, message, title=None, message_type=None):
manager_users = self.env.ref('saas.group_manager').users
if message_type == 'success':
manager_users.notify_success(message=message, title=title, sticky=True)
elif message_type == 'info':
manager_users.notify_info(message=message, title=title, sticky=True)
else:
manager_users.notify_default(message=message, title=title, sticky=True)


class SafeDict(defaultdict):
def __missing__(self, key):
@@ -149,6 +149,9 @@ def filter_free_operators(op):

def _prepare_template(self):
for r in self:
message = '''Template\'s deployment with name {} is creating
and will be ready in a few minutes.'''.format(r.operator_db_name)
self.operator_id.notify_users(message, message_type='info')
# delete db is there is one
r.operator_db_id.drop_db()
if not r.operator_db_id or r.operator_id != r.operator_db_id.operator_id:
@@ -205,13 +208,17 @@ def _post_init(self):
with api.Environment.manage(), db.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
action = env['ir.actions.server'].create({
'name': 'Local Code Eval',
'name': 'Template Code Eval',
'state': 'code',
'model_id': 1,
'code': self.template_id.template_post_init
})
action.run()
self.state = 'done'
message = '''Template\'s deployment with name {} is done,
now you can create builds. If you don't see \'Create Build\'
button on template\'s form, press \'Refresh\' button'''.format(self.operator_db_name)
self.operator_id.notify_users(message, message_type='success')
else:
auth = self._rpc_auth()
rpc_code_eval(auth, self.template_id.template_post_init)

0 comments on commit fce69a9

Please sign in to comment.
You can’t perform that action at this time.