diff --git a/ietf/doc/factories.py b/ietf/doc/factories.py index 35c3824f4..a23a9f7ad 100644 --- a/ietf/doc/factories.py +++ b/ietf/doc/factories.py @@ -464,11 +464,14 @@ class BofreqResponsibleDocEventFactory(DocEventFactory): class BofreqFactory(BaseDocumentFactory): type_id = 'bofreq' title = factory.Faker('sentence') - name = factory.LazyAttribute(lambda o: 'bofreq-%s'%(xslugify(o.title))) + name = factory.LazyAttribute(lambda o: 'bofreq-%s-%s'%(xslugify(o.requester_lastname), xslugify(o.title))) bofreqeditordocevent = factory.RelatedFactory('ietf.doc.factories.BofreqEditorDocEventFactory','doc') bofreqresponsibledocevent = factory.RelatedFactory('ietf.doc.factories.BofreqResponsibleDocEventFactory','doc') + class Params: + requester_lastname = factory.Faker('last_name') + @factory.post_generation def states(obj, create, extracted, **kwargs): if not create: diff --git a/ietf/doc/tests_bofreq.py b/ietf/doc/tests_bofreq.py index 2950a7165..f42ab0d4f 100644 --- a/ietf/doc/tests_bofreq.py +++ b/ietf/doc/tests_bofreq.py @@ -20,6 +20,7 @@ from ietf.doc.utils_bofreq import bofreq_editors, bofreq_responsible from ietf.person.factories import PersonFactory from ietf.utils.mail import outbox, empty_outbox from ietf.utils.test_utils import TestCase, reload_db_objects, unicontent, login_testing_unauthorized +from ietf.utils.text import xslugify class BofreqTests(TestCase): @@ -330,7 +331,7 @@ This test section has some text. empty_outbox() r = self.client.post(url, postdict) self.assertEqual(r.status_code,302) - name = f"bofreq-{postdict['title']}".replace(' ','-') + name = f"bofreq-{xslugify(nobody.last_name())[:64]}-{postdict['title']}".replace(' ','-') bofreq = Document.objects.filter(name=name,type_id='bofreq').first() self.assertIsNotNone(bofreq) self.assertIsNotNone(DocAlias.objects.filter(name=name).first()) @@ -342,7 +343,7 @@ This test section has some text. self.assertEqual(bofreq.text_or_error(), 'some stuff') self.assertEqual(len(outbox),1) os.unlink(file.name) - existing_bofreq = BofreqFactory() + existing_bofreq = BofreqFactory(requester_lastname=nobody.last_name()) for postdict in [ dict(title='', bofreq_submission='enter', bofreq_content='some stuff'), dict(title='a title', bofreq_submission='enter', bofreq_content=''), @@ -351,9 +352,9 @@ This test section has some text. dict(title='a title', bofreq_submission='', bofreq_content='some stuff'), ]: r = self.client.post(url,postdict) - self.assertEqual(r.status_code, 200) + self.assertEqual(r.status_code, 200, f'Wrong status_code for {postdict}') q = PyQuery(r.content) - self.assertTrue(q('form div.has-error')) + self.assertTrue(q('form div.has-error'), f'Expected an error for {postdict}') def test_post_proposed_restrictions(self): states = State.objects.filter(type_id='bofreq').exclude(slug='proposed') diff --git a/ietf/doc/views_bofreq.py b/ietf/doc/views_bofreq.py index 28b549537..bd86c263f 100644 --- a/ietf/doc/views_bofreq.py +++ b/ietf/doc/views_bofreq.py @@ -113,14 +113,20 @@ class NewBofreqForm(BofreqUploadForm): title = forms.CharField(max_length=255) field_order = ['title','bofreq_submission','bofreq_file','bofreq_content'] - def name_from_title(self,title): - name = 'bofreq-' + xslugify(title).replace('_', '-')[:128] - return name + def __init__(self, requester, *args, **kwargs): + self._requester = requester + super().__init__(*args, **kwargs) + + def name_from_title(self, title): + requester_slug = xslugify(self._requester.last_name()) + title_slug = xslugify(title) + name = f'bofreq-{requester_slug[:64]}-{title_slug[:128]}' + return name.replace('_', '-') def clean_title(self): title = self.cleaned_data['title'] name = self.name_from_title(title) - if name == 'bofreq-': + if name == self.name_from_title(''): raise forms.ValidationError('The filename derived from this title is empty. Please include a few descriptive words using ascii or numeric characters') if Document.objects.filter(name=name).exists(): raise forms.ValidationError('This title produces a filename already used by an existing BOF request') @@ -130,7 +136,7 @@ class NewBofreqForm(BofreqUploadForm): def new_bof_request(request): if request.method == 'POST': - form = NewBofreqForm(request.POST, request.FILES) + form = NewBofreqForm(request.user.person, request.POST, request.FILES) if form.is_valid(): title = form.cleaned_data['title'] name = form.name_from_title(title) @@ -175,7 +181,7 @@ def new_bof_request(request): init = {'bofreq_content':render_to_string('doc/bofreq/bofreq_template.md',{}), 'bofreq_submission':'enter', } - form = NewBofreqForm(initial=init) + form = NewBofreqForm(request.user.person, initial=init) return render(request, 'doc/bofreq/new_bofreq.html', {'form':form}) diff --git a/ietf/templates/doc/bofreq/new_bofreq.html b/ietf/templates/doc/bofreq/new_bofreq.html index e73acbb61..387f3a504 100644 --- a/ietf/templates/doc/bofreq/new_bofreq.html +++ b/ietf/templates/doc/bofreq/new_bofreq.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {# Copyright The IETF Trust 2021, All Rights Reserved #} -{% load origin bootstrap3 static %} +{% load origin bootstrap3 static textfilters %} {% block title %}Start a new BOF Request{% endblock %} @@ -9,7 +9,7 @@
Choose a short descriptive title for your request. Take time to choose a good initial title - it will be used to make the filename for your request's content. The title can be changed later, but the filename will not change.
-For example, a request with a title of "A new important bit" will be saved as "bofreq-a-new-important-bit-00.md".
+For example, a request with a title of "A new important bit" will be saved as "bofreq-{{ user.person.last_name|xslugify|slice:"64" }}-a-new-important-bit-00.md".