From 23ac054ad6f73e60355e8a2a7ed6d797fb8bb884 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sun, 21 Jul 2019 21:03:13 +0000 Subject: [PATCH] Merged in [16554] from rjsparks@nostrum.com: Rework how SlideSuggestion objects name their files. Improve the UI when there are multiple pending suggestions for updating the same presentation. - Legacy-Id: 16570 Note: SVN reference [16554] has been migrated to Git commit 1e8eb0ed6d227e32816c4bc352a7301691eaaaac --- ietf/meeting/models.py | 1 + ietf/meeting/tests_views.py | 18 ++++++++++++++---- ietf/meeting/views.py | 17 ++++++++++------- ietf/templates/meeting/session_details.html | 4 ++-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ietf/meeting/models.py b/ietf/meeting/models.py index 464b2ae15..d8f5a54ec 100644 --- a/ietf/meeting/models.py +++ b/ietf/meeting/models.py @@ -1172,6 +1172,7 @@ class ImportantDate(models.Model): return u'%s : %s : %s' % ( self.meeting, self.name, self.date ) class SlideSubmission(models.Model): + time = models.DateTimeField(auto_now=True) session = ForeignKey(Session) title = models.CharField(max_length=255) filename = models.CharField(max_length=255) diff --git a/ietf/meeting/tests_views.py b/ietf/meeting/tests_views.py index 087742fef..e9669c007 100644 --- a/ietf/meeting/tests_views.py +++ b/ietf/meeting/tests_views.py @@ -2131,22 +2131,32 @@ class MaterialsTests(TestCase): 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) + test_file = BytesIO(b'this is not really a slide, but it is third 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() - approve_url = urlreverse('ietf.meeting.views.approve_proposed_slides', kwargs={'slidesubmission_id':submission.pk,'num':submission.session.meeting.number}) + (first_submission, second_submission) = SlideSubmission.objects.filter(session=session).order_by('id') + + approve_url = urlreverse('ietf.meeting.views.approve_proposed_slides', kwargs={'slidesubmission_id':second_submission.pk,'num':second_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) + + disapprove_url = urlreverse('ietf.meeting.views.approve_proposed_slides', kwargs={'slidesubmission_id':first_submission.pk,'num':first_submission.session.meeting.number}) + r = self.client.post(disapprove_url,dict(title='some title',disapprove="disapprove")) + self.assertEqual(r.status_code,302) self.client.logout() + self.assertEqual(SlideSubmission.objects.count(),0) 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) + self.assertIn('third version', contents) class SessionTests(TestCase): diff --git a/ietf/meeting/views.py b/ietf/meeting/views.py index 8f6de41a7..4f36bb064 100644 --- a/ietf/meeting/views.py +++ b/ietf/meeting/views.py @@ -1580,6 +1580,9 @@ def propose_session_slides(request, session_id, num): if show_apply_to_all_checkbox: apply_to_all = form.cleaned_data['apply_to_all'] title = form.cleaned_data['title'] + + submission = SlideSubmission.objects.create(session = session, title = title, filename = '', apply_to_all = apply_to_all, submitter=request.user.person) + if session.meeting.type_id=='ietf': name = 'slides-%s-%s' % (session.meeting.number, session.group.acronym) @@ -1588,15 +1591,15 @@ 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] - 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) + filename = '%s-ss%d%s'% (name, submission.id, ext) destination = io.open(os.path.join(settings.SLIDE_STAGING_PATH, filename),'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() - submission = SlideSubmission.objects.create(session = session, title = title, filename = filename, apply_to_all = apply_to_all, submitter=request.user.person) + + submission.filename = filename + submission.save() + (to, cc) = gather_address_lists('slides_proposed', group=session.group).as_strings() msg_txt = render_to_string("meeting/slides_proposed.txt", { "to": to, @@ -2436,7 +2439,7 @@ def approve_proposed_slides(request, slidesubmission_id, num): if len(sessions) > 1: session_number = 1 + sessions.index(submission.session) name, _ = os.path.splitext(submission.filename) - name = name[:-3] + name = name[:name.rfind('-ss')] existing_doc = Document.objects.filter(name=name).first() if request.method == 'POST': form = ApproveSlidesForm(show_apply_to_all_checkbox, request.POST) @@ -2480,7 +2483,7 @@ def approve_proposed_slides(request, slidesubmission_id, num): if not os.path.exists(path): os.makedirs(path) sub_name, sub_ext = os.path.splitext(submission.filename) - target_filename = '%s-%s%s' % (sub_name[:-3],doc.rev,sub_ext) + target_filename = '%s-%s%s' % (sub_name[:sub_name.rfind('-ss')],doc.rev,sub_ext) os.rename(submission.staged_filepath(), os.path.join(path, target_filename)) acronym = submission.session.group.acronym submission.delete() diff --git a/ietf/templates/meeting/session_details.html b/ietf/templates/meeting/session_details.html index 0e8d3a061..caf13fda8 100644 --- a/ietf/templates/meeting/session_details.html +++ b/ietf/templates/meeting/session_details.html @@ -49,9 +49,9 @@
{% for s in pending_suggestions %} {% if can_manage_materials %} -

{{s.submitter}} - {{s.title}}

+

{{s.submitter}} - {{s.title}} ({{s.time}})

{% else %} -

{{s.title}}

+

{{s.title}} ({{s.time}})

{% endif %} {% endfor %}