Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create documents for rpc demo #6240

Merged
merged 9 commits into from
Aug 29, 2023
1 change: 0 additions & 1 deletion ietf/rpc/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Meta:

disposition = factory.SubFactory(DispositionFactory, slug="in_progress")
draft = factory.SubFactory("ietf.doc.factories.WgDraftFactory")
rfc_number = factory.Sequence(lambda n: n + 1000)
submitted_format = factory.SubFactory(
"ietf.name.factories.SourceFormatNameFactory", slug="xml-v3"
)
Expand Down
29 changes: 27 additions & 2 deletions ietf/rpc/management/commands/create_rpc_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# -*- coding: utf-8 -*-

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError, CommandParser
from django.core.management.base import BaseCommand, CommandError

from ...factories import RpcPersonFactory
from ietf.doc.factories import WgDraftFactory, WgRfcFactory

from ...factories import RfcToBeFactory, RpcPersonFactory
from ...utils import next_rfc_number


class Command(BaseCommand):
Expand All @@ -15,6 +18,10 @@ def handle(self, *args, **options):
if settings.SERVER_MODE == "production":
raise CommandError("This command is not allowed in production mode")

self.create_rpc_people()
self.create_documents()

def create_rpc_people(self):
# From "Manage Team Members" wireframe
bjenkins = RpcPersonFactory(
person__name="B. Jenkins",
Expand Down Expand Up @@ -154,3 +161,21 @@ def handle(self, *args, **options):
capable_of=["xmlfmt-expert"],
manager=bjenkins,
)

def create_documents(self):
# Draft sent to RPC
WgDraftFactory(states=[("draft-iesg", "pub-req")])

# Draft sent to RPC and in progress as an RfcToBe
RfcToBeFactory(
rfc_number=None,
draft__states=[("draft-iesg", "rfcqueue")]
)

# Draft published as an RFC
rfc_number = next_rfc_number()[0]
RfcToBeFactory(
disposition__slug="published",
rfc_number=rfc_number,
draft=WgRfcFactory(alias2__name=f"rfc{rfc_number}")
)
10 changes: 10 additions & 0 deletions ietf/rpc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ class Meta:
),
]

def __str__(self):
name = f"RFC {self.rfc_number}" if self.rfc_number is not None else self.draft.name
return f"{name} ({self.disposition})"


class Disposition(models.Model):
slug = models.CharField(max_length=32, primary_key=True)
name = models.CharField(max_length=255)
desc = models.TextField(blank=True)

def __str__(self):
return self.name


class Cluster(models.Model):
number = models.PositiveIntegerField(unique=True)
Expand All @@ -87,6 +94,9 @@ class Cluster(models.Model):
class UnusableRfcNumber(models.Model):
number = models.PositiveIntegerField(primary_key=True)
comment = models.TextField(blank=True)

class Meta:
ordering = ["number"]


class RpcPerson(models.Model):
Expand Down
34 changes: 32 additions & 2 deletions ietf/rpc/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Copyright The IETF Trust 2023, All Rights Reserved
# -*- coding: utf-8 -*-
from django.test import TestCase
from ietf.doc.factories import DocAliasFactory
from ietf.utils.test_utils import TestCase

# Create your tests here.
from .factories import RfcToBeFactory, UnusableRfcNumberFactory
from .utils import next_rfc_number


class UtilsTests(TestCase):
def test_next_rfc_number(self):
self.assertEqual(next_rfc_number(), [1])
self.assertEqual(next_rfc_number(2), [1, 2])
self.assertEqual(next_rfc_number(5), [1, 2, 3, 4, 5])

UnusableRfcNumberFactory(number=1)
self.assertEqual(next_rfc_number(), [2])
self.assertEqual(next_rfc_number(2), [2, 3])
self.assertEqual(next_rfc_number(5), [2, 3, 4, 5, 6])

RfcToBeFactory(rfc_number=2)
self.assertEqual(next_rfc_number(), [3])
self.assertEqual(next_rfc_number(2), [3, 4])
self.assertEqual(next_rfc_number(5), [3, 4, 5, 6, 7])

DocAliasFactory(name="rfc3")
self.assertEqual(next_rfc_number(), [4])
self.assertEqual(next_rfc_number(2), [4, 5])
self.assertEqual(next_rfc_number(5), [4, 5, 6, 7, 8])

# next_rfc_number is not done until this one passes!
# UnusableRfcNumberFactory(number=6)
# self.assertEqual(next_rfc_number(), [4])
# self.assertEqual(next_rfc_number(2), [4, 5])
# self.assertEqual(next_rfc_number(5), [7, 8, 9, 10, 11])
17 changes: 15 additions & 2 deletions ietf/rpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
# -*- coding: utf-8 -*-
from typing import List

from ietf.doc.models import Document
from django.db.models import Max, PositiveIntegerField
from django.db.models.functions import Cast, Substr

from ietf.doc.models import DocAlias
from .models import RfcToBe, UnusableRfcNumber


def next_rfc_number(count=1) -> List[int]:
"""Find the next count contiguous available RFC numbers"""
# todo implement me
# In the worst-case, we can always use (n + 1) to (n + count) where n is the last
# unavailable number.
last_unavailable_number = max((
UnusableRfcNumber.objects.aggregate(Max("number"))["number__max"] or 0,
RfcToBe.objects.aggregate(Max("rfc_number"))["rfc_number__max"] or 0,
DocAlias.objects.filter(name__startswith="rfc").annotate(
rfcnum=Cast(Substr("name", 4), PositiveIntegerField())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😿

).aggregate(Max("rfcnum"))["rfcnum__max"] or 0,
))
# todo consider holes in the unavailable number sequence!
return list(range(last_unavailable_number + 1, last_unavailable_number + 1 + count))
1 change: 0 additions & 1 deletion ietf/rpc/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright The IETF Trust 2023, All Rights Reserved
# -*- coding: utf-8 -*-
from django.shortcuts import render

# Create your views here.