ants_hub: display meeting type duration when configuration ANTS meeting types (#78398) #98

Merged
bdauvergne merged 3 commits from wip/78398-ants-hub-differentier-les-types into main 2023-06-13 12:07:28 +02:00
4 changed files with 32 additions and 12 deletions

View File

@ -178,7 +178,8 @@ class PlaceAgendaEditForm(forms.ModelForm):
self.meeting_types = self.instance.agenda.meetingtype_set.order_by('label')
for meeting_type in self.instance.agenda.iter_meetingtypes():
field_meeting_type = forms.TypedMultipleChoiceField(
label=_('%s') % meeting_type.label,
label=_('%(mt_label)s (%(mt_duration)s minutes)')
% {'mt_label': meeting_type.label, 'mt_duration': meeting_type.duration},
choices=models.ANTSMeetingType.choices,
widget=forms.CheckboxSelectMultiple(attrs={'class': 'inline'}),
required=False,
@ -187,7 +188,8 @@ class PlaceAgendaEditForm(forms.ModelForm):
field_meeting_type.meeting_type = meeting_type
field_meeting_type.key = 'ants_meeting_type'
field_persons_number = forms.TypedMultipleChoiceField(
label=_('%s') % meeting_type.label,
label=_('%(mt_label)s (%(mt_duration)s minutes)')
% {'mt_label': meeting_type.label, 'mt_duration': meeting_type.duration},
choices=models.ANTSPersonsNumber.choices,
widget=forms.CheckboxSelectMultiple(attrs={'class': 'inline'}),
required=False,

View File

@ -64,7 +64,10 @@ def agenda():
meetings CNI
desk "Desk1"
timeperiod monday-friday 08:00-17:00
meeting-type 15
meeting-type "Rdv CNI" mt-15 15
meeting-type "Rdv CNI" mt-30 30
meeting-type "Rdv CNI" mt-45 45
meeting-type "Rdv CNI" mt-60 60
'''
)

View File

@ -14,8 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from unittest import mock
import pytest
import responses
@ -148,6 +146,13 @@ def test_add_agenda(hub, app, admin_user, city, place, agenda, freezer):
resp = resp.click(href='agenda.*edit')
# make the meeting-type of 15 minutes correpond to a meeting to get a CNI
# for 1 person
assert [item.text() for item in resp.pyquery('table td.meeting-type').items()] == [
'Rdv CNI (15 minutes)',
'Rdv CNI (30 minutes)',
'Rdv CNI (45 minutes)',
'Rdv CNI (60 minutes)',
]
resp.form.set('mt_mt-15_1', [str(ANTSMeetingType.CNI)])
resp.form.set('mt_mt-15_2', [str(ANTSPersonsNumber.ONE)])
resp = resp.form.submit().follow()
@ -156,7 +161,12 @@ def test_add_agenda(hub, app, admin_user, city, place, agenda, freezer):
assert '(not configured)' not in resp
assert '(CNI, 1 person)' in resp
assert place_agenda.setting == {
'meeting-types': {'mt-15': {'ants_meeting_type': [1], 'ants_persons_number': [1]}}
'meeting-types': {
'mt-15': {'ants_meeting_type': [1], 'ants_persons_number': [1]},
'mt-30': {'ants_meeting_type': [], 'ants_persons_number': []},
'mt-45': {'ants_meeting_type': [], 'ants_persons_number': []},
'mt-60': {'ants_meeting_type': [], 'ants_persons_number': []},
}
}
open_dates = list(place_agenda.iter_open_dates())

View File

@ -218,7 +218,7 @@ def add_desk(
return desk
def add_meeting_type(agenda: Agenda, slug: str, duration: int = None):
def add_meeting_type(agenda: Agenda, slug: str, label: str = None, duration: int = None):
if duration is None:
if isinstance(slug, int) or ':' not in slug:
duration = int(slug)
@ -227,7 +227,10 @@ def add_meeting_type(agenda: Agenda, slug: str, duration: int = None):
slug, duration = slug.split(':')
duration = int(duration)
meeting_type = MeetingType.objects.create(agenda=agenda, slug=slug, duration=duration)
kwargs = {'agenda': agenda, 'slug': slug, 'duration': duration}
if label:
kwargs['label'] = label
meeting_type = MeetingType.objects.create(**kwargs)
setattr(agenda, f'_{meeting_type.slug.replace("-", "_")}', meeting_type)
return meeting_type
@ -552,11 +555,13 @@ def build_agendas(description):
return defn
def parse_mt(node):
dummy, slug, *rest = node.tokens
if rest:
return {'slug': slug, 'duration': int(rest[0])}
dummy, *rest = node.tokens
if len(rest) == 1:
return rest[0]
elif len(rest) == 2:
return {'slug': rest[0], 'duration': int(rest[1])}
else:
return slug
return {'label': eval_label(rest[0]), 'slug': rest[1], 'duration': int(rest[2])}
def parse_reminder_setting(node):
dummy, *rest = node.tokens