Skip to content

Commit 1aeeb1e

Browse files
Remove code still using old "length_sessionX" SessionForm fields. Commit ready for merge.
- Legacy-Id: 19826
1 parent cf62b46 commit 1aeeb1e

4 files changed

Lines changed: 156 additions & 15 deletions

File tree

ietf/secr/sreq/templatetags/ams_filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def display_duration(value):
3333
3600: '1 Hour',
3434
5400: '1.5 Hours',
3535
7200: '2 Hours',
36-
9000: '2.5 Hours'}
36+
9000: '2.5 Hours',
37+
10800: '3 Hours',
38+
12600: '3.5 Hours',
39+
14400: '4 Hours'}
3740
if value in map:
3841
return map[value]
3942
else:

ietf/secr/sreq/tests.py

Lines changed: 127 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def test_edit(self):
9595
attendees = 10
9696
comments = 'need lights'
9797
mars_sessions = meeting.session_set.filter(group__acronym='mars')
98+
empty_outbox()
9899
post_data = {'num_session':'2',
99100
'attendees': attendees,
100101
'constraint_chair_conflict':iabprog.acronym,
@@ -156,11 +157,16 @@ def test_edit(self):
156157
self.assertContains(r, group2.acronym)
157158
self.assertContains(r, 'Second session with: {} {}'.format(group3.acronym, group4.acronym))
158159

160+
# check that a notification was sent
161+
self.assertEqual(len(outbox), 1)
162+
notification_payload = get_payload_text(outbox[0])
163+
self.assertIn('1 Hour, 1 Hour', notification_payload)
164+
self.assertNotIn('1 Hour, 1 Hour, 1 Hour', notification_payload)
165+
159166
# Edit again, changing the joint sessions and clearing some fields. The behaviour of
160167
# edit is different depending on whether previous joint sessions were recorded.
168+
empty_outbox()
161169
post_data = {'num_session':'2',
162-
'length_session1':'3600',
163-
'length_session2':'3600',
164170
'attendees':attendees,
165171
'constraint_chair_conflict':'',
166172
'comments':'need lights',
@@ -206,6 +212,12 @@ def test_edit(self):
206212
self.assertEqual(list(sessions[0].joint_with_groups.all()), [group2])
207213
self.assertFalse(sessions[1].joint_with_groups.count())
208214

215+
# check that a notification was sent
216+
self.assertEqual(len(outbox), 1)
217+
notification_payload = get_payload_text(outbox[0])
218+
self.assertIn('1 Hour, 1 Hour', notification_payload)
219+
self.assertNotIn('1 Hour, 1 Hour, 1 Hour', notification_payload)
220+
209221
# Check whether the updated data is visible on the view page
210222
r = self.client.get(redirect_url)
211223
self.assertContains(r, 'First session with: {}'.format(group2.acronym))
@@ -579,7 +591,7 @@ def test_request_notification(self):
579591
sessions = Session.objects.filter(meeting=meeting,group=group)
580592
self.assertEqual(len(sessions), 2)
581593
session = sessions[0]
582-
594+
583595
self.assertEqual(session.resources.count(),1)
584596
self.assertEqual(session.people_constraints.count(),1)
585597
self.assertEqual(session.constraints().get(name='time_relation').time_relation, 'subsequent-days')
@@ -597,6 +609,115 @@ def test_request_notification(self):
597609
self.assertTrue(ad.ascii_name() in notification_payload)
598610
self.assertIn(ConstraintName.objects.get(slug='chair_conflict').name, notification_payload)
599611
self.assertIn(group.acronym, notification_payload)
612+
self.assertIn('1 Hour, 1 Hour', notification_payload)
613+
self.assertNotIn('1 Hour, 1 Hour, 1 Hour', notification_payload)
614+
self.assertNotIn('The third session requires your approval', notification_payload)
615+
616+
def test_request_notification_third_session(self):
617+
meeting = MeetingFactory(type_id='ietf', date=datetime.date.today())
618+
ad = Person.objects.get(user__username='ad')
619+
area = GroupFactory(type_id='area')
620+
RoleFactory(name_id='ad', person=ad, group=area)
621+
group = GroupFactory(acronym='ames', parent=area)
622+
group2 = GroupFactory(acronym='ames2', parent=area)
623+
group3 = GroupFactory(acronym='ames2', parent=area)
624+
group4 = GroupFactory(acronym='ames3', parent=area)
625+
RoleFactory(name_id='chair', group=group, person__user__username='ameschairman')
626+
resource = ResourceAssociation.objects.create(name_id='project')
627+
# Bit of a test data hack - the fixture now has no used resources to pick from
628+
resource.name.used=True
629+
resource.name.save()
630+
631+
url = reverse('ietf.secr.sreq.views.new',kwargs={'acronym':group.acronym})
632+
confirm_url = reverse('ietf.secr.sreq.views.confirm',kwargs={'acronym':group.acronym})
633+
len_before = len(outbox)
634+
attendees = '10'
635+
post_data = {'num_session':'2',
636+
'third_session': 'true',
637+
'attendees':attendees,
638+
'bethere':str(ad.pk),
639+
'constraint_chair_conflict':group4.acronym,
640+
'comments':'',
641+
'resources': resource.pk,
642+
'session_time_relation': 'subsequent-days',
643+
'adjacent_with_wg': group2.acronym,
644+
'joint_with_groups': group3.acronym,
645+
'joint_for_session': '2',
646+
'timeranges': ['thursday-afternoon-early', 'thursday-afternoon-late'],
647+
'session_set-TOTAL_FORMS': '3',
648+
'session_set-INITIAL_FORMS': '0',
649+
'session_set-MIN_NUM_FORMS': '1',
650+
'session_set-MAX_NUM_FORMS': '3',
651+
# no 'session_set-0-id' for new session
652+
'session_set-0-name': '',
653+
'session_set-0-short': '',
654+
'session_set-0-purpose': 'regular',
655+
'session_set-0-type': 'regular',
656+
'session_set-0-requested_duration': '3600',
657+
'session_set-0-on_agenda': True,
658+
'session_set-0-remote_instructions': '',
659+
'session_set-0-attendees': attendees,
660+
'session_set-0-comments': '',
661+
'session_set-0-DELETE': '',
662+
# no 'session_set-1-id' for new session
663+
'session_set-1-name': '',
664+
'session_set-1-short': '',
665+
'session_set-1-purpose': 'regular',
666+
'session_set-1-type': 'regular',
667+
'session_set-1-requested_duration': '3600',
668+
'session_set-1-on_agenda': True,
669+
'session_set-1-remote_instructions': '',
670+
'session_set-1-attendees': attendees,
671+
'session_set-1-comments': '',
672+
'session_set-1-DELETE': '',
673+
# no 'session_set-2-id' for new session
674+
'session_set-2-name': '',
675+
'session_set-2-short': '',
676+
'session_set-2-purpose': 'regular',
677+
'session_set-2-type': 'regular',
678+
'session_set-2-requested_duration': '3600',
679+
'session_set-2-on_agenda': True,
680+
'session_set-2-remote_instructions': '',
681+
'session_set-2-attendees': attendees,
682+
'session_set-2-comments': '',
683+
'session_set-2-DELETE': '',
684+
'submit': 'Continue'}
685+
self.client.login(username="ameschairman", password="ameschairman+password")
686+
# submit
687+
r = self.client.post(url,post_data)
688+
self.assertEqual(r.status_code, 200)
689+
q = PyQuery(r.content)
690+
self.assertTrue('Confirm' in str(q("title")), r.context['form'].errors)
691+
# confirm
692+
post_data['submit'] = 'Submit'
693+
r = self.client.post(confirm_url,post_data)
694+
self.assertRedirects(r, reverse('ietf.secr.sreq.views.main'))
695+
self.assertEqual(len(outbox),len_before+1)
696+
notification = outbox[-1]
697+
notification_payload = get_payload_text(notification)
698+
sessions = Session.objects.filter(meeting=meeting,group=group)
699+
self.assertEqual(len(sessions), 3)
700+
session = sessions[0]
701+
702+
self.assertEqual(session.resources.count(),1)
703+
self.assertEqual(session.people_constraints.count(),1)
704+
self.assertEqual(session.constraints().get(name='time_relation').time_relation, 'subsequent-days')
705+
self.assertEqual(session.constraints().get(name='wg_adjacent').target.acronym, group2.acronym)
706+
self.assertEqual(
707+
list(session.constraints().get(name='timerange').timeranges.all().values('name')),
708+
list(TimerangeName.objects.filter(name__in=['thursday-afternoon-early', 'thursday-afternoon-late']).values('name'))
709+
)
710+
resource = session.resources.first()
711+
self.assertTrue(resource.desc in notification_payload)
712+
self.assertTrue('Schedule the sessions on subsequent days' in notification_payload)
713+
self.assertTrue(group2.acronym in notification_payload)
714+
self.assertTrue("Can't meet: Thursday early afternoon, Thursday late" in notification_payload)
715+
self.assertTrue('Second session joint with: {}'.format(group3.acronym) in notification_payload)
716+
self.assertTrue(ad.ascii_name() in notification_payload)
717+
self.assertIn(ConstraintName.objects.get(slug='chair_conflict').name, notification_payload)
718+
self.assertIn(group.acronym, notification_payload)
719+
self.assertIn('1 Hour, 1 Hour, 1 Hour', notification_payload)
720+
self.assertIn('The third session requires your approval', notification_payload)
600721

601722
class LockAppTestCase(TestCase):
602723
def setUp(self):
@@ -747,17 +868,17 @@ def test_valid(self):
747868

748869
# Test with two sessions
749870
self.valid_form_data.update({
750-
'length_session3': '',
751871
'third_session': '',
872+
'session_set-TOTAL_FORMS': '2',
752873
'joint_for_session': '2'
753874
})
754875
form = SessionForm(data=self.valid_form_data, group=self.group1, meeting=self.meeting)
755876
self.assertTrue(form.is_valid())
756877

757878
# Test with one session
758879
self.valid_form_data.update({
759-
'length_session2': '',
760880
'num_session': 1,
881+
'session_set-TOTAL_FORMS': '1',
761882
'joint_for_session': '1',
762883
'session_time_relation': '',
763884
})
@@ -806,7 +927,7 @@ def test_invalid_conflict_with_self(self):
806927
def test_invalid_session_time_relation(self):
807928
form = self._invalid_test_helper({
808929
'third_session': '',
809-
'length_session2': '',
930+
'session_set-TOTAL_FORMS': 1,
810931
'num_session': 1,
811932
'joint_for_session': '1',
812933
})

ietf/secr/sreq/views.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ def save_conflicts(group, meeting, conflicts, name):
141141
name=constraint_name)
142142
constraint.save()
143143

144-
def send_notification(group,meeting,login,session,action):
144+
def send_notification(group, meeting, login, sreq_data, session_data, action):
145145
'''
146146
This function generates email notifications for various session request activities.
147-
session argument is a dictionary of fields from the session request form
147+
sreq_data argument is a dictionary of fields from the session request form
148+
session_data is an array of data from individual session subforms
148149
action argument is a string [new|update].
149150
'''
150151
(to_email, cc_list) = gather_address_lists('session_requested',group=group,person=login)
@@ -154,7 +155,7 @@ def send_notification(group,meeting,login,session,action):
154155

155156
# send email
156157
context = {}
157-
context['session'] = session
158+
context['session'] = sreq_data
158159
context['group'] = group
159160
context['meeting'] = meeting
160161
context['login'] = login
@@ -168,12 +169,14 @@ def send_notification(group,meeting,login,session,action):
168169

169170
# if third session requested approval is required
170171
# change headers TO=ADs, CC=session-request, submitter and cochairs
171-
if session.get('length_session3',None):
172-
context['session']['num_session'] = 3
172+
if len(session_data) > 2:
173173
(to_email, cc_list) = gather_address_lists('session_requested_long',group=group,person=login)
174174
subject = '%s - Request for meeting session approval for IETF %s' % (group.acronym, meeting.number)
175175
template = 'sreq/session_approval_notification.txt'
176176
#status_text = 'the %s Directors for approval' % group.parent
177+
178+
context['session_lengths'] = [sd['requested_duration'] for sd in session_data]
179+
177180
send_mail(None,
178181
to_email,
179182
from_email,
@@ -368,7 +371,14 @@ def confirm(request, acronym):
368371

369372
# send notification
370373
session_data['outbound_conflicts'] = [f"{d['name']}: {d['groups']}" for d in outbound_conflicts]
371-
send_notification(group,meeting,login,session_data,'new')
374+
send_notification(
375+
group,
376+
meeting,
377+
login,
378+
session_data,
379+
[sf.cleaned_data for sf in form.session_forms[:num_sessions]],
380+
'new',
381+
)
372382

373383
status_text = 'IETF Agenda to be scheduled'
374384
messages.success(request, 'Your request has been sent to %s' % status_text)
@@ -537,7 +547,14 @@ def edit(request, acronym, num=None):
537547
#add_session_activity(group,'Session Request was updated',meeting,user)
538548

539549
# send notification
540-
send_notification(group,meeting,login,form.cleaned_data,'update')
550+
send_notification(
551+
group,
552+
meeting,
553+
login,
554+
form.cleaned_data,
555+
[sf.cleaned_data for sf in form.session_forms.forms_to_keep],
556+
'update',
557+
)
541558

542559
messages.success(request, 'Session Request updated')
543560
return redirect('ietf.secr.sreq.views.view', acronym=acronym)

ietf/secr/templates/includes/session_info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Session Requester: {{ login }}
66
{% if session.joint_with_groups %}{{ session.joint_for_session_display }} joint with: {{ session.joint_with_groups }}{% endif %}
77

88
Number of Sessions: {{ session.num_session }}
9-
Length of Session(s): {{ session.length_session1|display_duration }}{% if session.length_session2 %}, {{ session.length_session2|display_duration }}{% endif %}{% if session.length_session3 %}, {{ session.length_session3|display_duration }}{% endif %}
9+
Length of Session(s): {% for session_length in session_lengths %}{{ session_length.total_seconds|display_duration }}{% if not forloop.last %}, {% endif %}{% endfor %}
1010
Number of Attendees: {{ session.attendees }}
1111
Conflicts to Avoid:
1212
{% for line in session.outbound_conflicts %} {{line}}

0 commit comments

Comments
 (0)