|
41 | 41 | import os |
42 | 42 | import re |
43 | 43 | import markdown |
44 | | -import textwrap |
45 | 44 |
|
46 | | -from collections import defaultdict |
47 | 45 | from urllib.parse import quote |
48 | 46 |
|
49 | 47 | from django.http import HttpResponse, Http404 |
|
52 | 50 | from django.urls import reverse as urlreverse |
53 | 51 | from django.conf import settings |
54 | 52 | from django import forms |
55 | | -from django.views.decorators.cache import cache_page |
56 | 53 |
|
57 | 54 |
|
58 | 55 | import debug # pyflakes:ignore |
59 | 56 |
|
60 | 57 | from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType, |
61 | 58 | ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent, IanaExpertDocEvent, |
62 | | - IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor, RelatedDocument) |
| 59 | + IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor) |
63 | 60 | from ietf.doc.utils import (add_links_in_new_revision_events, augment_events_with_revision, |
64 | 61 | can_adopt_draft, can_unadopt_draft, get_chartering_type, get_tags_for_stream_id, |
65 | 62 | needed_ballot_positions, nice_consensus, prettify_std_name, update_telechat, has_same_ballot, |
|
83 | 80 | from ietf.review.utils import can_request_review_of_doc, review_assignments_to_list_for_docs |
84 | 81 | from ietf.review.utils import no_review_from_teams_on_doc |
85 | 82 | from ietf.utils import markup_txt, log |
| 83 | +from ietf.utils.draft import Draft |
86 | 84 | from ietf.utils.response import permission_denied |
87 | 85 | from ietf.utils.text import maybe_split |
88 | 86 |
|
@@ -1719,57 +1717,53 @@ def all_presentations(request, name): |
1719 | 1717 | 'past' : past+recent, |
1720 | 1718 | }) |
1721 | 1719 |
|
1722 | | -@cache_page ( 60 * 60, cache="slowpages" ) |
1723 | | -def idnits2_rfcs_obsoleted(request): |
1724 | | - |
1725 | | - obsdict = defaultdict(list) |
1726 | | - for r in RelatedDocument.objects.filter(relationship_id='obs'): |
1727 | | - obsdict[int(r.target.document.rfc_number())].append(int(r.source.rfc_number())) |
1728 | 1720 |
|
1729 | | - for k in obsdict: |
1730 | | - obsdict[k] = sorted(obsdict[k]) |
| 1721 | +def idnits2_rfcs_obsoleted(request): |
| 1722 | + filename = os.path.join(settings.DERIVED_DIR,'idnits2-rfcs-obsoleted') |
| 1723 | + try: |
| 1724 | + with open(filename,'rb') as f: |
| 1725 | + blob = f.read() |
| 1726 | + return HttpResponse(blob,content_type='text/plain;charset=utf-8') |
| 1727 | + except Exception as e: |
| 1728 | + log.log('Failed to read idnits2-rfcs-obsoleted:'+str(e)) |
| 1729 | + raise Http404 |
1731 | 1730 |
|
1732 | | - return render(request, 'doc/idnits2-rfcs-obsoleted.txt', context={'obsitems':sorted(obsdict.items())},content_type='text/plain;charset=utf-8') |
1733 | 1731 |
|
1734 | | -@cache_page ( 60 * 60, cache="slowpages" ) |
1735 | 1732 | def idnits2_rfc_status(request): |
| 1733 | + filename = os.path.join(settings.DERIVED_DIR,'idnits2-rfc-status') |
| 1734 | + try: |
| 1735 | + with open(filename,'rb') as f: |
| 1736 | + blob = f.read() |
| 1737 | + return HttpResponse(blob,content_type='text/plain;charset=utf-8') |
| 1738 | + except Exception as e: |
| 1739 | + log.log('Failed to read idnits2-rfc-status:'+str(e)) |
| 1740 | + raise Http404 |
1736 | 1741 |
|
1737 | | - blob=['N']*10000 |
1738 | | - |
1739 | | - symbols={ |
1740 | | - 'ps': 'P', |
1741 | | - 'inf': 'I', |
1742 | | - 'exp': 'E', |
1743 | | - 'ds': 'D', |
1744 | | - 'hist': 'H', |
1745 | | - 'std': 'S', |
1746 | | - 'bcp': 'B', |
1747 | | - 'unkn': 'U', |
1748 | | - } |
1749 | | - |
1750 | | - rfcs = Document.objects.filter(type_id='draft',states__slug='rfc',states__type='draft') |
1751 | | - for rfc in rfcs: |
1752 | | - offset = int(rfc.rfcnum)-1 |
1753 | | - blob[offset] = symbols[rfc.std_level_id] |
1754 | | - if rfc.related_that('obs'): |
1755 | | - blob[offset] = 'O' |
1756 | 1742 |
|
1757 | | - # Workarounds for unusual states in the datatracker |
| 1743 | +def idnits2_state(request, name, rev=None): |
| 1744 | + doc = get_object_or_404(Document, docalias__name=name) |
| 1745 | + if doc.type_id!='draft': |
| 1746 | + raise Http404 |
| 1747 | + zero_revision = NewRevisionDocEvent.objects.filter(doc=doc,rev='00').first() |
| 1748 | + if zero_revision: |
| 1749 | + doc.created = zero_revision.time |
| 1750 | + else: |
| 1751 | + doc.created = doc.docevent_set.order_by('-time').first().time |
| 1752 | + if doc.std_level: |
| 1753 | + doc.deststatus = doc.std_level.name |
| 1754 | + elif doc.intended_std_level: |
| 1755 | + doc.deststatus = doc.intended_std_level.name |
| 1756 | + else: |
| 1757 | + text = doc.text() |
| 1758 | + if text: |
| 1759 | + parsed_draft = Draft(text=doc.text(), source=name, name_from_source=False) |
| 1760 | + doc.deststatus = parsed_draft.get_status() |
| 1761 | + else: |
| 1762 | + doc.deststatus="Unknown" |
| 1763 | + return render(request, 'doc/idnits2-state.txt', context={'doc':doc}, content_type='text/plain;charset=utf-8') |
1758 | 1764 |
|
1759 | | - # Document.get(docalias='rfc6312').rfcnum == 6342 |
1760 | | - # 6312 was published with the wrong rfc number in it |
1761 | | - # weird workaround in the datatracker - there are two |
1762 | | - # DocAliases starting with rfc - the canonical name code |
1763 | | - # searches for the lexically highest alias starting with rfc |
1764 | | - # which is getting lucky. |
1765 | | - blob[6312 - 1] = 'O' |
1766 | 1765 |
|
1767 | | - # RFC200 is an old RFC List by Number |
1768 | | - blob[200 -1] = 'O' |
1769 | 1766 |
|
1770 | | - # End Workarounds |
1771 | 1767 |
|
1772 | | - blob = re.sub('N*$','',''.join(blob)) |
1773 | 1768 |
|
1774 | | - return HttpResponse(textwrap.fill(blob, width=64),content_type='text/plain;charset=utf-8') |
1775 | 1769 |
|
0 commit comments