Skip to content

Commit 0d1aa09

Browse files
Include requester's last name as part of a bofreq document's name. Fixes ietf-tools#3377. Commit ready for merge.
- Legacy-Id: 19679
1 parent 9d853d3 commit 0d1aa09

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

ietf/doc/factories.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,14 @@ def responsible(obj, create, extracted, **kwargs):
437437
class BofreqFactory(BaseDocumentFactory):
438438
type_id = 'bofreq'
439439
title = factory.Faker('sentence')
440-
name = factory.LazyAttribute(lambda o: 'bofreq-%s'%(xslugify(o.title)))
440+
name = factory.LazyAttribute(lambda o: 'bofreq-%s-%s'%(xslugify(o.requester_lastname), xslugify(o.title)))
441441

442442
bofreqeditordocevent = factory.RelatedFactory('ietf.doc.factories.BofreqEditorDocEventFactory','doc')
443443
bofreqresponsibledocevent = factory.RelatedFactory('ietf.doc.factories.BofreqResponsibleDocEventFactory','doc')
444444

445+
class Params:
446+
requester_lastname = factory.Faker('last_name')
447+
445448
@factory.post_generation
446449
def states(obj, create, extracted, **kwargs):
447450
if not create:

ietf/doc/tests_bofreq.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ietf.person.factories import PersonFactory
2121
from ietf.utils.mail import outbox, empty_outbox
2222
from ietf.utils.test_utils import TestCase, reload_db_objects, unicontent, login_testing_unauthorized
23+
from ietf.utils.text import xslugify
2324

2425

2526
class BofreqTests(TestCase):
@@ -330,7 +331,7 @@ def test_start_new_bofreq(self):
330331
empty_outbox()
331332
r = self.client.post(url, postdict)
332333
self.assertEqual(r.status_code,302)
333-
name = f"bofreq-{postdict['title']}".replace(' ','-')
334+
name = f"bofreq-{xslugify(nobody.last_name())[:64]}-{postdict['title']}".replace(' ','-')
334335
bofreq = Document.objects.filter(name=name,type_id='bofreq').first()
335336
self.assertIsNotNone(bofreq)
336337
self.assertIsNotNone(DocAlias.objects.filter(name=name).first())
@@ -342,7 +343,7 @@ def test_start_new_bofreq(self):
342343
self.assertEqual(bofreq.text_or_error(), 'some stuff')
343344
self.assertEqual(len(outbox),1)
344345
os.unlink(file.name)
345-
existing_bofreq = BofreqFactory()
346+
existing_bofreq = BofreqFactory(requester_lastname=nobody.last_name())
346347
for postdict in [
347348
dict(title='', bofreq_submission='enter', bofreq_content='some stuff'),
348349
dict(title='a title', bofreq_submission='enter', bofreq_content=''),
@@ -351,9 +352,9 @@ def test_start_new_bofreq(self):
351352
dict(title='a title', bofreq_submission='', bofreq_content='some stuff'),
352353
]:
353354
r = self.client.post(url,postdict)
354-
self.assertEqual(r.status_code, 200)
355+
self.assertEqual(r.status_code, 200, f'Wrong status_code for {postdict}')
355356
q = PyQuery(r.content)
356-
self.assertTrue(q('form div.has-error'))
357+
self.assertTrue(q('form div.has-error'), f'Expected an error for {postdict}')
357358

358359
def test_post_proposed_restrictions(self):
359360
states = State.objects.filter(type_id='bofreq').exclude(slug='proposed')

ietf/doc/views_bofreq.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,20 @@ class NewBofreqForm(BofreqUploadForm):
113113
title = forms.CharField(max_length=255)
114114
field_order = ['title','bofreq_submission','bofreq_file','bofreq_content']
115115

116-
def name_from_title(self,title):
117-
name = 'bofreq-' + xslugify(title).replace('_', '-')[:128]
118-
return name
116+
def __init__(self, requester, *args, **kwargs):
117+
self._requester = requester
118+
super().__init__(*args, **kwargs)
119+
120+
def name_from_title(self, title):
121+
requester_slug = xslugify(self._requester.last_name())
122+
title_slug = xslugify(title)
123+
name = f'bofreq-{requester_slug[:64]}-{title_slug[:128]}'
124+
return name.replace('_', '-')
119125

120126
def clean_title(self):
121127
title = self.cleaned_data['title']
122128
name = self.name_from_title(title)
123-
if name == 'bofreq-':
129+
if name == self.name_from_title(''):
124130
raise forms.ValidationError('The filename derived from this title is empty. Please include a few descriptive words using ascii or numeric characters')
125131
if Document.objects.filter(name=name).exists():
126132
raise forms.ValidationError('This title produces a filename already used by an existing BOF request')
@@ -130,7 +136,7 @@ def clean_title(self):
130136
def new_bof_request(request):
131137

132138
if request.method == 'POST':
133-
form = NewBofreqForm(request.POST, request.FILES)
139+
form = NewBofreqForm(request.user.person, request.POST, request.FILES)
134140
if form.is_valid():
135141
title = form.cleaned_data['title']
136142
name = form.name_from_title(title)
@@ -175,7 +181,7 @@ def new_bof_request(request):
175181
init = {'bofreq_content':render_to_string('doc/bofreq/bofreq_template.md',{}),
176182
'bofreq_submission':'enter',
177183
}
178-
form = NewBofreqForm(initial=init)
184+
form = NewBofreqForm(request.user.person, initial=init)
179185
return render(request, 'doc/bofreq/new_bofreq.html',
180186
{'form':form})
181187

ietf/templates/doc/bofreq/new_bofreq.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "base.html" %}
22
{# Copyright The IETF Trust 2021, All Rights Reserved #}
3-
{% load origin bootstrap3 static %}
3+
{% load origin bootstrap3 static textfilters %}
44

55
{% block title %}Start a new BOF Request{% endblock %}
66

@@ -9,7 +9,7 @@
99
<h1>Start a new BOF Request</h1>
1010

1111
<p>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.</p>
12-
<p>For example, a request with a title of "A new important bit" will be saved as "bofreq-a-new-important-bit-00.md".</p>
12+
<p>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".</p>
1313
<form class="upload-content form-horizontal" method="post" enctype="multipart/form-data">
1414
{% csrf_token %}
1515

0 commit comments

Comments
 (0)