Merge pull request #5932 from jennifer-richards/migrate-related

fix: Preserve RelatedDocuments for RFCs
This commit is contained in:
Jennifer Richards 2023-07-07 08:06:07 -03:00 committed by GitHub
commit c36413aa65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 6 deletions

View file

@ -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)]

View file

@ -30,7 +30,7 @@ def forward(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
("doc", "0008_move_rfc_docevents"),
("doc", "0009_rfc_relateddocuments"),
]
operations = [

View file

@ -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

View file

@ -64,7 +64,7 @@
</a>
</td>
<td>
{% 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 %}

View file

@ -51,7 +51,7 @@
</a>
</td>
<td>
{% 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 %}