Make the meeting session request tool use a Person field rather than

one operating on Email, also fix a couple of bugs in the Person branch
of the tokenized autocompleting field
 - Legacy-Id: 8283
This commit is contained in:
Ole Laursen 2014-08-19 08:18:17 +00:00
parent 92e5694ed3
commit 1aafd73ec1
5 changed files with 22 additions and 29 deletions

View file

@ -82,8 +82,7 @@ class AutocompletedPersonsField(forms.CharField):
#if self.only_users:
# objs = objs.exclude(person__user=None)
found_pks = [e.pk for e in objs]
found_pks = [str(o.pk) for o in objs]
failed_pks = [x for x in pks if x not in found_pks]
if failed_pks:
raise forms.ValidationError(u"Could not recognize the following {model_name}s: {pks}. You can only input {model_name}s already registered in the Datatracker.".format(pks=", ".join(failed_pks), model_name=self.model.__name__.lower()))

View file

@ -17,7 +17,13 @@ def ajax_tokeninput_search(request, model_name):
else:
query = Q()
for t in q:
query &= Q(person__alias__name__icontains=t) | Q(address__icontains=t)
if model == Email:
query &= Q(person__alias__name__icontains=t) | Q(address__icontains=t)
elif model == Person:
if "@" in t: # allow searching email address if there's a @ in the search term
query &= Q(alias__name__icontains=t) | Q(email__address__icontains=t)
else:
query &= Q(alias__name__icontains=t)
objs = model.objects.filter(query)

View file

@ -2,7 +2,7 @@ from django import forms
from ietf.group.models import Group
from ietf.meeting.models import ResourceAssociation
from ietf.person.fields import AutocompletedEmailsField
from ietf.person.fields import AutocompletedPersonsField
# -------------------------------------------------
@ -67,7 +67,7 @@ class SessionForm(forms.Form):
wg_selector3 = forms.ChoiceField(choices=WG_CHOICES,required=False)
third_session = forms.BooleanField(required=False)
resources = forms.MultipleChoiceField(choices=[(x.pk,x.desc) for x in ResourceAssociation.objects.all()], widget=forms.CheckboxSelectMultiple,required=False)
bethere = AutocompletedEmailsField(label="Must be present", required=False)
bethere = AutocompletedPersonsField(label="Must be present", required=False)
def __init__(self, *args, **kwargs):
super(SessionForm, self).__init__(*args, **kwargs)

View file

@ -18,7 +18,7 @@ from ietf.secr.utils.decorators import check_permissions, sec_only
from ietf.secr.utils.group import groups_by_session
from ietf.secr.utils.mail import get_ad_email_list, get_chair_email_list, get_cc_list
from ietf.utils.mail import send_mail
from ietf.person.models import Email
from ietf.person.models import Person
# -------------------------------------------------
# Globals
@ -48,15 +48,8 @@ def get_initial_session(sessions):
group = sessions[0].group
conflicts = group.constraint_source_set.filter(meeting=meeting)
bethere_people = [x.person for x in sessions[0].constraints().filter(name='bethere')]
bethere_email = []
for person in bethere_people:
e = person.email_set.order_by("-active","-time").first()
if e:
bethere_email.append(e)
# even if there are three sessions requested, the old form has 2 in this field
initial['num_session'] = sessions.count() if sessions.count() <= 2 else 2
initial['num_session'] = min(sessions.count(), 2)
# accessing these foreign key fields throw errors if they are unset so we
# need to catch these
@ -72,7 +65,7 @@ def get_initial_session(sessions):
initial['conflict3'] = ' '.join([ c.target.acronym for c in conflicts.filter(name__slug='conflic3') ])
initial['comments'] = sessions[0].comments
initial['resources'] = sessions[0].resources.all()
initial['bethere'] = bethere_email
initial['bethere'] = [x.person for x in sessions[0].constraints().filter(name='bethere').select_related("person")]
return initial
def get_lock_message():
@ -238,6 +231,7 @@ def confirm(request, acronym):
This view displays details of the new session that has been requested for the user
to confirm for submission.
'''
# FIXME: this should be using form.is_valid/form.cleaned_data - invalid input will make it crash
querydict = request.session.get('session_form',None)
if not querydict:
raise Http404
@ -245,7 +239,7 @@ def confirm(request, acronym):
if 'resources' in form:
form['resources'] = [ ResourceAssociation.objects.get(pk=pk) for pk in form['resources'].split(',')]
if 'bethere' in form:
form['bethere'] = [Email.objects.get(address=addr) for addr in form['bethere'].split(',')]
form['bethere'] = Person.objects.filter(pk__in=form['bethere'].split(','))
meeting = get_meeting()
group = get_object_or_404(Group,acronym=acronym)
login = request.user.person
@ -289,8 +283,8 @@ def confirm(request, acronym):
if 'bethere' in form:
bethere_cn = ConstraintName.objects.get(slug='bethere')
for email in form['bethere']:
Constraint.objects.create(name=bethere_cn,source=group,person=email.person,meeting=new_session.meeting)
for p in form['bethere']:
Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=new_session.meeting)
# deprecated in new schema
# log activity
@ -322,14 +316,8 @@ def add_essential_people(group,initial):
people = set()
if 'bethere' in initial:
people.update(initial['bethere'])
for role in group.role_set.filter(name='chair'):
e = role.person.email_set.order_by("-active","-time").first()
if e:
people.add(e)
if group.ad:
e = group.ad.email_set.order_by("-active","-time").first()
if e:
people.add(e)
people.update(Person.objects.filter(role__group=group, role__name='chair'))
people.add(group.ad)
initial['bethere'] = list(people)
@ -446,8 +434,8 @@ def edit_mtg(request, num, acronym):
if 'bethere' in form.changed_data and set(form.cleaned_data['bethere'])!=set(initial['bethere']):
session.constraints().filter(name='bethere').delete()
bethere_cn = ConstraintName.objects.get(slug='bethere')
for email in form.cleaned_data['bethere']:
Constraint.objects.create(name=bethere_cn,source=group,person=email.person,meeting=session.meeting)
for p in form.cleaned_data['bethere']:
Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=session.meeting)
# deprecated
# log activity

View file

@ -32,7 +32,7 @@
</tr>
<tr class="row1">
<td>People who must be present:</td>
<td>{% if session.bethere %}<ul>{% for email in session.bethere %}<li>{{ email.person }}</li>{% endfor %}</ul>{% else %}<i>None</i>{% endif %}</td>
<td>{% if session.bethere %}<ul>{% for person in session.bethere %}<li>{{ person }}</li>{% endfor %}</ul>{% else %}<i>None</i>{% endif %}</td>
{% autoescape off %}
<tr class="row2"><td>Special Requests:</td><td>{{ session.comments }}</td></tr>
{% endautoescape %}