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
Add URN schemes to variable completions #1067
Conversation
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.
What is the use case here?
# a Twitter channel | ||
Channel.create(self.org, self.user, None, 'TT') | ||
completions.insert(-2, dict(name="contact.%s" % 'twitter', display="Contact %s" % "Twitter handle")) | ||
|
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.
Why the substitution here?
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.
completions
is a list and I want to keep the order right so I inserted before the 2 dict representing the contact fields above
This is to allow @contact.twitter to be auto completed currently it was not while their values are included in the contact message_context |
temba/contacts/models.py
Outdated
|
||
if not urn and scheme is not None: | ||
return '' | ||
|
||
if org.is_anon: | ||
return self.anon_identifier |
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.
What is this doing here? This is returning a function pointer isn't it?
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.
Agree that it would make sense for us to return a generic masked version of the URN here. (IE, just ********
for anon orgs). Though empty string if the contact doesn't have an URN of that scheme.
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.
were are return "000173823" for anon orgs not *******
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.
Ya, that seems wrong to return for @contact.tel
don't you think?
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.
Okay I can change this to make sure it is ******** only in the message context(scheme is not None
) and leave the other place be 00000173823 for the contacts views
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, ya the contact views should maybe be switching higher up on anon orgs.. (ie deciding to show the ID before calling get_urn_display)
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.
we use a template tag that calls get_urn_display
temba/flows/views.py
Outdated
@@ -789,7 +790,12 @@ def render_to_response(self, context, **response_kwargs): | |||
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))), | |||
dict(name='new_contact', display=six.text_type(_('New Contact'))) | |||
] | |||
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)] | |||
|
|||
contact_variables += [dict(name="contact.%s" % scheme, display="Contact %s" % label) for scheme, label in |
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.
localize?
General thought:
I'm thinking |
temba/contacts/models.py
Outdated
if org.is_anon: | ||
if scheme is not None: | ||
return Contact.HIDDEN_URN_MASK |
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.
Already have ContactURN.ANON_MASK
for this
…emes-to-completions
…apidpro into add-urn-schemes-to-completions
temba/contacts/models.py
Outdated
@@ -1736,8 +1736,13 @@ def get_urn_display(self, org=None, scheme=None, formatted=True, international=F | |||
if not org: | |||
org = self.org | |||
|
|||
urn = self.get_urn(scheme) | |||
|
|||
if not urn and scheme is not None: |
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.
What happens if get_urn_display
is called with no scheme on an anon org on a contact which has no URNs. Won't it return the ANON_MASK instead of ''?
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 that is what is expected, we want to have '' only in the contact message context which is where we call the method with the scheme
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.
I don't think that should be as expected.. get_urn_display
should only return the ANON_MASK if there is an URN that exists for the contact. You are saying if there is no URN on a contact we'll still get the ANON_MASK instead of ''?
@@ -66,7 +66,8 @@ def format_urn(urn_or_contact, org): | |||
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity | |||
elif isinstance(urn_or_contact, Contact): | |||
# will render contact's highest priority URN | |||
return urn_or_contact.get_urn_display(org=org, international=True) | |||
urn_val = urn_or_contact.get_display(org=org) | |||
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity |
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.
Maybe we should be calling this method something different. format_urn
sure sounds like it should return a URN.
This should only accept an URN as an argument, and we should have a filter for format_contact
for that case that shows the anon id for anon orgs, otherwise the highest priority URN.
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.
yep
@@ -789,7 +790,13 @@ def render_to_response(self, context, **response_kwargs): | |||
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))), | |||
dict(name='new_contact', display=six.text_type(_('New Contact'))) | |||
] | |||
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)] | |||
|
|||
contact_variables += [dict(name="contact.%s" % scheme, display=six.text_type(_("Contact %s" % label))) |
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.
So this will read "Contact Facebook" or "Contact Twitter" ya? Seems we might want something more like "Contact Facebook URN" and "Contact Twitter URN" instead.. Though from a naming perspective that is slightly problematic since these won't be full URNs but just the paths right?
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.
Here we'll get "Contact Facebook identifier" or "Contact Twitter handle"
as seen on
https://github.com/nyaruka/rapidpro/blob/master/temba/contacts/models.py#L61
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.
Oh ok great.
@nicpottier this is updated please review |
temba/contacts/models.py
Outdated
if org.is_anon: | ||
return self.anon_identifier | ||
return ContactURN.ANON_MASK | ||
|
||
urn = self.get_urn(scheme) |
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.
No need to call this again..
raise ValueError('Must be a URN or contact') | ||
def format_urn(urn, org): | ||
urn_val = urn.get_display(org=org, international=True) | ||
return urn_val if urn_val != ContactURN.ANON_MASK else '\u2022' * 8 # replace *'s with prettier HTML entity |
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.
Lets not use this kind of operator when we want to comment things, just use a normal if block here.
@@ -789,7 +790,13 @@ def render_to_response(self, context, **response_kwargs): | |||
dict(name='contact.uuid', display=six.text_type(_("Contact UUID"))), | |||
dict(name='new_contact', display=six.text_type(_('New Contact'))) | |||
] | |||
contact_variables += [dict(name="contact.%s" % field.key, display=field.label) for field in ContactField.objects.filter(org=org, is_active=True)] | |||
|
|||
contact_variables += [dict(name="contact.%s" % scheme, display=six.text_type(_("Contact %s" % label))) |
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.
Oh ok great.
…apidpro into add-urn-schemes-to-completions
Doh, coverage! |
that line can never be reached, coverage should be good now |
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.
No description provided.