fix: label > 26 sessions per group (#7599)
* fix: label > 26 sessions correctly * test: test new helper --------- Co-authored-by: Robert Sparks <rjsparks@nostrum.com>
This commit is contained in:
parent
b6f8ede98a
commit
36847428d5
|
@ -1205,19 +1205,30 @@ class Session(models.Model):
|
|||
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
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from django.test import override_settings
|
|||
|
||||
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
|
||||
|
@ -147,6 +148,14 @@ class SessionTests(TestCase):
|
|||
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()
|
||||
|
|
Loading…
Reference in a new issue