Skip to content

Commit

Permalink
fix: label > 26 sessions per group (#7599)
Browse files Browse the repository at this point in the history
* fix: label > 26 sessions correctly

* test: test new helper

---------

Co-authored-by: Robert Sparks <[email protected]>
  • Loading branch information
jennifer-richards and rjsparks committed Sep 4, 2024
1 parent b6f8ede commit 3684742
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ietf/meeting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,19 +1205,30 @@ def special_request_token(self):
else:
return ""

@staticmethod
def _alpha_str(n: int):
"""Convert integer to string of a-z characters (a, b, c, ..., aa, ab, ...)"""
chars = []
while True:
chars.append(string.ascii_lowercase[n % 26])
n //= 26
# for 2nd letter and beyond, 0 means end the string
if n == 0:
break
# beyond the first letter, no need to represent a 0, so decrement
n -= 1
return "".join(chars[::-1])

def docname_token(self):
sess_mtg = Session.objects.filter(meeting=self.meeting, group=self.group).order_by('pk')
index = list(sess_mtg).index(self)
return 'sess%s' % (string.ascii_lowercase[index])
return f"sess{self._alpha_str(index)}"

def docname_token_only_for_multiple(self):
sess_mtg = Session.objects.filter(meeting=self.meeting, group=self.group).order_by('pk')
if len(list(sess_mtg)) > 1:
index = list(sess_mtg).index(self)
if index < 26:
token = 'sess%s' % (string.ascii_lowercase[index])
else:
token = 'sess%s%s' % (string.ascii_lowercase[index//26],string.ascii_lowercase[index%26])
token = f"sess{self._alpha_str(index)}"
return token
return None

Expand Down
9 changes: 9 additions & 0 deletions ietf/meeting/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ietf.group.factories import GroupFactory, GroupHistoryFactory
from ietf.meeting.factories import MeetingFactory, SessionFactory, AttendedFactory, SessionPresentationFactory
from ietf.meeting.models import Session
from ietf.stats.factories import MeetingRegistrationFactory
from ietf.utils.test_utils import TestCase
from ietf.utils.timezone import date_today, datetime_today
Expand Down Expand Up @@ -147,6 +148,14 @@ def test_chat_room_name(self):
session.chat_room = 'fnord'
self.assertEqual(session.chat_room_name(), 'fnord')

def test_alpha_str(self):
self.assertEqual(Session._alpha_str(0), "a")
self.assertEqual(Session._alpha_str(1), "b")
self.assertEqual(Session._alpha_str(25), "z")
self.assertEqual(Session._alpha_str(26), "aa")
self.assertEqual(Session._alpha_str(27 * 26 - 1), "zz")
self.assertEqual(Session._alpha_str(27 * 26), "aaa")

def test_session_recording_url(self):
group_acronym = "foobar"
meeting_date = datetime.date.today()
Expand Down

0 comments on commit 3684742

Please sign in to comment.