Merged in [16515] from rjsparks@nostrum.com:
Save files correctly when updates to an existing set of slides are proposed. Fixes #2748. - Legacy-Id: 16517 Note: SVN reference [16515] has been migrated to Git commit 41fd67c6847b82d9e9f006f5bb79c03bc5b8b577
This commit is contained in:
parent
fb3d4ddb0b
commit
e3f083e6d3
|
@ -2101,6 +2101,53 @@ class MaterialsTests(TestCase):
|
||||||
self.assertEqual(session1.sessionpresentation_set.count(),1)
|
self.assertEqual(session1.sessionpresentation_set.count(),1)
|
||||||
self.assertEqual(session2.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):
|
class SessionTests(TestCase):
|
||||||
|
|
||||||
|
|
|
@ -1588,7 +1588,10 @@ def propose_session_slides(request, session_id, num):
|
||||||
else:
|
else:
|
||||||
name = 'slides-%s-%s' % (session.meeting.number, session.docname_token())
|
name = 'slides-%s-%s' % (session.meeting.number, session.docname_token())
|
||||||
name = name + '-' + slugify(title).replace('_', '-')[:128]
|
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+')
|
destination = io.open(os.path.join(settings.SLIDE_STAGING_PATH, filename),'wb+')
|
||||||
for chunk in file.chunks():
|
for chunk in file.chunks():
|
||||||
destination.write(chunk)
|
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')
|
path = os.path.join(submission.session.meeting.get_materials_path(),'slides')
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(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
|
acronym = submission.session.group.acronym
|
||||||
submission.delete()
|
submission.delete()
|
||||||
return redirect('ietf.meeting.views.session_details',num=num,acronym=acronym)
|
return redirect('ietf.meeting.views.session_details',num=num,acronym=acronym)
|
||||||
|
|
Loading…
Reference in a new issue