Make it possible to merge nominations with inactive email addresses in the Nominee Merge form.

- Legacy-Id: 12091
This commit is contained in:
Henrik Levkowetz 2016-10-05 17:03:31 +00:00
parent c236357b4f
commit 236fb3e185
3 changed files with 19 additions and 4 deletions

View file

@ -225,11 +225,15 @@ class EditNomcomForm(forms.ModelForm):
class MergeNomineeForm(forms.Form): class MergeNomineeForm(forms.Form):
primary_email = SearchableEmailField( primary_email = SearchableEmailField(
help_text="Select the email of the Nominee record you want to use as the primary record.") help_text="Select the email of the Nominee record you want to use as the primary record.",
all_emails = True,
)
secondary_emails = SearchableEmailsField( secondary_emails = SearchableEmailsField(
help_text="Select all the duplicates that should be consolidated with the primary " help_text="Select all the duplicates that should be consolidated with the primary "
"Nominee record. Nominations already received with any of these email address " "Nominee record. Nominations already received with any of these email address "
"will be moved to show under the primary address." ) "will be moved to show under the primary address.",
all_emails = True,
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.nomcom = kwargs.pop('nomcom', None) self.nomcom = kwargs.pop('nomcom', None)

View file

@ -1,6 +1,7 @@
import json import json
from collections import Counter from collections import Counter
from urllib import urlencode
from django.utils.html import escape from django.utils.html import escape
from django import forms from django import forms
@ -47,12 +48,14 @@ class SearchablePersonsField(forms.CharField):
def __init__(self, def __init__(self,
max_entries=None, # max number of selected objs max_entries=None, # max number of selected objs
only_users=False, # only select persons who also have a user only_users=False, # only select persons who also have a user
all_emails=False, # select only active email addresses
model=Person, # or Email model=Person, # or Email
hint_text="Type in name to search for person.", hint_text="Type in name to search for person.",
*args, **kwargs): *args, **kwargs):
kwargs["max_length"] = 1000 kwargs["max_length"] = 1000
self.max_entries = max_entries self.max_entries = max_entries
self.only_users = only_users self.only_users = only_users
self.all_emails = all_emails
assert model in [ Email, Person ] assert model in [ Email, Person ]
self.model = model self.model = model
@ -83,8 +86,13 @@ class SearchablePersonsField(forms.CharField):
# doing this in the constructor is difficult because the URL # doing this in the constructor is difficult because the URL
# patterns may not have been fully constructed there yet # patterns may not have been fully constructed there yet
self.widget.attrs["data-ajax-url"] = urlreverse("ajax_select2_search_person_email", kwargs={ "model_name": self.model.__name__.lower() }) self.widget.attrs["data-ajax-url"] = urlreverse("ajax_select2_search_person_email", kwargs={ "model_name": self.model.__name__.lower() })
query_args = {}
if self.only_users: if self.only_users:
self.widget.attrs["data-ajax-url"] += "?user=1" # require a Datatracker account query_args["user"] = "1"
if self.all_emails:
query_args["a"] = "1"
if query_args:
self.widget.attrs["data-ajax-url"] += "?%s" % urlencode(query_args)
return u",".join(str(p.pk) for p in value) return u",".join(str(p.pk) for p in value)

View file

@ -34,9 +34,12 @@ def ajax_select2_search(request, model_name):
# require an account at the Datatracker # require an account at the Datatracker
only_users = request.GET.get("user") == "1" only_users = request.GET.get("user") == "1"
all_emails = request.GET.get("a", "0") == "1"
if model == Email: if model == Email:
objs = objs.filter(active=True).order_by('person__name').exclude(person=None) objs = objs.exclude(person=None).order_by('person__name')
if not all_emails:
objs = objs.filter(active=True)
if only_users: if only_users:
objs = objs.exclude(person__user=None) objs = objs.exclude(person__user=None)
elif model == Person: elif model == Person: