Skip to content

Commit

Permalink
[#1713] Added Videoplayer to Product model and template
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van der Schoor committed Sep 19, 2023
1 parent bb33f64 commit 2c26a90
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/open_inwoner/pdc/migrations/0059_product_video.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
9 changes: 9 additions & 0 deletions src/open_inwoner/pdc/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
19 changes: 19 additions & 0 deletions src/open_inwoner/pdc/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -295,6 +296,24 @@ def test_content_html_escape(self):
self.assertContains(response, "<strong>test</strong>")


@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):
Expand Down
5 changes: 5 additions & 0 deletions src/open_inwoner/templates/pages/product/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ <h1 class="h1" id="title">
<p class="p">{{ object.summary }}</p>
{{ 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 %}
<hr class="divider">
{% endif %}
Expand Down

0 comments on commit 2c26a90

Please sign in to comment.