Skip to content

Commit a3f59ee

Browse files
committed
Added conversion of version 3 XML draft submissions to v3 HTML, in addition to text. Added a link to HTML versions (when present) to the document status page, and renamed the link to the htmlized version to 'htmlized'. Converted the submission XML test-file to version 3. Added test code to check that HTML is generated for version 3 XML submissions.
- Legacy-Id: 16737
1 parent 2c72d33 commit a3f59ee

6 files changed

Lines changed: 62 additions & 37 deletions

File tree

ietf/doc/views_doc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def document_main(request, name, rev=None):
206206

207207
# file types
208208
base_path = os.path.join(settings.RFC_PATH, name + ".")
209-
possible_types = ["txt", "pdf", "ps"]
209+
possible_types = settings.RFC_FILE_TYPES
210210
found_types = [t for t in possible_types if os.path.exists(base_path + t)]
211211

212212
base = "https://www.rfc-editor.org/rfc/"
@@ -220,7 +220,7 @@ def document_main(request, name, rev=None):
220220
file_urls.append(("pdf", base + "pdfrfc/" + name + ".txt.pdf"))
221221

222222
if "txt" in found_types:
223-
file_urls.append(("html", settings.TOOLS_ID_HTML_URL + name))
223+
file_urls.append(("htmlized", settings.TOOLS_ID_HTML_URL + name))
224224
if doc.tags.filter(slug="errata"):
225225
file_urls.append(("with errata", settings.RFC_EDITOR_INLINE_ERRATA_URL.format(rfc_number=rfc_number)))
226226

@@ -236,8 +236,8 @@ def document_main(request, name, rev=None):
236236

237237
# file types
238238
base_path = os.path.join(settings.INTERNET_DRAFT_PATH, doc.name + "-" + doc.rev + ".")
239-
possible_types = ["pdf", "xml", "ps"]
240-
found_types = ["txt"] + [t for t in possible_types if os.path.exists(base_path + t)]
239+
possible_types = settings.IDSUBMIT_FILE_TYPES
240+
found_types = [t for t in possible_types if os.path.exists(base_path + t)]
241241

242242
if not snapshot and doc.get_state_slug() == "active":
243243
base = settings.IETF_ID_URL
@@ -251,7 +251,7 @@ def document_main(request, name, rev=None):
251251

252252
if "pdf" not in found_types:
253253
file_urls.append(("pdf", settings.TOOLS_ID_PDF_URL + doc.name + "-" + doc.rev + ".pdf"))
254-
file_urls.append(("html", settings.TOOLS_ID_HTML_URL + doc.name + "-" + doc.rev))
254+
file_urls.append(("htmlized", settings.TOOLS_ID_HTML_URL + doc.name + "-" + doc.rev))
255255

256256
# latest revision
257257
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")

ietf/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,17 @@ def skip_unreadable_post(record):
782782

783783
IDSUBMIT_FILE_TYPES = (
784784
'txt',
785+
'html',
785786
'xml',
786787
'pdf',
787788
'ps',
788789
)
790+
RFC_FILE_TYPES = IDSUBMIT_FILE_TYPES
791+
789792
IDSUBMIT_MAX_DRAFT_SIZE = {
790793
'txt': 2*1024*1024, # Max size of txt draft file in bytes
791794
'xml': 3*1024*1024, # Max size of xml draft file in bytes
795+
'html': 4*1024*1024,
792796
'pdf': 6*1024*1024,
793797
'ps' : 6*1024*1024,
794798
}

ietf/submit/forms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,16 @@ def deduce_group(self):
352352
class SubmissionManualUploadForm(SubmissionBaseUploadForm):
353353
xml = forms.FileField(label='.xml format', required=False) # xml field with required=False instead of True
354354
txt = forms.FileField(label='.txt format', required=False)
355+
# We won't permit html upload until we can verify that the content
356+
# reasonably matches the text and/or xml upload. Till then, we generate
357+
# html for version 3 xml submissions.
358+
# html = forms.FileField(label='.html format', required=False)
355359
pdf = forms.FileField(label='.pdf format', required=False)
356360
ps = forms.FileField(label='.ps format', required=False)
357361

358362
def __init__(self, request, *args, **kwargs):
359363
super(SubmissionManualUploadForm, self).__init__(request, *args, **kwargs)
360-
self.formats = ['txt', 'pdf', 'xml', 'ps', ]
364+
self.formats = settings.IDSUBMIT_FILE_TYPES
361365
self.base_formats = ['txt', 'xml', ]
362366

363367
def clean_txt(self):

ietf/submit/test_submission.xml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" []>
2+
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">
33
<?rfc toc="yes"?>
4-
<rfc category="info" docName="%(name)s" ipr="trust200902">
4+
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="info" docName="%(name)s" ipr="trust200902" obsoletes="" updates="" submissionType="IETF" xml:lang="en" version="3">
55
<front>
66
<title>%(title)s</title>
7+
<seriesInfo name="Internet-Draft" value="%(name)s"/>
78
<author fullname="%(author)s" initials="%(initials)s" surname="%(surname)s">
89
<organization>Test Centre Inc.</organization>
9-
1010
<address>
1111
<postal>
1212
<street>42 Some Road</street>
@@ -16,26 +16,24 @@
1616
<email>%(email)s</email>
1717
</address>
1818
</author>
19-
<date month="%(month)s" year="%(year)s" />
19+
<date day="%(day)s" month="%(month)s" year="%(year)s"/>
2020
<workgroup>%(group)s</workgroup>
2121
<abstract>
2222
<t>
2323
This document describes how to test tests.
2424
</t>
2525
</abstract>
2626
</front>
27-
2827
<middle>
29-
<section title="Introduction">
28+
<section numbered="true" toc="default">
29+
<name>Introduction</name>
3030
<t>
3131
This document describes a protocol for testing tests.
3232
</t>
3333
</section>
34-
<section title="Yang">
35-
<figure>
36-
<artwork>
37-
<![CDATA[
38-
<CODE BEGINS> file "ietf-yang-metadata@2016-08-05.yang"
34+
<section numbered="true" toc="default">
35+
<name>Yang</name>
36+
<sourcecode name="ietf-yang-metadata@2016-08-05.yang" type="" markers="true"><![CDATA[
3937
4038
module ietf-yang-metadata {
4139
@@ -122,13 +120,10 @@ module ietf-yang-metadata {
122120
}
123121
}
124122
125-
<CODE ENDS>
126-
]]>
127-
</artwork>
128-
</figure>
123+
]]></sourcecode>
129124
</section>
130-
131-
<section anchor="JSON" title="JSON example">
125+
<section anchor="JSON" numbered="true" toc="default">
126+
<name>JSON example</name>
132127
<t>
133128
The JSON object should look like this:
134129

@@ -137,17 +132,18 @@ module ietf-yang-metadata {
137132
}
138133
</t>
139134
</section>
140-
<section anchor="Security" title="Security Considerations">
135+
<section anchor="Security" numbered="true" toc="default">
136+
<name>Security Considerations</name>
141137
<t>
142138
There are none.
143139
</t>
144140
</section>
145-
<section anchor="IANA" title="IANA Considerations">
141+
<section anchor="IANA" numbered="true" toc="default">
142+
<name>IANA Considerations</name>
146143
<t>
147144
No new registrations for IANA.
148145
</t>
149146
</section>
150147
</middle>
151-
<back>
152-
</back>
148+
<back/>
153149
</rfc>

ietf/submit/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def submission_file(name, rev, group, format, templatename, author=None, email=N
6464
expiration=(datetime.date.today() + datetime.timedelta(days=100)).strftime("%d %B, %Y"),
6565
year=year,
6666
month=datetime.date.today().strftime("%B"),
67+
day=datetime.date.today().strftime("%d"),
6768
name="%s-%s" % (name, rev),
6869
group=group or "",
6970
author=author.ascii if ascii else author.name,
@@ -151,6 +152,8 @@ def do_submission(self, name, rev, group=None, formats=["txt",], author=None):
151152
status_url = r["Location"]
152153
for format in formats:
153154
self.assertTrue(os.path.exists(os.path.join(self.staging_dir, "%s-%s.%s" % (name, rev, format))))
155+
if format == 'xml':
156+
self.assertTrue(os.path.exists(os.path.join(self.staging_dir, "%s-%s.%s" % (name, rev, 'html'))))
154157
self.assertEqual(Submission.objects.filter(name=name).count(), 1)
155158
submission = Submission.objects.get(name=name)
156159
if len(submission.authors) != 1:
@@ -1684,7 +1687,7 @@ def test_api_submit_no_title(self):
16841687
self.assertContains(r, expected, status_code=400)
16851688

16861689
def test_api_submit_failed_idnits(self):
1687-
r, author, name = self.post_submission('00', year="1900")
1690+
r, author, name = self.post_submission('00', year="2010")
16881691
expected = "Document date must be within 3 days of submission date"
16891692
self.assertContains(r, expected, status_code=400)
16901693

ietf/submit/utils.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,14 @@ def cancel_submission(submission):
528528
remove_submission_files(submission)
529529

530530
def rename_submission_files(submission, prev_rev, new_rev):
531-
from ietf.submit.forms import SubmissionManualUploadForm
532-
for ext in list(SubmissionManualUploadForm.base_fields.keys()):
531+
for ext in settings.IDSUBMIT_FILE_TYPES:
533532
source = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.%s' % (submission.name, prev_rev, ext))
534533
dest = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.%s' % (submission.name, new_rev, ext))
535534
if os.path.exists(source):
536535
os.rename(source, dest)
537536

538537
def move_files_to_repository(submission):
539-
from ietf.submit.forms import SubmissionManualUploadForm
540-
for ext in list(SubmissionManualUploadForm.base_fields.keys()):
538+
for ext in settings.IDSUBMIT_FILE_TYPES:
541539
source = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.%s' % (submission.name, submission.rev, ext))
542540
dest = os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, '%s-%s.%s' % (submission.name, submission.rev, ext))
543541
if os.path.exists(source):
@@ -622,18 +620,24 @@ def get_draft_meta(form, saved_files):
622620
file_name = saved_files
623621
abstract = None
624622
file_size = None
623+
xml2rfc.log.write_out = open(os.devnull, "w")
624+
xml2rfc.log.write_err = open(os.devnull, "w")
625625
if form.cleaned_data['xml']:
626+
try:
627+
xmlroot = form.xmltree.getroot()
628+
xml_version = xmlroot.get('version', '2')
629+
if xml_version == '3':
630+
prep = xml2rfc.PrepToolWriter(form.xmltree, quiet=True)
631+
form.xmltree.tree = prep.prep()
632+
except Exception as e:
633+
raise ValidationError("Error from xml2rfc (prep): %s" % e)
626634
if not ('txt' in form.cleaned_data and form.cleaned_data['txt']):
627635
file_name['txt'] = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.txt' % (form.filename, form.revision))
628636
try:
629-
xmlroot = form.xmltree.getroot()
630-
xml_version = xmlroot.get('version', '2')
631637
if xml_version != '3':
632638
pagedwriter = xml2rfc.PaginatedTextRfcWriter(form.xmltree, quiet=True)
633639
pagedwriter.write(file_name['txt'])
634640
else:
635-
prep = xml2rfc.PrepToolWriter(form.xmltree, quiet=True)
636-
form.xmltree.tree = prep.prep()
637641
writer = xml2rfc.TextWriter(form.xmltree, quiet=True)
638642
writer.write(file_name['txt'])
639643
log.log("In %s: xml2rfc %s generated %s from %s (version %s)" %
@@ -643,8 +647,22 @@ def get_draft_meta(form, saved_files):
643647
os.path.basename(file_name['xml']),
644648
xml_version))
645649
except Exception as e:
646-
raise ValidationError("Error from xml2rfc: %s" % e)
650+
raise ValidationError("Error from xml2rfc (text): %s" % e)
647651
file_size = os.stat(file_name['txt']).st_size
652+
if xml_version == '3':
653+
try:
654+
file_name['html'] = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.html' % (form.filename, form.revision))
655+
writer = xml2rfc.HtmlWriter(form.xmltree, quiet=True)
656+
writer.write(file_name['html'])
657+
form.file_types.append('.html')
658+
log.log("In %s: xml2rfc %s generated %s from %s (version %s)" %
659+
( os.path.dirname(file_name['xml']),
660+
xml2rfc.__version__,
661+
os.path.basename(file_name['html']),
662+
os.path.basename(file_name['xml']),
663+
xml_version))
664+
except Exception as e:
665+
raise ValidationError("Error from xml2rfc (html): %s" % e)
648666
# Some meta-information, such as the page-count, can only
649667
# be retrieved from the generated text file. Provide a
650668
# parsed draft object to get at that kind of information.

0 commit comments

Comments
 (0)