diff --git a/ietf/meeting/tests_views.py b/ietf/meeting/tests_views.py index de3fc4286..087742fef 100644 --- a/ietf/meeting/tests_views.py +++ b/ietf/meeting/tests_views.py @@ -2101,6 +2101,53 @@ class MaterialsTests(TestCase): self.assertEqual(session1.sessionpresentation_set.count(),1) self.assertEqual(session2.sessionpresentation_set.count(),1) + def test_submit_and_approve_multiple_versions(self): + session = SessionFactory(meeting__type_id='ietf') + chair = RoleFactory(group=session.group,name_id='chair').person + session.meeting.importantdate_set.create(name_id='revsub',date=datetime.date.today()+datetime.timedelta(days=20)) + newperson = PersonFactory() + + propose_url = urlreverse('ietf.meeting.views.propose_session_slides', kwargs={'session_id':session.pk, 'num': session.meeting.number}) + + login_testing_unauthorized(self,newperson.user.username,propose_url) + test_file = BytesIO(b'this is not really a slide') + test_file.name = 'not_really.txt' + r = self.client.post(propose_url,dict(file=test_file,title='a test slide file',apply_to_all=True)) + self.assertEqual(r.status_code, 302) + self.client.logout() + + submission = SlideSubmission.objects.get(session = session) + + approve_url = urlreverse('ietf.meeting.views.approve_proposed_slides', kwargs={'slidesubmission_id':submission.pk,'num':submission.session.meeting.number}) + login_testing_unauthorized(self, chair.user.username, approve_url) + r = self.client.post(approve_url,dict(title=submission.title,approve='approve')) + self.assertEqual(r.status_code,302) + self.client.logout() + + self.assertEqual(session.sessionpresentation_set.first().document.rev,'00') + + login_testing_unauthorized(self,newperson.user.username,propose_url) + test_file = BytesIO(b'this is not really a slide, but it is another version of it') + test_file.name = 'not_really.txt' + r = self.client.post(propose_url,dict(file=test_file,title='a test slide file',apply_to_all=True)) + self.assertEqual(r.status_code, 302) + self.client.logout() + + submission = SlideSubmission.objects.get(session = session) + + approve_url = urlreverse('ietf.meeting.views.approve_proposed_slides', kwargs={'slidesubmission_id':submission.pk,'num':submission.session.meeting.number}) + login_testing_unauthorized(self, chair.user.username, approve_url) + r = self.client.post(approve_url,dict(title=submission.title,approve='approve')) + self.assertEqual(r.status_code,302) + self.client.logout() + + self.assertEqual(session.sessionpresentation_set.first().document.rev,'01') + path = os.path.join(submission.session.meeting.get_materials_path(),'slides') + filename = os.path.join(path,session.sessionpresentation_set.first().document.name+'-01.txt') + self.assertTrue(os.path.exists(filename)) + contents = open(filename,'r').read() + self.assertIn('another version', contents) + class SessionTests(TestCase): diff --git a/ietf/meeting/views.py b/ietf/meeting/views.py index e24b2d48c..8f6de41a7 100644 --- a/ietf/meeting/views.py +++ b/ietf/meeting/views.py @@ -1588,7 +1588,10 @@ def propose_session_slides(request, session_id, num): else: name = 'slides-%s-%s' % (session.meeting.number, session.docname_token()) name = name + '-' + slugify(title).replace('_', '-')[:128] - filename = '%s-00%s'% (name, ext) + rev = '00' + if Document.objects.filter(name=name).exists(): + rev ='%02s' % (int(Document.objects.get(name=name).rev) + 1) + filename = '%s-%s%s'% (name, rev, ext) destination = io.open(os.path.join(settings.SLIDE_STAGING_PATH, filename),'wb+') for chunk in file.chunks(): destination.write(chunk) @@ -2476,7 +2479,9 @@ def approve_proposed_slides(request, slidesubmission_id, num): path = os.path.join(submission.session.meeting.get_materials_path(),'slides') if not os.path.exists(path): os.makedirs(path) - os.rename(submission.staged_filepath(), os.path.join(path, submission.filename)) + sub_name, sub_ext = os.path.splitext(submission.filename) + target_filename = '%s-%s%s' % (sub_name[:-3],doc.rev,sub_ext) + os.rename(submission.staged_filepath(), os.path.join(path, target_filename)) acronym = submission.session.group.acronym submission.delete() return redirect('ietf.meeting.views.session_details',num=num,acronym=acronym)