Skip to content

Commit 2daff23

Browse files
committed
Remove shim layer from submit code
- Legacy-Id: 6654
1 parent e1708da commit 2daff23

6 files changed

Lines changed: 117 additions & 329 deletions

File tree

ietf/submit/forms.py

Lines changed: 58 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import debug
1616

17-
from ietf.group.models import Group
18-
from ietf.idtracker.models import InternetDraft, IETFWG
19-
from ietf.proceedings.models import Meeting
17+
from ietf.group.models import Group, Role
18+
from ietf.doc.models import Document
19+
from ietf.meeting.models import Meeting
2020
from ietf.submit.models import IdSubmissionDetail, TempIdAuthors, Preapproval
21-
from ietf.submit.utils import MANUAL_POST_REQUESTED, NONE_WG, UPLOADED, AWAITING_AUTHENTICATION, POSTED, POSTED_BY_SECRETARIAT
21+
from ietf.submit.utils import MANUAL_POST_REQUESTED, UPLOADED, AWAITING_AUTHENTICATION, POSTED, POSTED_BY_SECRETARIAT, submission_confirmation_email_list
2222
from ietf.submit.parsers.pdf_parser import PDFParser
2323
from ietf.submit.parsers.plain_parser import PlainParser
2424
from ietf.submit.parsers.ps_parser import PSParser
@@ -154,30 +154,30 @@ def check_tresholds(self):
154154
same_name = IdSubmissionDetail.objects.filter(filename=filename, revision=revision, submission_date=today)
155155
if same_name.count() > settings.MAX_SAME_DRAFT_NAME:
156156
raise forms.ValidationError('The same I-D cannot be submitted more than %s times a day' % settings.MAX_SAME_DRAFT_NAME)
157-
if sum([i.filesize for i in same_name]) > (settings.MAX_SAME_DRAFT_NAME_SIZE * 1048576):
157+
if sum(i.filesize for i in same_name) > settings.MAX_SAME_DRAFT_NAME_SIZE * 1048576:
158158
raise forms.ValidationError('The same I-D submission cannot exceed more than %s MByte a day' % settings.MAX_SAME_DRAFT_NAME_SIZE)
159159

160160
# Total from same ip
161161
same_ip = IdSubmissionDetail.objects.filter(remote_ip=remote_ip, submission_date=today)
162162
if same_ip.count() > settings.MAX_SAME_SUBMITTER:
163163
raise forms.ValidationError('The same submitter cannot submit more than %s I-Ds a day' % settings.MAX_SAME_SUBMITTER)
164-
if sum([i.filesize for i in same_ip]) > (settings.MAX_SAME_SUBMITTER_SIZE * 1048576):
164+
if sum(i.filesize for i in same_ip) > settings.MAX_SAME_SUBMITTER_SIZE * 1048576:
165165
raise forms.ValidationError('The same submitter cannot exceed more than %s MByte a day' % settings.MAX_SAME_SUBMITTER_SIZE)
166166

167167
# Total in same group
168168
if self.group:
169169
same_group = IdSubmissionDetail.objects.filter(group_acronym=self.group, submission_date=today)
170170
if same_group.count() > settings.MAX_SAME_WG_DRAFT:
171171
raise forms.ValidationError('The same working group I-Ds cannot be submitted more than %s times a day' % settings.MAX_SAME_WG_DRAFT)
172-
if sum([i.filesize for i in same_group]) > (settings.MAX_SAME_WG_DRAFT_SIZE * 1048576):
172+
if sum(i.filesize for i in same_group) > settings.MAX_SAME_WG_DRAFT_SIZE * 1048576:
173173
raise forms.ValidationError('Total size of same working group I-Ds cannot exceed %s MByte a day' % settings.MAX_SAME_WG_DRAFT_SIZE)
174174

175175

176176
# Total drafts for today
177177
total_today = IdSubmissionDetail.objects.filter(submission_date=today)
178178
if total_today.count() > settings.MAX_DAILY_SUBMISSION:
179179
raise forms.ValidationError('The total number of today\'s submission has reached the maximum number of submission per day')
180-
if sum([i.filesize for i in total_today]) > (settings.MAX_DAILY_SUBMISSION_SIZE * 1048576):
180+
if sum(i.filesize for i in total_today) > settings.MAX_DAILY_SUBMISSION_SIZE * 1048576:
181181
raise forms.ValidationError('The total size of today\'s submission has reached the maximum size of submission per day')
182182

183183
def check_paths(self):
@@ -234,10 +234,10 @@ def check_idnits(self):
234234

235235
def get_working_group(self):
236236
name = self.draft.filename
237-
existing_draft = InternetDraft.objects.filter(filename=name)
237+
existing_draft = Document.objects.filter(name=name, type="draft")
238238
if existing_draft:
239-
group = existing_draft[0].group and existing_draft[0].group.ietfwg or None
240-
if group and group.pk != NONE_WG and group.type_id != "area":
239+
group = existing_draft[0].group
240+
if group and group.type_id not in ("individ", "area"):
241241
return group
242242
else:
243243
return None
@@ -255,25 +255,18 @@ def get_working_group(self):
255255
# first check groups with dashes
256256
for g in Group.objects.filter(acronym__contains="-", type=group_type):
257257
if name.startswith('draft-%s-%s-' % (components[1], g.acronym)):
258-
return IETFWG().from_object(g)
258+
return g
259259

260260
try:
261-
return IETFWG().from_object(Group.objects.get(acronym=components[2], type=group_type))
261+
return Group.objects.get(acronym=components[2], type=group_type)
262262
except Group.DoesNotExist:
263263
raise forms.ValidationError('There is no active group with acronym \'%s\', please rename your draft' % components[2])
264264
elif name.startswith("draft-iab-"):
265-
return IETFWG().from_object(Group.objects.get(acronym="iab"))
265+
return Group.objects.get(acronym="iab")
266266
else:
267267
return None
268268

269269
def save_draft_info(self, draft):
270-
document_id = 0
271-
existing_draft = InternetDraft.objects.filter(filename=draft.filename)
272-
if existing_draft:
273-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
274-
document_id = -1
275-
else:
276-
document_id = existing_draft[0].id_document_tag
277270
detail = IdSubmissionDetail.objects.create(
278271
id_document_name=draft.get_title(),
279272
filename=draft.filename,
@@ -283,46 +276,29 @@ def save_draft_info(self, draft):
283276
creation_date=draft.get_creation_date(),
284277
submission_date=datetime.date.today(),
285278
idnits_message=self.idnits_message,
286-
temp_id_document_tag=document_id,
279+
temp_id_document_tag=-1,
287280
group_acronym=self.group,
288281
remote_ip=self.remote_ip,
289282
first_two_pages=''.join(draft.pages[:2]),
290283
status_id=UPLOADED,
291284
abstract=draft.get_abstract(),
292285
file_type=','.join(self.file_type),
293286
)
294-
order = 0
295-
for author in draft.get_author_list():
287+
for order, author in enumerate(draft.get_author_list(), start=1):
296288
full_name, first_name, middle_initial, last_name, name_suffix, email, company = author
297-
order += 1
298-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
299-
# save full name
300-
TempIdAuthors.objects.create(
301-
id_document_tag=document_id,
302-
first_name=full_name.strip(),
303-
email_address=(email or "").strip(),
304-
author_order=order,
305-
submission=detail)
306-
else:
307-
TempIdAuthors.objects.create(
308-
id_document_tag=document_id,
309-
first_name=first_name,
310-
middle_initial=middle_initial,
311-
last_name=last_name,
312-
name_suffix=name_suffix,
313-
email_address=email,
314-
author_order=order,
315-
submission=detail)
289+
# save full name
290+
TempIdAuthors.objects.create(
291+
id_document_tag=-1,
292+
first_name=full_name.strip(),
293+
email_address=(email or "").strip(),
294+
author_order=order,
295+
submission=detail)
316296
return detail
317297

318298

319299
class AutoPostForm(forms.Form):
320300

321-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
322-
name = forms.CharField(required=True)
323-
else:
324-
first_name = forms.CharField(label=u'Given name', required=True)
325-
last_name = forms.CharField(label=u'Last name', required=True)
301+
name = forms.CharField(required=True)
326302
email = forms.EmailField(label=u'Email address', required=True)
327303

328304
def __init__(self, *args, **kwargs):
@@ -332,26 +308,12 @@ def __init__(self, *args, **kwargs):
332308
super(AutoPostForm, self).__init__(*args, **kwargs)
333309

334310
def get_author_buttons(self):
335-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
336-
buttons = []
337-
for i in self.validation.authors:
338-
buttons.append('<input type="button" data-name="%(name)s" data-email="%(email)s" value="%(name)s" />'
339-
% dict(name=i.get_full_name(),
340-
email=i.email()[1] or ''))
341-
return "".join(buttons)
342-
343-
344-
# this should be moved to a Javascript file and attributes like data-first-name ...
345-
button_template = '<input type="button" onclick="jQuery(\'#id_first_name\').val(\'%(first_name)s\');jQuery(\'#id_last_name\').val(\'%(last_name)s\');jQuery(\'#id_email\').val(\'%(email)s\');" value="%(full_name)s" />'
346-
347311
buttons = []
348312
for i in self.validation.authors:
349-
full_name = u'%s. %s' % (i.first_name[0], i.last_name)
350-
buttons.append(button_template % {'first_name': i.first_name,
351-
'last_name': i.last_name,
352-
'email': i.email()[1] or '',
353-
'full_name': full_name})
354-
return ''.join(buttons)
313+
buttons.append('<input type="button" data-name="%(name)s" data-email="%(email)s" value="%(name)s" />'
314+
% dict(name=i.get_full_name(),
315+
email=i.email()[1] or ''))
316+
return "".join(buttons)
355317

356318
def save(self, request):
357319
self.save_submitter_info()
@@ -361,7 +323,7 @@ def save(self, request):
361323
def send_confirmation_mail(self, request):
362324
subject = 'Confirmation for Auto-Post of I-D %s' % self.draft.filename
363325
from_email = settings.IDSUBMIT_FROM_EMAIL
364-
to_email = self.draft.confirmation_email_list()
326+
to_email = submission_confirmation_email_list(self.draft)
365327

366328
confirm_url = settings.IDTRACKER_BASE_URL + urlreverse('draft_confirm', kwargs=dict(submission_id=self.draft.submission_id, auth_key=self.draft.auth_key))
367329
status_url = settings.IDTRACKER_BASE_URL + urlreverse('draft_status_by_hash', kwargs=dict(submission_id=self.draft.submission_id, submission_hash=self.draft.get_hash()))
@@ -370,21 +332,13 @@ def send_confirmation_mail(self, request):
370332
{ 'draft': self.draft, 'confirm_url': confirm_url, 'status_url': status_url })
371333

372334
def save_submitter_info(self):
373-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
374-
return TempIdAuthors.objects.create(
375-
id_document_tag=self.draft.temp_id_document_tag,
376-
first_name=self.cleaned_data['name'],
377-
email_address=self.cleaned_data['email'],
378-
author_order=0,
379-
submission=self.draft)
380-
381335
return TempIdAuthors.objects.create(
382336
id_document_tag=self.draft.temp_id_document_tag,
383-
first_name=self.cleaned_data['first_name'],
384-
last_name=self.cleaned_data['last_name'],
337+
first_name=self.cleaned_data['name'],
385338
email_address=self.cleaned_data['email'],
386339
author_order=0,
387-
submission=self.draft)
340+
submission=self.draft,
341+
)
388342

389343
def save_new_draft_info(self):
390344
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
@@ -400,18 +354,11 @@ class MetaDataForm(AutoPostForm):
400354
creation_date = forms.DateField(label=u'Creation date', required=True)
401355
pages = forms.IntegerField(label=u'Pages', required=True)
402356
abstract = forms.CharField(label=u'Abstract', widget=forms.Textarea, required=True)
403-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
404-
name = forms.CharField(required=True)
405-
else:
406-
first_name = forms.CharField(label=u'Given name', required=True)
407-
last_name = forms.CharField(label=u'Last name', required=True)
357+
name = forms.CharField(required=True)
408358
email = forms.EmailField(label=u'Email address', required=True)
409359
comments = forms.CharField(label=u'Comments to the secretariat', widget=forms.Textarea, required=False)
410360

411-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
412-
fields = ['title', 'version', 'creation_date', 'pages', 'abstract', 'name', 'email', 'comments']
413-
else:
414-
fields = ['title', 'version', 'creation_date', 'pages', 'abstract', 'first_name', 'last_name', 'email', 'comments']
361+
fields = ['title', 'version', 'creation_date', 'pages', 'abstract', 'name', 'email', 'comments']
415362

416363
def __init__(self, *args, **kwargs):
417364
super(MetaDataForm, self).__init__(*args, **kwargs)
@@ -422,43 +369,21 @@ def get_initial_authors(self):
422369
authors=[]
423370
if self.is_bound:
424371
for key, value in self.data.items():
425-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
426-
if key.startswith('name_'):
427-
author = {'errors': {}}
428-
index = key.replace('name_', '')
429-
name = value.strip()
430-
if not name:
431-
author['errors']['name'] = 'This field is required'
432-
email = self.data.get('email_%s' % index, '').strip()
433-
if email and not email_re.search(email):
434-
author['errors']['email'] = 'Enter a valid e-mail address'
435-
if name or email:
436-
author.update({'get_full_name': name,
437-
'email': (name, email),
438-
'index': index,
439-
})
440-
authors.append(author)
441-
442-
else:
443-
if key.startswith('first_name_'):
444-
author = {'errors': {}}
445-
index = key.replace('first_name_', '')
446-
first_name = value.strip()
447-
if not first_name:
448-
author['errors']['first_name'] = 'This field is required'
449-
last_name = self.data.get('last_name_%s' % index, '').strip()
450-
if not last_name:
451-
author['errors']['last_name'] = 'This field is required'
452-
email = self.data.get('email_%s' % index, '').strip()
453-
if email and not email_re.search(email):
454-
author['errors']['email'] = 'Enter a valid e-mail address'
455-
if first_name or last_name or email:
456-
author.update({'first_name': first_name,
457-
'last_name': last_name,
458-
'email': ('%s %s' % (first_name, last_name), email),
459-
'index': index,
460-
})
461-
authors.append(author)
372+
if key.startswith('name_'):
373+
author = {'errors': {}}
374+
index = key.replace('name_', '')
375+
name = value.strip()
376+
if not name:
377+
author['errors']['name'] = 'This field is required'
378+
email = self.data.get('email_%s' % index, '').strip()
379+
if email and not email_re.search(email):
380+
author['errors']['email'] = 'Enter a valid e-mail address'
381+
if name or email:
382+
author.update({'get_full_name': name,
383+
'email': (name, email),
384+
'index': index,
385+
})
386+
authors.append(author)
462387
authors.sort(key=lambda x: x['index'])
463388
return authors
464389

@@ -491,7 +416,7 @@ def clean_version(self):
491416
raise forms.ValidationError('Version field is not in NN format')
492417
if version_int > 99 or version_int < 0:
493418
raise forms.ValidationError('Version must be set between 00 and 99')
494-
existing_revisions = [int(i.revision_display()) for i in InternetDraft.objects.filter(filename=self.draft.filename)]
419+
existing_revisions = [int(i.rev) for i in Document.objects.filter(name=self.draft.filename)]
495420
expected = 0
496421
if existing_revisions:
497422
expected = max(existing_revisions) + 1
@@ -536,14 +461,12 @@ def save_new_draft_info(self):
536461
self.save_submitter_info() # submitter is author 0
537462

538463
for i, author in enumerate(self.authors):
539-
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
540-
# save full name
541-
TempIdAuthors.objects.create(
542-
id_document_tag=draft.temp_id_document_tag,
543-
first_name=author["get_full_name"],
544-
email_address=author["email"][1],
545-
author_order=i + 1,
546-
submission=draft)
464+
TempIdAuthors.objects.create(
465+
id_document_tag=draft.temp_id_document_tag,
466+
first_name=author["get_full_name"], # save full name
467+
email_address=author["email"][1],
468+
author_order=i + 1,
469+
submission=draft)
547470

548471
def save(self, request):
549472
self.save_new_draft_info()
@@ -556,7 +479,7 @@ def send_mail_to_secretariat(self, request):
556479
cc = [self.cleaned_data['email']]
557480
cc += [i['email'][1] for i in self.authors]
558481
if self.draft.group_acronym:
559-
cc += [i.person.email()[1] for i in self.draft.group_acronym.wgchair_set.all()]
482+
cc += [r.email.address for r in Role.objects.filter(group=self.draft.group_acronym, name="chair").select_related("email")]
560483
cc = list(set(cc))
561484
submitter = self.draft.tempidauthors_set.get(author_order=0)
562485
send_mail(request, to_email, from_email, subject, 'submit/manual_post_mail.txt', {
@@ -588,7 +511,7 @@ def clean_name(self):
588511
raise forms.ValidationError("Name ends with a dash.")
589512
acronym = components[2]
590513
if acronym not in self.groups.values_list('acronym', flat=True):
591-
raise forms.ValidationError("WG acronym not recognized as one you can approve drafts for.")
514+
raise forms.ValidationError("Group acronym not recognized as one you can approve drafts for.")
592515

593516
if Preapproval.objects.filter(name=n):
594517
raise forms.ValidationError("Pre-approval for this name already exists.")

0 commit comments

Comments
 (0)