Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions ietf/submit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,70 +770,6 @@ def save_files(form):
log.log("saved file %s" % name)
return file_name

def get_draft_meta(form, saved_files):
authors = []
file_name = saved_files

if form.cleaned_data['xml']:
# Some meta-information, such as the page-count, can only
# be retrieved from the generated text file. Provide a
# parsed draft object to get at that kind of information.
file_name['txt'] = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.txt' % (form.filename, form.revision))
file_size = os.stat(file_name['txt']).st_size
with io.open(file_name['txt']) as txt_file:
form.parsed_draft = PlaintextDraft(txt_file.read(), txt_file.name)
else:
file_size = form.cleaned_data['txt'].size

if form.authors:
authors = form.authors
else:
# If we don't have an xml file, try to extract the
# relevant information from the text file
for author in form.parsed_draft.get_author_list():
full_name, first_name, middle_initial, last_name, name_suffix, email, country, company = author

name = full_name.replace("\n", "").replace("\r", "").replace("<", "").replace(">", "").strip()

if email:
try:
validate_email(email)
except ValidationError:
email = ""

def turn_into_unicode(s):
if s is None:
return ""

if isinstance(s, str):
return s
else:
try:
return s.decode("utf-8")
except UnicodeDecodeError:
try:
return s.decode("latin-1")
except UnicodeDecodeError:
return ""

name = turn_into_unicode(name)
email = turn_into_unicode(email)
company = turn_into_unicode(company)

authors.append({
"name": name,
"email": email,
"affiliation": company,
"country": country
})

if form.abstract:
abstract = form.abstract
else:
abstract = form.parsed_draft.get_abstract()

return authors, abstract, file_name, file_size


def get_submission(form):
# See if there is a Submission in state waiting-for-draft
Expand Down
6 changes: 4 additions & 2 deletions ietf/utils/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,20 @@ def get_wordcount(self):

class PlaintextDraft(Draft):

def __init__(self, text, source, name_from_source=False):
def __init__(self, text, source, name_from_source=False, max_line_width=100):
"""Initialize a Draft instance

:param text: plaintext draft contents
:param source: name of file containing the contents
:param name_from_source: if True, fall back to source to determine draft name not found from text
:param max_line_width: (default 100) ignore contents of lines beyond this width
"""
super().__init__()
assert isinstance(text, str)
self.source = str(source)
self.rawtext = text
self.name_from_source = name_from_source
self.max_line_width = max_line_width

text = re.sub(".\x08", "", text) # Get rid of inkribbon backspace-emphasis
text = text.replace("\r\n", "\n") # Convert DOS to unix
Expand Down Expand Up @@ -320,7 +322,7 @@ def begpage(pages, page, newpage, line=None):
return pages, page, newpage
for line in self.rawlines:
linecount += 1
line = line.rstrip()
line = line.rstrip()[:self.max_line_width] # source of lines used elsewhere in the class!
if re.search(r"\[?page [0-9ivx]+\]?[ \t\f]*$", line, re.I):
pages, page, newpage = endpage(pages, page, newpage, line)
continue
Expand Down