Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ def check_active_app(self):
@params : None
@returns : Appid else 0
'''
appln_id = request.env['onesignal.credentials'].sudo().search([('is_active','=',True)])
if appln_id:
if (
appln_id := request.env['onesignal.credentials']
.sudo()
.search([('is_active', '=', True)])
):
Comment on lines -14 to +18
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ActiveAppCtrl.check_active_app refactored with the following changes:

return appln_id.app_id
else:
return "0"
4 changes: 1 addition & 3 deletions models/onesignal_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class OnesignalCredentials(models.Model):
def activate_app(self):
self.ensure_one()
if not self.is_active:
#STEP 1 : CHECK IF BOOLEAN ACTIVE IN OTHER APP
app_ids = self.search([('is_active','=',True)])
if app_ids:
if app_ids := self.search([('is_active', '=', True)]):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OnesignalCredentials.activate_app refactored with the following changes:

This removes the following comments ( why? ):

#STEP 1 : CHECK IF BOOLEAN ACTIVE IN OTHER APP

raise Warning("Only one app can be active a time.")
else:
self.is_active = True
Expand Down
37 changes: 18 additions & 19 deletions models/onesignal_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def get_key(self, var, priority):

@api.multi
def get_app_data(self, app):
header = {"Content-Type": "application/json; charset=utf-8",
"Authorization": "Basic {}".format(app.apikey)}
header = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": f"Basic {app.apikey}",
}
Comment on lines -41 to +44
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OnesignalMessage.get_app_data refactored with the following changes:

appln_id = app.app_id
return {'header':header,
'app_id':appln_id}
Expand All @@ -57,31 +59,28 @@ def send_push_notification(self):

message_title = self.message_title
message_title = message_title.encode('utf-8')

payload = {"app_id": "{}".format(appln_data.get('app_id')),
"included_segments": ["All"],
"contents": {"en": "{}".format(message_content)},
"headings" :{"en": "{}".format(message_title)},
"url": "{}".format(self.launch_url),
"chrome_web_icon": "{}".format(self.icon),
"ttl": self.time_to_live or 3,
}

payload = {
"app_id": f"{appln_data.get('app_id')}",
"included_segments": ["All"],
"contents": {"en": f"{message_content}"},
"headings": {"en": f"{message_title}"},
"url": f"{self.launch_url}",
"chrome_web_icon": f"{self.icon}",
"ttl": self.time_to_live or 3,
}
if self.priority:
priority = self.get_key(var,self.priority)
payload.update({
'priority':priority
})
payload['priority'] = priority
if self.send_to_chrome or self.send_to_mozilla or self.send_to_edge:
payload.update({
'isAnyWeb': True
})
payload['isAnyWeb'] = True
try:
response = requests.post("https://onesignal.com/api/v1/notifications", headers=header, data=json.dumps(payload))
if response.status_code == 200:
resp = response.json()
self.summary = "RECEIPIENTS : {}".format(resp.get('recipients'))
self.summary = f"RECEIPIENTS : {resp.get('recipients')}"
else:
self.summary = "Error : {}".format(response.text)
self.summary = f"Error : {response.text}"
Comment on lines -60 to +83
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function OnesignalMessage.send_push_notification refactored with the following changes:

except SSLError as ex:
raise Warning("Oops, SSL Seems blocking the request.")
except Exception as ex:
Expand Down