Make it possible to merge nominations with inactive email addresses in the Nominee Merge form.
- Legacy-Id: 12091
This commit is contained in:
parent
c236357b4f
commit
236fb3e185
|
@ -225,11 +225,15 @@ class EditNomcomForm(forms.ModelForm):
|
|||
class MergeNomineeForm(forms.Form):
|
||||
|
||||
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(
|
||||
help_text="Select all the duplicates that should be consolidated with the primary "
|
||||
"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):
|
||||
self.nomcom = kwargs.pop('nomcom', None)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
|
||||
from collections import Counter
|
||||
from urllib import urlencode
|
||||
|
||||
from django.utils.html import escape
|
||||
from django import forms
|
||||
|
@ -47,12 +48,14 @@ class SearchablePersonsField(forms.CharField):
|
|||
def __init__(self,
|
||||
max_entries=None, # max number of selected objs
|
||||
only_users=False, # only select persons who also have a user
|
||||
all_emails=False, # select only active email addresses
|
||||
model=Person, # or Email
|
||||
hint_text="Type in name to search for person.",
|
||||
*args, **kwargs):
|
||||
kwargs["max_length"] = 1000
|
||||
self.max_entries = max_entries
|
||||
self.only_users = only_users
|
||||
self.all_emails = all_emails
|
||||
assert model in [ Email, Person ]
|
||||
self.model = model
|
||||
|
||||
|
@ -83,8 +86,13 @@ class SearchablePersonsField(forms.CharField):
|
|||
# doing this in the constructor is difficult because the URL
|
||||
# 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() })
|
||||
query_args = {}
|
||||
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)
|
||||
|
||||
|
|
|
@ -34,9 +34,12 @@ def ajax_select2_search(request, model_name):
|
|||
|
||||
# require an account at the Datatracker
|
||||
only_users = request.GET.get("user") == "1"
|
||||
all_emails = request.GET.get("a", "0") == "1"
|
||||
|
||||
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:
|
||||
objs = objs.exclude(person__user=None)
|
||||
elif model == Person:
|
||||
|
|
Loading…
Reference in a new issue