diff --git a/ietf/doc/migrations/0009_rfc_relateddocuments.py b/ietf/doc/migrations/0009_rfc_relateddocuments.py new file mode 100644 index 000000000..a00de56d6 --- /dev/null +++ b/ietf/doc/migrations/0009_rfc_relateddocuments.py @@ -0,0 +1,45 @@ +# Generated by Django 4.2.3 on 2023-07-05 22:40 + +from django.db import migrations + + +def forward(apps, schema_editor): + DocAlias = apps.get_model("doc", "DocAlias") + Document = apps.get_model("doc", "Document") + RelatedDocument = apps.get_model("doc", "RelatedDocument") + for rfc_alias in DocAlias.objects.filter(name__startswith="rfc").exclude( + docs__type__slug="rfc" + ): + # Move these over to the RFC + RelatedDocument.objects.filter( + relationship__slug__in=( + "tobcp", + "toexp", + "tohist", + "toinf", + "tois", + "tops", + "obs", + "updates", + ), + source__docalias=rfc_alias, + ).update(source=Document.objects.get(name=rfc_alias.name)) + # Duplicate references on the RFC but keep the ones on the draft as well + originals = list( + RelatedDocument.objects.filter( + relationship__slug__in=("refinfo", "refnorm", "refold", "refunk"), + source__docalias=rfc_alias, + ) + ) + for o in originals: + o.pk = None + o.source = Document.objects.get(name=rfc_alias.name) + RelatedDocument.objects.bulk_create(originals) + + +class Migration(migrations.Migration): + dependencies = [ + ("doc", "0008_move_rfc_docevents"), + ] + + operations = [migrations.RunPython(forward)] diff --git a/ietf/doc/migrations/0009_move_rfc_docaliases.py b/ietf/doc/migrations/0010_move_rfc_docaliases.py similarity index 96% rename from ietf/doc/migrations/0009_move_rfc_docaliases.py rename to ietf/doc/migrations/0010_move_rfc_docaliases.py index 2d38ff34d..af12c26a1 100644 --- a/ietf/doc/migrations/0009_move_rfc_docaliases.py +++ b/ietf/doc/migrations/0010_move_rfc_docaliases.py @@ -30,7 +30,7 @@ def forward(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ("doc", "0008_move_rfc_docevents"), + ("doc", "0009_rfc_relateddocuments"), ] operations = [ diff --git a/ietf/doc/models.py b/ietf/doc/models.py index 958fde12a..76c30738e 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -641,10 +641,20 @@ class DocumentInfo(models.Model): return self.relations_that_doc(('refnorm','refinfo','refunk','refold')) def referenced_by(self): - return self.relations_that(('refnorm','refinfo','refunk','refold')).filter(source__states__type__slug='draft',source__states__slug__in=['rfc','active']) - + return self.relations_that(("refnorm", "refinfo", "refunk", "refold")).filter( + models.Q( + source__type__slug="draft", + source__states__type__slug="draft", + source__states__slug="active", + ) + | models.Q(source__type__slug="rfc") + ) + + def referenced_by_rfcs(self): - return self.relations_that(('refnorm','refinfo','refunk','refold')).filter(source__states__type__slug='draft',source__states__slug='rfc') + return self.relations_that(("refnorm", "refinfo", "refunk", "refold")).filter( + source__type__slug="rfc" + ) class Meta: abstract = True diff --git a/ietf/templates/doc/document_referenced_by.html b/ietf/templates/doc/document_referenced_by.html index 958108bdd..7f7fe13c3 100644 --- a/ietf/templates/doc/document_referenced_by.html +++ b/ietf/templates/doc/document_referenced_by.html @@ -64,7 +64,7 @@ - {% if ref.source.get_state.slug == 'rfc' %} + {% if ref.source.type_id == "rfc" %} {% with ref.source.std_level as lvl %} {% if lvl %}{{ lvl }}{% endif %} {% endwith %} diff --git a/ietf/templates/doc/document_references.html b/ietf/templates/doc/document_references.html index d9134be6f..83358774f 100644 --- a/ietf/templates/doc/document_references.html +++ b/ietf/templates/doc/document_references.html @@ -51,7 +51,7 @@ - {% if ref.target.document.get_state.slug == 'rfc' %} + {% if ref.target.document.type_id == "rfc" %} {% with ref.target.document.std_level as lvl %} {% if lvl %}{{ lvl }}{% endif %} {% endwith %}