1818from ietf .secr .utils .group import groups_by_session
1919from ietf .secr .utils .mail import get_ad_email_list , get_chair_email_list , get_cc_list
2020from ietf .utils .mail import send_mail
21- from ietf .person .models import Email
21+ from ietf .person .models import Person
2222
2323# -------------------------------------------------
2424# Globals
@@ -48,15 +48,8 @@ def get_initial_session(sessions):
4848 group = sessions [0 ].group
4949 conflicts = group .constraint_source_set .filter (meeting = meeting )
5050
51- bethere_people = [x .person for x in sessions [0 ].constraints ().filter (name = 'bethere' )]
52- bethere_email = []
53- for person in bethere_people :
54- e = person .email_set .order_by ("-active" ,"-time" ).first ()
55- if e :
56- bethere_email .append (e )
57-
5851 # even if there are three sessions requested, the old form has 2 in this field
59- initial ['num_session' ] = sessions . count () if sessions .count () <= 2 else 2
52+ initial ['num_session' ] = min ( sessions .count (), 2 )
6053
6154 # accessing these foreign key fields throw errors if they are unset so we
6255 # need to catch these
@@ -72,7 +65,7 @@ def get_initial_session(sessions):
7265 initial ['conflict3' ] = ' ' .join ([ c .target .acronym for c in conflicts .filter (name__slug = 'conflic3' ) ])
7366 initial ['comments' ] = sessions [0 ].comments
7467 initial ['resources' ] = sessions [0 ].resources .all ()
75- initial ['bethere' ] = bethere_email
68+ initial ['bethere' ] = [ x . person for x in sessions [ 0 ]. constraints (). filter ( name = 'bethere' ). select_related ( "person" )]
7669 return initial
7770
7871def get_lock_message ():
@@ -238,14 +231,15 @@ def confirm(request, acronym):
238231 This view displays details of the new session that has been requested for the user
239232 to confirm for submission.
240233 '''
234+ # FIXME: this should be using form.is_valid/form.cleaned_data - invalid input will make it crash
241235 querydict = request .session .get ('session_form' ,None )
242236 if not querydict :
243237 raise Http404
244238 form = querydict .copy ()
245239 if 'resources' in form :
246240 form ['resources' ] = [ ResourceAssociation .objects .get (pk = pk ) for pk in form ['resources' ].split (',' )]
247241 if 'bethere' in form :
248- form ['bethere' ] = [ Email .objects .get ( address = addr ) for addr in form ['bethere' ].split (',' )]
242+ form ['bethere' ] = Person .objects .filter ( pk__in = form ['bethere' ].split (',' ))
249243 meeting = get_meeting ()
250244 group = get_object_or_404 (Group ,acronym = acronym )
251245 login = request .user .person
@@ -289,8 +283,8 @@ def confirm(request, acronym):
289283
290284 if 'bethere' in form :
291285 bethere_cn = ConstraintName .objects .get (slug = 'bethere' )
292- for email in form ['bethere' ]:
293- Constraint .objects .create (name = bethere_cn ,source = group ,person = email . person , meeting = new_session .meeting )
286+ for p in form ['bethere' ]:
287+ Constraint .objects .create (name = bethere_cn , source = group , person = p , meeting = new_session .meeting )
294288
295289 # deprecated in new schema
296290 # log activity
@@ -322,14 +316,8 @@ def add_essential_people(group,initial):
322316 people = set ()
323317 if 'bethere' in initial :
324318 people .update (initial ['bethere' ])
325- for role in group .role_set .filter (name = 'chair' ):
326- e = role .person .email_set .order_by ("-active" ,"-time" ).first ()
327- if e :
328- people .add (e )
329- if group .ad :
330- e = group .ad .email_set .order_by ("-active" ,"-time" ).first ()
331- if e :
332- people .add (e )
319+ people .update (Person .objects .filter (role__group = group , role__name = 'chair' ))
320+ people .add (group .ad )
333321 initial ['bethere' ] = list (people )
334322
335323
@@ -446,8 +434,8 @@ def edit_mtg(request, num, acronym):
446434 if 'bethere' in form .changed_data and set (form .cleaned_data ['bethere' ])!= set (initial ['bethere' ]):
447435 session .constraints ().filter (name = 'bethere' ).delete ()
448436 bethere_cn = ConstraintName .objects .get (slug = 'bethere' )
449- for email in form .cleaned_data ['bethere' ]:
450- Constraint .objects .create (name = bethere_cn ,source = group ,person = email . person , meeting = session .meeting )
437+ for p in form .cleaned_data ['bethere' ]:
438+ Constraint .objects .create (name = bethere_cn , source = group , person = p , meeting = session .meeting )
451439
452440 # deprecated
453441 # log activity
0 commit comments