Skip to content

Commit 1f976da

Browse files
committed
Third part of document read refactoring, after [14406] and [14410]. This replaces all usage of the non-unicode-aware get_document_content() function with unicode-aware Document.text() or Document.text_or_error() methods. This was triggered by yet another report of unicode content not being shown properly, and should fix all instances of document (drafts, agendas, minutes, etc.) display in the datatracker not handling unicode characters properly.
- Legacy-Id: 14411 Note: SVN reference [14406] has been migrated to Git commit 967ece7 Note: SVN reference [14410] has been migrated to Git commit 660c81c
1 parent 660c81c commit 1f976da

9 files changed

Lines changed: 27 additions & 111 deletions

File tree

ietf/doc/mails.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# generation of mails
22

3-
import os
43
import textwrap, datetime
54

65
from django.template.loader import render_to_string
@@ -13,11 +12,11 @@
1312
from ietf.utils.mail import send_mail, send_mail_text
1413
from ietf.ipr.utils import iprs_from_docs, related_docs
1514
from ietf.doc.models import WriteupDocEvent, LastCallDocEvent, DocAlias, ConsensusDocEvent
16-
from ietf.doc.utils import needed_ballot_positions, get_document_content
15+
from ietf.doc.utils import needed_ballot_positions
1716
from ietf.group.models import Role
1817
from ietf.doc.models import Document
1918
from ietf.mailtrigger.utils import gather_address_lists
20-
from ietf.utils import log
19+
2120

2221
def email_state_changed(request, doc, text, mailtrigger_id=None):
2322
(to,cc) = gather_address_lists(mailtrigger_id or 'doc_state_edited',doc=doc)
@@ -512,18 +511,7 @@ def send_review_possibly_replaces_request(request, doc, submitter_info):
512511

513512
def email_charter_internal_review(request, charter):
514513
addrs = gather_address_lists('charter_internal_review',doc=charter,group=charter.group)
515-
filename = '%s-%s.txt' % (charter.canonical_name(),charter.rev)
516-
charter_text = get_document_content(
517-
filename,
518-
os.path.join(settings.CHARTER_PATH,filename),
519-
split=False,
520-
markup=False,
521-
)
522-
utext = charter.text_or_error() # pyflakes:ignore
523-
if charter_text and charter_text != utext and not 'Error; cannot read' in charter_text:
524-
debug.show('charter_text[:64]')
525-
debug.show('utext[:64]')
526-
log.assertion('charter_text == utext')
514+
charter_text = charter.text_or_error() # pyflakes:ignore
527515

528516
send_mail(request, addrs.to, settings.DEFAULT_FROM_EMAIL,
529517
'Internal %s Review: %s (%s)'%(charter.group.type.name,charter.group.name,charter.group.acronym),

ietf/doc/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ def replaced_by(self):
437437

438438
def text(self):
439439
path = self.get_file_name()
440+
root, ext = os.path.splitext(path)
441+
txtpath = root+'.txt'
442+
if ext != '.txt' and os.path.exists(txtpath):
443+
path = txtpath
440444
try:
441445
with open(path, 'rb') as file:
442446
raw = file.read()
@@ -450,7 +454,7 @@ def text(self):
450454
return text
451455

452456
def text_or_error(self):
453-
return self.text() or "Error; cannot read (%s)"%self.get_file_name()
457+
return self.text() or "Error; cannot read '%s'"%self.get_base_name()
454458

455459
def htmlized(self):
456460
name = self.get_base_name()
@@ -607,7 +611,7 @@ def canonical_name(self):
607611
if not hasattr(self, '_canonical_name'):
608612
name = self.name
609613
if self.type_id == "draft" and self.get_state_slug() == "rfc":
610-
a = self.docalias_set.filter(name__startswith="rfc").first()
614+
a = self.docalias_set.filter(name__startswith="rfc").order_by('-name').first()
611615
if a:
612616
name = a.name
613617
elif self.type_id == "charter":

ietf/doc/templatetags/ietf_filters.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import re
44
import datetime
5-
import os
65
import types
76
from email.utils import parseaddr
87

@@ -16,9 +15,7 @@
1615
import debug # pyflakes:ignore
1716

1817
from ietf.doc.models import ConsensusDocEvent
19-
from ietf.doc.utils import get_document_content
2018
from ietf.utils.text import wordwrap, fill, wrap_text_if_unwrapped
21-
from ietf.utils import log
2219

2320
register = template.Library()
2421

@@ -508,13 +505,7 @@ def emailwrap(email):
508505
def document_content(doc):
509506
if doc is None:
510507
return None
511-
path = os.path.join(doc.get_file_path(),doc.filename_with_rev())
512-
content = get_document_content(doc.name,path,markup=False)
513-
utext = doc.text_or_error() # pyflakes:ignore
514-
if content and content != utext and not 'Error; cannot read' in content:
515-
debug.show('content[:64]')
516-
debug.show('utext[:64]')
517-
log.assertion('content == utext')
508+
content = doc.text_or_error() # pyflakes:ignore
518509
return content
519510

520511
@register.filter

ietf/doc/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ietf.utils import draft, text
2626
from ietf.utils.mail import send_mail
2727
from ietf.mailtrigger.utils import gather_address_lists
28+
from ietf.utils import log
2829

2930
def save_document_in_history(doc):
3031
"""Save a snapshot of document and related objects in the database."""
@@ -299,7 +300,7 @@ def get_unicode_document_content(key, filename, codec='utf-8', errors='ignore'):
299300
return raw_content
300301

301302
def get_document_content(key, filename, split=True, markup=True):
302-
#log.unreachable("2017-12-05")
303+
log.unreachable("2017-12-05")
303304
try:
304305
with open(filename, 'rb') as f:
305306
raw_content = f.read()

ietf/doc/views_conflict_review.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ietf.doc.models import ( BallotDocEvent, BallotPositionDocEvent, DocAlias, DocEvent,
1313
Document, NewRevisionDocEvent, State )
1414
from ietf.doc.utils import ( add_state_change_event, close_open_ballots,
15-
create_ballot_if_not_open, get_document_content, update_telechat )
15+
create_ballot_if_not_open, update_telechat )
1616
from ietf.doc.mails import email_iana
1717
from ietf.doc.forms import AdForm
1818
from ietf.group.models import Role, Group
@@ -253,14 +253,7 @@ def edit_ad(request, name):
253253

254254
def default_approval_text(review):
255255

256-
filename = "%s-%s.txt" % (review.canonical_name(), review.rev)
257-
current_text = get_document_content(filename, os.path.join(settings.CONFLICT_REVIEW_PATH, filename), split=False, markup=False)
258-
utext = review.text_or_error() # pyflakes:ignore
259-
if current_text and current_text != utext and not 'Error; cannot read' in current_text:
260-
debug.show('current_text[:64]')
261-
debug.show('utext[:64]')
262-
log.assertion('current_text == utext')
263-
256+
current_text = review.text_or_error() # pyflakes:ignore
264257
conflictdoc = review.relateddocument_set.get(relationship__slug='conflrev').target.document
265258
if conflictdoc.stream_id=='ise':
266259
receiver = 'Independent Submissions Editor'

ietf/doc/views_doc.py

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent,
4848
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS )
4949
from ietf.doc.utils import ( add_links_in_new_revision_events, augment_events_with_revision,
50-
can_adopt_draft, get_chartering_type, get_document_content, get_tags_for_stream_id,
50+
can_adopt_draft, get_chartering_type, get_tags_for_stream_id,
5151
needed_ballot_positions, nice_consensus, prettify_std_name, update_telechat, has_same_ballot,
5252
get_initial_notify, make_notify_changed_event, make_rev_history, default_consensus,
5353
add_events_message_info, get_unicode_document_content, build_doc_meta_block)
@@ -66,7 +66,7 @@
6666
from ietf.review.models import ReviewRequest
6767
from ietf.review.utils import can_request_review_of_doc, review_requests_to_list_for_docs
6868
from ietf.review.utils import no_review_from_teams_on_doc
69-
from ietf.utils import markup_txt, log
69+
from ietf.utils import markup_txt
7070
from ietf.utils.text import maybe_split
7171

7272

@@ -185,15 +185,7 @@ def document_main(request, name, rev=None):
185185

186186
if doc.get_state_slug() == "rfc":
187187
# content
188-
filename = name + ".txt"
189-
190-
content = get_document_content(filename, os.path.join(settings.RFC_PATH, filename),
191-
split_content, markup=True)
192-
utext = doc.text_or_error() # pyflakes:ignore
193-
if content and content != utext and not 'Error; cannot read' in content:
194-
debug.show('content[:64]')
195-
debug.show('utext[:64]')
196-
log.assertion('content == utext')
188+
content = doc.text_or_error() # pyflakes:ignore
197189
content = markup_txt.markup(maybe_split(content, split=split_content))
198190

199191
# file types
@@ -221,15 +213,7 @@ def document_main(request, name, rev=None):
221213
content = "This RFC is not available in plain text format."
222214
split_content = False
223215
else:
224-
filename = "%s-%s.txt" % (draft_name, doc.rev)
225-
226-
content = get_document_content(filename, os.path.join(settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR, filename),
227-
split_content, markup=True)
228-
utext = doc.text_or_error() # pyflakes:ignore
229-
if content and content != utext and not 'Error; cannot read' in content:
230-
debug.show('content[:64]')
231-
debug.show('utext[:64]')
232-
log.assertion('content == utext')
216+
content = doc.text_or_error() # pyflakes:ignore
233217
content = markup_txt.markup(maybe_split(content, split=split_content))
234218

235219
# file types
@@ -451,14 +435,7 @@ def document_main(request, name, rev=None):
451435
))
452436

453437
if doc.type_id == "charter":
454-
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
455-
456-
content = get_document_content(filename, os.path.join(settings.CHARTER_PATH, filename), split=False, markup=True)
457-
utext = doc.text_or_error() # pyflakes:ignore
458-
if content and content != utext and not 'Error; cannot read' in content:
459-
debug.show('content[:64]')
460-
debug.show('utext[:64]')
461-
log.assertion('content == utext')
438+
content = doc.text_or_error() # pyflakes:ignore
462439
content = markup_txt.markup(content)
463440

464441
ballot_summary = None
@@ -502,12 +479,7 @@ def document_main(request, name, rev=None):
502479
# This could move to a template
503480
content = u"A conflict review response has not yet been proposed."
504481
else:
505-
content = get_document_content(filename, pathname, split=False, markup=True)
506-
utext = doc.text_or_error() # pyflakes:ignore
507-
if content and content != utext and not 'Error; cannot read' in content:
508-
debug.show('content[:64]')
509-
debug.show('utext[:64]')
510-
log.assertion('content == utext')
482+
content = doc.text_or_error() # pyflakes:ignore
511483
content = markup_txt.markup(content)
512484

513485
ballot_summary = None
@@ -535,12 +507,7 @@ def document_main(request, name, rev=None):
535507
# This could move to a template
536508
content = u"Status change text has not yet been proposed."
537509
else:
538-
content = get_document_content(filename, pathname, split=False)
539-
utext = doc.text_or_error() # pyflakes:ignore
540-
if content and content != utext and not 'Error; cannot read' in content:
541-
debug.show('content[:64]')
542-
debug.show('utext[:64]')
543-
log.assertion('content == utext')
510+
content = doc.text_or_error() # pyflakes:ignore
544511

545512
ballot_summary = None
546513
if doc.get_state_slug() in ("iesgeval"):
@@ -593,12 +560,7 @@ def document_main(request, name, rev=None):
593560
url = urlbase + extension
594561

595562
if extension == ".txt":
596-
content = get_document_content(basename, pathname + extension, split=False)
597-
utext = doc.text_or_error() # pyflakes:ignore
598-
if content != utext:
599-
debug.show('content[:64]')
600-
debug.show('utext[:64]')
601-
log.assertion('content == utext')
563+
content = doc.text_or_error() # pyflakes:ignore
602564
t = "plain text"
603565

604566
other_types.append((t, url))

ietf/doc/views_status_change.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
BallotPositionDocEvent, NewRevisionDocEvent, WriteupDocEvent, STATUSCHANGE_RELATIONS )
1414
from ietf.doc.forms import AdForm
1515
from ietf.doc.lastcall import request_last_call
16-
from ietf.doc.utils import get_document_content, add_state_change_event, update_telechat, close_open_ballots, create_ballot_if_not_open
16+
from ietf.doc.utils import add_state_change_event, update_telechat, close_open_ballots, create_ballot_if_not_open
1717
from ietf.doc.views_ballot import LastCallTextForm
1818
from ietf.group.models import Group
1919
from ietf.iesg.models import TelechatDate
@@ -281,13 +281,7 @@ def newstatus(relateddoc):
281281

282282
def default_approval_text(status_change,relateddoc):
283283

284-
filename = "%s-%s.txt" % (status_change.canonical_name(), status_change.rev)
285-
current_text = get_document_content(filename, os.path.join(settings.STATUS_CHANGE_PATH, filename), split=False, markup=False)
286-
utext = status_change.text_or_error() # pyflakes:ignore
287-
if current_text and current_text != utext and not 'Error; cannot read' in current_text:
288-
debug.show('current_text[:64]')
289-
debug.show('utext[:64]')
290-
log.assertion('current_text == utext')
284+
current_text = status_change.text_or_error() # pyflakes:ignore
291285

292286
if relateddoc.target.document.std_level.slug in ('std','ps','ds','bcp',):
293287
action = "Protocol Action"

ietf/meeting/forms.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import debug # pyflakes:ignore
1010

1111
from ietf.doc.models import Document, DocAlias, State, NewRevisionDocEvent
12-
from ietf.doc.utils import get_document_content
1312
from ietf.group.models import Group
1413
from ietf.ietfauth.utils import has_role
1514
from ietf.meeting.models import Session, Meeting, Schedule, countries, timezones
@@ -18,7 +17,6 @@
1817
from ietf.message.models import Message
1918
from ietf.person.models import Person
2019
from ietf.utils.fields import DatepickerDateField, DurationField
21-
from ietf.utils import log
2220

2321
# need to insert empty option for use in ChoiceField
2422
# countries.insert(0, ('', '-'*9 ))
@@ -220,13 +218,7 @@ def __init__(self, *args, **kwargs):
220218
self.initial['time'] = self.instance.official_timeslotassignment().timeslot.time
221219
if self.instance.agenda():
222220
doc = self.instance.agenda()
223-
path = os.path.join(doc.get_file_path(), doc.filename_with_rev())
224-
content = get_document_content(os.path.basename(path), path, markup=False)
225-
utext = doc.text_or_error() # pyflakes:ignore
226-
if content and content != utext and not 'Error; cannot read' in content:
227-
debug.show('content[:64]')
228-
debug.show('utext[:64]')
229-
log.assertion('content == utext')
221+
content = doc.text_or_error()
230222
self.initial['agenda'] = content
231223

232224

ietf/secr/telechat/views.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import datetime
32

43
from django.contrib import messages
@@ -9,16 +8,14 @@
98
import debug # pyflakes:ignore
109

1110
from ietf.doc.models import DocEvent, Document, BallotDocEvent, BallotPositionDocEvent, BallotType, WriteupDocEvent
12-
from ietf.doc.utils import get_document_content, add_state_change_event
11+
from ietf.doc.utils import add_state_change_event
1312
from ietf.person.models import Person
1413
from ietf.doc.lastcall import request_last_call
1514
from ietf.doc.mails import email_state_changed
1615
from ietf.iesg.models import TelechatDate, TelechatAgendaItem, Telechat
1716
from ietf.iesg.agenda import agenda_data, get_doc_section
1817
from ietf.ietfauth.utils import role_required
1918
from ietf.secr.telechat.forms import BallotForm, ChangeStateForm, DateSelectForm, TELECHAT_TAGS
20-
from ietf.utils import log
21-
2219

2320
'''
2421
EXPECTED CHANGES:
@@ -71,13 +68,7 @@ def get_doc_writeup(doc):
7168
if latest:
7269
writeup = latest.text
7370
elif doc.type_id == 'conflrev':
74-
path = os.path.join(doc.get_file_path(),doc.filename_with_rev())
75-
writeup = get_document_content(doc.name,path,split=False,markup=False)
76-
utext = doc.text_or_error() # pyflakes:ignore
77-
if writeup and writeup != utext and not 'Error; cannot read' in writeup:
78-
debug.show('writeup[:64]')
79-
debug.show('utext[:64]')
80-
log.assertion('writeup == utext')
71+
writeup = doc.text_or_error() # pyflakes:ignore
8172
return writeup
8273

8374
def get_last_telechat_date():

0 commit comments

Comments
 (0)