fix: Migrate and handle subseries IprDocRels ()

* chore: Stash orig IprDocRel document alias

* chore: Point IprDocRel at subseries docs

* fix: Fix IprDocRel.document usage in templates

* fix: Handle subseries in IprDocRel.formatted_name()

* refactor: Better presentation of IprDocRel subseries

* fix: Allow blank originaldocumentaliasname
This commit is contained in:
Jennifer Richards 2023-12-07 15:40:18 -04:00 committed by GitHub
parent dd41234bb4
commit cbe710d3fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 7 deletions

View file

@ -2,14 +2,29 @@
from django.db import migrations
import django.db.models.deletion
from django.db.models import F, Subquery, OuterRef, ManyToManyField
from django.db.models import F, Subquery, OuterRef, ManyToManyField, CharField
import ietf.utils.models
def forward(apps, schema_editor):
IprDocRel = apps.get_model("ipr", "IprDocRel")
DocAlias = apps.get_model("doc", "DocAlias")
subquery = Subquery(DocAlias.objects.filter(pk=OuterRef("deprecated_document")).values("docs")[:1])
IprDocRel.objects.annotate(firstdoc=subquery).update(document=F("firstdoc"))
document_subquery = Subquery(
DocAlias.objects.filter(
pk=OuterRef("deprecated_document")
).values("docs")[:1]
)
name_subquery = Subquery(
DocAlias.objects.filter(
pk=OuterRef("deprecated_document")
).values("name")[:1]
)
IprDocRel.objects.annotate(
firstdoc=document_subquery,
aliasname=name_subquery,
).update(
document=F("firstdoc"),
originaldocumentaliasname=F("aliasname"),
)
# This might not be right - we may need here (and in the relateddocument migrations) to pay attention to
# whether the name being pointed to is and rfc name or a draft name and point to the right object instead...
@ -57,6 +72,12 @@ class Migration(migrations.Migration):
),
preserve_default=False,
),
migrations.AddField(
model_name="iprdocrel",
name="originaldocumentaliasname",
field=CharField(max_length=255,null=True,blank=True),
preserve_default=True,
),
migrations.RunPython(forward, reverse),
migrations.AlterField(
model_name="iprdocrel",

View file

@ -163,6 +163,7 @@ class IprDocRel(models.Model):
document = ForeignKey(Document)
sections = models.TextField(blank=True)
revisions = models.CharField(max_length=16,blank=True) # allows strings like 01-07
originaldocumentaliasname = models.CharField(max_length=255, null=True, blank=True)
def doc_type(self):
name = self.document.name
@ -175,7 +176,7 @@ class IprDocRel(models.Model):
def formatted_name(self):
name = self.document.name
if name.startswith("rfc"):
if len(name) >= 3 and name[:3] in ("rfc", "bcp", "fyi", "std"):
return name.upper()
#elif self.revisions:
# return "%s-%s" % (name, self.revisions)

View file

@ -23,6 +23,7 @@ from ietf.doc.models import ( Document, State, StateType, DocEvent, DocRelations
from ietf.doc.expire import move_draft_files_to_archive
from ietf.doc.utils import add_state_change_event, prettify_std_name, update_action_holders
from ietf.group.models import Group
from ietf.ipr.models import IprDocRel
from ietf.name.models import StdLevelName, StreamName
from ietf.person.models import Person
from ietf.utils.log import log
@ -776,6 +777,15 @@ def update_docs_from_rfc_index(
Document.objects.filter(name=OuterRef("originaltargetaliasname")).values_list("pk",flat=True)[:1]
)
).update(target=F("subseries_target"))
IprDocRel.objects.filter(
Q(originaldocumentaliasname__startswith="bcp") |
Q(originaldocumentaliasname__startswith="std") |
Q(originaldocumentaliasname__startswith="fyi")
).annotate(
subseries_target=Subquery(
Document.objects.filter(name=OuterRef("originaldocumentaliasname")).values_list("pk",flat=True)[:1]
)
).update(document=F("subseries_target"))
def post_approved_draft(url, name):

View file

@ -383,7 +383,8 @@
{{ iprdocrel.doc_type }}:
</dt>
<dd class="col-sm-8 my-0">
{{ iprdocrel.formatted_name|urlize_ietf_docs }} ("{{ iprdocrel.document.document.title }}")
{{ iprdocrel.formatted_name|urlize_ietf_docs }}
{% if iprdocrel.document.title %}("{{ iprdocrel.document.title }}"){% endif %}
</dd>
{% if iprdocrel.revisions %}
<dt class="col-sm-4 my-0">
@ -429,7 +430,8 @@
{{ iprdocrel.doc_type }}:
</dt>
<dd class="{% if prev %}col-sm-8{% else %}col-sm-9{% endif %} my-0">
{{ iprdocrel.formatted_name|urlize_ietf_docs }} ("{{ iprdocrel.document.document.title }}")
{{ iprdocrel.formatted_name|urlize_ietf_docs }}
{% if iprdocrel.document.title %}("{{ iprdocrel.document.title }}"){% endif %}
</dd>
{% if iprdocrel.revisions %}
<dt class="{% if prev %}col-sm-4{% else %}col-sm-3{% endif %} my-0">

View file

@ -54,7 +54,7 @@
is related to
{% for item in iprdocrels %}
{% if forloop.last and forloop.counter > 1 %}and{% endif %}
{{ item.formatted_name|urlize_ietf_docs }} ("{{ item.document.document.title }}"){% if not forloop.last and forloop.counter > 1 %},{% endif %}
{{ item.formatted_name|urlize_ietf_docs }}{% if item.document.title %} ("{{ item.document.title }}"){% endif %}{% if not forloop.last and forloop.counter > 1 %},{% endif %}
{% endfor %}
{% endif %}
{% endwith %}