family: agenda_references_template field (#57927)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-10-21 14:38:31 +02:00
parent d41302e20b
commit 9a288e01b1
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 65 additions and 6 deletions

View File

@ -0,0 +1,23 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('family', '0008_clean'),
]
operations = [
migrations.RenameField(
model_name='weeklyagendacell',
old_name='agenda_reference',
new_name='agenda_references_template',
),
migrations.AlterField(
model_name='weeklyagendacell',
name='user_external_template',
field=models.CharField(
blank=True, max_length=255, verbose_name='User external reference template'
),
),
]

View File

@ -0,0 +1,16 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('family', '0009_agenda_references_template'),
]
operations = [
migrations.AlterField(
model_name='weeklyagendacell',
name='agenda_references_template',
field=models.CharField(blank=True, max_length=2000, verbose_name='Agenda references template'),
),
]

View File

@ -25,8 +25,12 @@ from combo.data.models import JsonCellBase
@register_cell_class
class WeeklyAgendaCell(JsonCellBase):
title = models.CharField(_('Title'), max_length=150, blank=True)
agenda_reference = models.CharField(_('Agenda'), max_length=128)
user_external_template = models.CharField(max_length=255)
agenda_references_template = models.CharField(
_('Agenda references template'), max_length=2000, blank=True
)
user_external_template = models.CharField(
_('User external reference template'), max_length=255, blank=True
)
default_template_name = 'family/weekly_agenda.html'
force_async = True
@ -50,7 +54,7 @@ class WeeklyAgendaCell(JsonCellBase):
chrono_url += '/'
return '%sapi/agendas/datetimes/?agendas=%s&user_external_id=%s&show_past_events=true' % (
chrono_url,
self.agenda_reference,
self.agenda_references_template,
self.user_external_template,
)

View File

@ -6,6 +6,7 @@ from django.core.cache import cache
from django.test.client import RequestFactory
from combo.apps.family.models import WeeklyAgendaCell
from combo.apps.wcs.context_processors import Cards
from combo.data.models import Page
from combo.utils import NothingInCacheException
@ -14,7 +15,7 @@ pytestmark = pytest.mark.django_db
@pytest.fixture
def context():
ctx = {'request': RequestFactory().get('/')}
ctx = {'cards': Cards(), 'request': RequestFactory().get('/')}
ctx['request'].user = None
ctx['request'].session = {}
return ctx
@ -70,7 +71,7 @@ def test_weeklyagenda_cell(settings, context):
== 'http://chrono.example.org/api/agendas/datetimes/?agendas=&user_external_id=&show_past_events=true'
)
cell.agenda_reference = 'some-agenda'
cell.agenda_references_template = 'some-agenda,other-agenda'
cell.save()
context['request'].user = MockUserWithNameId()
with mock.patch('combo.utils.requests.get') as requests_get:
@ -78,9 +79,24 @@ def test_weeklyagenda_cell(settings, context):
cell.render(context)
assert (
requests_get.call_args_list[0][0][0]
== 'http://chrono.example.org/api/agendas/datetimes/?agendas=some-agenda&user_external_id=&show_past_events=true'
== 'http://chrono.example.org/api/agendas/datetimes/?agendas=some-agenda,other-agenda&user_external_id=&show_past_events=true'
)
cell.agenda_references_template = (
'{% load wcs %}{{ cards|objects:"foo"|get_full|first|get:"fields"|get:"bar"|default:"" }}'
',some-agenda,other-agenda,{{ user_nameid }}'
)
cell.save()
context['request'].user = MockUserWithNameId()
with mock.patch('combo.utils.requests.get') as requests_get:
requests_get.return_value = MockedRequestResponse(content=json.dumps(data))
cell.render(context)
assert (
requests_get.call_args_list[1][0][0]
== 'http://chrono.example.org/api/agendas/datetimes/?agendas=,some-agenda,other-agenda,xyz&user_external_id=&show_past_events=true'
)
cell.agenda_references_template = 'some-agenda'
cell.user_external_template = 'some-key:{{ user_nameid }}'
cell.save()
with mock.patch('combo.utils.requests.get') as requests_get: