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
Abstract Notification processing and RawNotification model #23
Conversation
for custom_field, value in provider.get_custom_fields().items(): | ||
if custom_field.name == "emails_circuit_maintenances" and value: | ||
self._emails_to_fetch.extend(value.split(",")) | ||
providers_with_email.append(provider.name) | ||
else: | ||
providers_without_email.append(provider.name) |
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.
This logic seems incorrect as it will add a provider that has multiple custom fields to both providers_with_email
and providers_without_email
.
for custom_field, value in provider.get_custom_fields().items(): | |
if custom_field.name == "emails_circuit_maintenances" and value: | |
self._emails_to_fetch.extend(value.split(",")) | |
providers_with_email.append(provider.name) | |
else: | |
providers_without_email.append(provider.name) | |
custom_fields = provider.get_custom_fields() | |
emails = custom_fields.get("emails_circuit_maintenance") | |
if emails: | |
self._emails_to_fetch.extend(emails.split(",")) | |
providers_with_email.append(provider.name) | |
else: | |
providers_without_email.append(provider.name) |
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.
yes, I agree with you
for custom_field, value in provider.get_custom_fields().items(): | ||
if custom_field.name == "emails_circuit_maintenances" and value: | ||
provider_emails = value | ||
break |
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.
Still not seeing why this needs to be a for loop instead of just provider_emails = provider.get_custom_fields().get("emails_circuit_maintenance", "")
. What am I missing?
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.
provider.get_custom_fields()
returns and OrderedDict
that doesn't work fine with .get("emails_circuit_maintenance", "")
... but maybe it's me who is missing something 🤒
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.
Really? OrderedDict
is a subclass of dict
, it ought to support the same syntax.
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.
it actually works as you say and I expected, but the code was not behaving well because the key is a Django object, will refine it...
>>> from collections import OrderedDict
>>> numbers = OrderedDict()
>>> numbers["one"] = 1
>>> numbers.get("one")
1
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.
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.
Ah, okay, I hadn't remembered that get_custom_fields()
returns a dict of CustomField
objects. That makes sense then. The way you've coded it is fine; the alternative would be to use provider.cf
(which is an ordinary key-value dictionary) instead of provider.get_custom_fields()
, but either way is fine.
…nexpected-exception Handle unexpected exceptions for HTML parser
The goal of the PR was to start abstracting how do we handle Notifications from external sources, with these changes:
get_notifications
function extracting theProviders
validation to eachSource
class as this will depend on each type of integration, and fix a logic issue.RawNotification.souce
is now a foreingkey to aNotificationSource
and thesender
is optional