From 2c26a904f5a1ed7224a00711224cbe0dac9c3ea6 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Tue, 19 Sep 2023 15:08:53 +0200 Subject: [PATCH] [#1713] Added Videoplayer to Product model and template --- .../pdc/migrations/0059_product_video.py | 28 +++++++++++++++++++ src/open_inwoner/pdc/models/product.py | 9 ++++++ src/open_inwoner/pdc/tests/test_product.py | 19 +++++++++++++ .../templates/pages/product/detail.html | 5 ++++ 4 files changed, 61 insertions(+) create mode 100644 src/open_inwoner/pdc/migrations/0059_product_video.py diff --git a/src/open_inwoner/pdc/migrations/0059_product_video.py b/src/open_inwoner/pdc/migrations/0059_product_video.py new file mode 100644 index 0000000000..ea523aa502 --- /dev/null +++ b/src/open_inwoner/pdc/migrations/0059_product_video.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.20 on 2023-09-19 12:38 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("media", "0001_initial"), + ("pdc", "0058_product_button_text"), + ] + + operations = [ + migrations.AddField( + model_name="product", + name="video", + field=models.ForeignKey( + blank=True, + help_text="Video to show after the intro", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="products", + to="media.video", + verbose_name="Video", + ), + ), + ] diff --git a/src/open_inwoner/pdc/models/product.py b/src/open_inwoner/pdc/models/product.py index c18c2ffb5d..ba8d2521b3 100644 --- a/src/open_inwoner/pdc/models/product.py +++ b/src/open_inwoner/pdc/models/product.py @@ -101,6 +101,15 @@ class Product(models.Model): "Product content with build-in WYSIWYG editor. By adding '[CTABUTTON]' you can embed a cta-button for linking to the defined form or link" ), ) + video = models.ForeignKey( + "media.Video", + blank=True, + null=True, + verbose_name=_("Video"), + on_delete=models.PROTECT, + related_name="products", + help_text=_("Video to show after the intro"), + ) categories = models.ManyToManyField( "pdc.Category", verbose_name=_("Categories"), diff --git a/src/open_inwoner/pdc/tests/test_product.py b/src/open_inwoner/pdc/tests/test_product.py index c894c69e94..1dcb17b1b7 100644 --- a/src/open_inwoner/pdc/tests/test_product.py +++ b/src/open_inwoner/pdc/tests/test_product.py @@ -8,6 +8,7 @@ from open_inwoner.accounts.tests.factories import UserFactory from open_inwoner.questionnaire.tests.factories import QuestionnaireStepFactory +from ...media.tests.factories import VideoFactory from ..models import CategoryProduct from .factories import CategoryFactory, ProductFactory, QuestionFactory @@ -295,6 +296,24 @@ def test_content_html_escape(self): self.assertContains(response, "test") +@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") +class TestProductVideo(WebTest): + def test_product_video_is_rendered(self): + video = VideoFactory() + product = ProductFactory( + content="Some content", + link="http://www.example.com", + video=video, + ) + response = self.app.get( + reverse("products:product_detail", kwargs={"slug": product.slug}) + ) + video_frames = response.pyquery(".video iframe") + self.assertEqual(len(video_frames), 1) + iframe = video_frames[0] + self.assertEqual(iframe.attrib["src"], video.player_url) + + @override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") class TestProductDetailView(WebTest): def test_subheadings_in_sidebar(self): diff --git a/src/open_inwoner/templates/pages/product/detail.html b/src/open_inwoner/templates/pages/product/detail.html index 82ccfeef5e..186b9cf8ca 100644 --- a/src/open_inwoner/templates/pages/product/detail.html +++ b/src/open_inwoner/templates/pages/product/detail.html @@ -36,6 +36,11 @@

{{ object.summary }}

{{ object|product_ckeditor_content|safe }} + {% if object.video %} + {# duck-type the fact the videoplayer plugin also uses .video for the Video #} + {% include "cms/plugins/videoplayer/videoplayer.html" with instance=object %} + {% endif %} + {% if object.question_set.exists or object.files.exists or object.conditions.exists or object.locations.exists or product_links.exists or object.related_products.published.exists or object.contacts.exists %}
{% endif %}