Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor build_file_urls() #5886

Merged
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
30 changes: 14 additions & 16 deletions ietf/doc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,11 @@ def get_search_cache_key(params):
kwargs = dict([ (k,v) for (k,v) in list(params.items()) if k in fields ])
key = "doc:document:search:" + hashlib.sha512(json.dumps(kwargs, sort_keys=True).encode('utf-8')).hexdigest()
return key

def build_file_urls(doc: Union[Document, DocHistory]):
if doc.type_id not in ['draft', 'rfc']:
return [], []


def build_file_urls(doc: Union[Document, DocHistory]):
if doc.type_id == "rfc":
name = doc.canonical_name()
base_path = os.path.join(settings.RFC_PATH, name + ".")
base_path = os.path.join(settings.RFC_PATH, doc.name + ".")
possible_types = settings.RFC_FILE_TYPES
found_types = [t for t in possible_types if os.path.exists(base_path + t)]

Expand All @@ -1014,17 +1011,17 @@ def build_file_urls(doc: Union[Document, DocHistory]):
file_urls = []
for t in found_types:
label = "plain text" if t == "txt" else t
file_urls.append((label, base + name + "." + t))
file_urls.append((label, base + doc.name + "." + t))

if "pdf" not in found_types and "txt" in found_types:
file_urls.append(("pdf", base + "pdfrfc/" + name + ".txt.pdf"))
file_urls.append(("pdf", base + "pdfrfc/" + doc.name + ".txt.pdf"))

if "txt" in found_types:
file_urls.append(("htmlized", urlreverse('ietf.doc.views_doc.document_html', kwargs=dict(name=name))))
file_urls.append(("htmlized", urlreverse('ietf.doc.views_doc.document_html', kwargs=dict(name=doc.name))))
if doc.tags.filter(slug="verified-errata").exists():
file_urls.append(("with errata", settings.RFC_EDITOR_INLINE_ERRATA_URL.format(rfc_number=doc.rfc_number)))
file_urls.append(("bibtex", urlreverse('ietf.doc.views_doc.document_bibtex',kwargs=dict(name=name))))
elif doc.rev:
file_urls.append(("bibtex", urlreverse('ietf.doc.views_doc.document_bibtex',kwargs=dict(name=doc.name))))
elif doc.type_id == "draft" and doc.rev != "":
base_path = os.path.join(settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR, doc.name + "-" + doc.rev + ".")
possible_types = settings.IDSUBMIT_FILE_TYPES
found_types = [t for t in possible_types if os.path.exists(base_path + t)]
Expand All @@ -1039,13 +1036,14 @@ def build_file_urls(doc: Union[Document, DocHistory]):
file_urls.append(("pdfized", urlreverse('ietf.doc.views_doc.document_pdfized', kwargs=dict(name=doc.name, rev=doc.rev))))
file_urls.append(("bibtex", urlreverse('ietf.doc.views_doc.document_bibtex',kwargs=dict(name=doc.name,rev=doc.rev))))
else:
# TODO: look at the state of the database post migration and update this comment, or remove the block
# As of 2022-12-14, there are 1463 Document and 3136 DocHistory records with type='draft' and rev=''.
# All of these are in the rfc state and are covered by the above cases.
log.unreachable('2022-12-14')
if doc.type_id == "draft":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this if?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It recreates the original logic (unless I blew it). This else block now handles what used to be the short-circuit for non-draft/non-rfc documents. This if causes it to also log the unreachable should a draft without a rev get through.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - its because of the refactor of the original L1003-1004. Got it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seemed just begging to skew out of sync with the if cases and turn into a bug later.

# TODO: look at the state of the database post migration and update this comment, or remove the block
# As of 2022-12-14, there are 1463 Document and 3136 DocHistory records with type='draft' and rev=''.
# All of these are in the rfc state and are covered by the above cases.
log.unreachable('2022-12-14')
file_urls = []
found_types = []

return file_urls, found_types

def augment_docs_and_user_with_user_info(docs, user):
Expand Down