Skip to content

Commit a5e1586

Browse files
committed
Add option (default set to true) to EmailsField to require that the
email addresses have associated Datatracker accounts - this takes effect immediately for the JS auto-complete thing, but the actual validation afterwards doesn't actually require it yet (check commented out for the time being), as it appears there are still a few people without accounts in active groups - Legacy-Id: 8277
1 parent f7ac066 commit a5e1586

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

ietf/person/fields.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class EmailsField(forms.CharField):
2020
representation on the way out and parse the ids coming back as a
2121
comma-separated list on the way in."""
2222

23-
def __init__(self, *args, **kwargs):
23+
def __init__(self, max_entries=None, hint_text="Type in name or email to search for person and email address", only_users=True,
24+
*args, **kwargs):
2425
kwargs["max_length"] = 1000
25-
self.max_entries = kwargs.pop("max_entries", None)
26-
hint_text = kwargs.pop("hint_text", "Type in name or email to search for person and email address")
26+
self.max_entries = max_entries
27+
self.only_users = only_users
2728

2829
super(EmailsField, self).__init__(*args, **kwargs)
2930

3031
self.widget.attrs["class"] = "tokenized-field"
31-
self.widget.attrs["data-ajax-url"] = lazy(urlreverse, str)("ajax_search_emails") # do this lazy to prevent form initialization problems
3232
self.widget.attrs["data-hint-text"] = hint_text
3333
if self.max_entries != None:
3434
self.widget.attrs["data-max-entries"] = self.max_entries
@@ -44,6 +44,11 @@ def prepare_value(self, value):
4444
value = Email.objects.filter(address__in=addresses).select_related("person")
4545

4646
self.widget.attrs["data-pre"] = json_emails(value)
47+
# doing this in the constructor is difficult because the URL
48+
# patterns may not have been fully constructed there yet
49+
self.widget.attrs["data-ajax-url"] = urlreverse("ajax_search_emails")
50+
if self.only_users:
51+
self.widget.attrs["data-ajax-url"] += "?user=1" # require a Datatracker account
4752

4853
return ",".join(e.address for e in value)
4954

@@ -52,14 +57,17 @@ def clean(self, value):
5257
addresses = self.parse_tokenized_value(value)
5358

5459
emails = Email.objects.filter(address__in=addresses).exclude(person=None).select_related("person")
60+
# there are still a couple of active roles without accounts so don't disallow those yet
61+
#if self.only_users:
62+
# emails = emails.exclude(person__user=None)
5563
found_addresses = [e.address for e in emails]
5664

5765
failed_addresses = [x for x in addresses if x not in found_addresses]
5866
if failed_addresses:
5967
raise forms.ValidationError(u"Could not recognize the following email addresses: %s. You can only input addresses already registered in the Datatracker." % ", ".join(failed_addresses))
6068

6169
if self.max_entries != None and len(emails) > self.max_entries:
62-
raise forms.ValidationError(u"You can only select at most %s entries." % self.max_entries)
70+
raise forms.ValidationError(u"You can select at most %s entries only." % self.max_entries)
6371

6472
return emails
6573

ietf/person/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
def ajax_search_emails(request):
88
q = request.GET.get('q', '').strip()
99
emails = Email.objects.filter(Q(person__alias__name__icontains=q) |
10-
Q(address__icontains=q)).filter(active='true').order_by('person__name').distinct()[:10]
10+
Q(address__icontains=q))
11+
if request.GET.get("user") == "1":
12+
emails = emails.exclude(person__user=None) # require an account at the Datatracker
13+
emails = emails.filter(active=True).order_by('person__name').distinct()[:10]
1114
return HttpResponse(json_emails(emails), content_type='application/json')

0 commit comments

Comments
 (0)