|
12 | 12 | from xml.dom import pulldom, Node |
13 | 13 |
|
14 | 14 | from django.conf import settings |
| 15 | +from django.db.models import Subquery, OuterRef, F, Q |
15 | 16 | from django.utils import timezone |
16 | 17 | from django.utils.encoding import smart_bytes, force_str |
17 | 18 |
|
18 | 19 | import debug # pyflakes:ignore |
19 | 20 |
|
20 | 21 | from ietf.doc.models import ( Document, State, StateType, DocEvent, DocRelationshipName, |
21 | | - DocTagName, RelatedDocument ) |
| 22 | + DocTagName, RelatedDocument, RelatedDocHistory ) |
22 | 23 | from ietf.doc.expire import move_draft_files_to_archive |
23 | 24 | from ietf.doc.utils import add_state_change_event, prettify_std_name, update_action_holders |
24 | 25 | from ietf.group.models import Group |
@@ -327,7 +328,7 @@ def extract_doc_list(parentNode, tagName): |
327 | 328 | log("node: %s" % node) |
328 | 329 | raise |
329 | 330 | for d in data: |
330 | | - k = "RFC%04d" % d[0] |
| 331 | + k = "RFC%d" % d[0] |
331 | 332 | if k in also_list: |
332 | 333 | d[9].extend(also_list[k]) |
333 | 334 | return data |
@@ -680,13 +681,17 @@ def parse_relation_list(l): |
680 | 681 | if created: |
681 | 682 | if first_sync_creating_subseries: |
682 | 683 | subseries_doc.docevent_set.create(type=f"{subseries_slug}_history_marker", by=system, desc=f"No history of this {subseries_slug.upper()} document is currently available in the datatracker before this point") |
683 | | - subseries_doc.docevent_set.create(type=f"{subseries_slug}_doc_created", by=system, desc=f"Created {subseries_doc_name} via sync to the rfc-index") |
| 684 | + subseries_doc.docevent_set.create(type=f"{subseries_slug}_doc_created", by=system, desc=f"Imported {subseries_doc_name} into the datatracker via sync to the rfc-index") |
| 685 | + else: |
| 686 | + subseries_doc.docevent_set.create(type=f"{subseries_slug}_doc_created", by=system, desc=f"Created {subseries_doc_name} via sync to the rfc-index") |
684 | 687 | _, relationship_created = subseries_doc.relateddocument_set.get_or_create(relationship_id="contains", target=doc) |
685 | 688 | if relationship_created: |
686 | 689 | subseries_doc.docevent_set.create(type="sync_from_rfc_editor", by=system, desc=f"Added {doc.name} to {subseries_doc.name}") |
687 | 690 | if first_sync_creating_subseries: |
688 | 691 | rfc_events.append(doc.docevent_set.create(type=f"{subseries_slug}_history_marker", by=system, desc=f"No history of {subseries_doc.name.upper()} is currently available in the datatracker before this point")) |
689 | | - rfc_events.append(doc.docevent_set.create(type="sync_from_rfc_editor", by=system, desc=f"Added {doc.name} to {subseries_doc.name}")) |
| 692 | + rfc_events.append(doc.docevent_set.create(type="sync_from_rfc_editor", by=system, desc=f"Imported membership of {doc.name} in {subseries_doc.name} via sync to the rfc-index")) |
| 693 | + else: |
| 694 | + rfc_events.append(doc.docevent_set.create(type="sync_from_rfc_editor", by=system, desc=f"Added {doc.name} to {subseries_doc.name}")) |
690 | 695 |
|
691 | 696 | for subdoc in doc.related_that("contains"): |
692 | 697 | if subdoc.name not in also: |
@@ -735,6 +740,40 @@ def parse_relation_list(l): |
735 | 740 | ) |
736 | 741 | doc.save_with_history(rfc_events) |
737 | 742 | yield rfc_changes, doc, rfc_published # yield changes to the RFC |
| 743 | + |
| 744 | + if first_sync_creating_subseries: |
| 745 | + # First - create the known subseries documents that have ghosted. |
| 746 | + # The RFC editor (as of 31 Oct 2023) claims these subseries docs do not exist. |
| 747 | + # The datatracker, on the other hand, will say that the series doc currently contains no RFCs. |
| 748 | + for name in ["fyi17", "std1", "bcp12", "bcp113", "bcp66"]: |
| 749 | + # Leaving most things to the default intentionally |
| 750 | + # Of note, title and stream are left to the defaults of "" and none. |
| 751 | + subseries_doc, created = Document.objects.get_or_create(type_id=name[:3], name=name) |
| 752 | + if not created: |
| 753 | + log(f"Warning: {name} unexpectedly already exists") |
| 754 | + else: |
| 755 | + subseries_slug = name[:3] |
| 756 | + subseries_doc.docevent_set.create(type=f"{subseries_slug}_history_marker", by=system, desc=f"No history of this {subseries_slug.upper()} document is currently available in the datatracker before this point") |
| 757 | + |
| 758 | + |
| 759 | + RelatedDocument.objects.filter( |
| 760 | + Q(originaltargetaliasname__startswith="bcp") | |
| 761 | + Q(originaltargetaliasname__startswith="std") | |
| 762 | + Q(originaltargetaliasname__startswith="fyi") |
| 763 | + ).annotate( |
| 764 | + subseries_target=Subquery( |
| 765 | + Document.objects.filter(name=OuterRef("originaltargetaliasname")).values_list("pk",flat=True)[:1] |
| 766 | + ) |
| 767 | + ).update(target=F("subseries_target")) |
| 768 | + RelatedDocHistory.objects.filter( |
| 769 | + Q(originaltargetaliasname__startswith="bcp") | |
| 770 | + Q(originaltargetaliasname__startswith="std") | |
| 771 | + Q(originaltargetaliasname__startswith="fyi") |
| 772 | + ).annotate( |
| 773 | + subseries_target=Subquery( |
| 774 | + Document.objects.filter(name=OuterRef("originaltargetaliasname")).values_list("pk",flat=True)[:1] |
| 775 | + ) |
| 776 | + ).update(target=F("subseries_target")) |
738 | 777 |
|
739 | 778 |
|
740 | 779 | def post_approved_draft(url, name): |
|
0 commit comments