-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)]): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| raise Warning("Only one app can be active a time.") | ||
| else: | ||
| self.is_active = True | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| appln_id = app.app_id | ||
| return {'header':header, | ||
| 'app_id':appln_id} | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| except SSLError as ex: | ||
| raise Warning("Oops, SSL Seems blocking the request.") | ||
| except Exception as ex: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
ActiveAppCtrl.check_active_apprefactored with the following changes:use-named-expression)