Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added very basic Open Forms integration #311

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ django-rich
django-csp
django-csp-reports
mozilla-django-oidc-db
django-open-forms-client

# API libraries
djangorestframework
Expand Down
5 changes: 5 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ django==3.2.15
# django-hijack
# django-import-export
# django-localflavor
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-polymorphic
Expand Down Expand Up @@ -141,6 +142,8 @@ django-localflavor==3.1
# via -r requirements/base.in
django-mptt==0.13.4
# via django-filer
django-open-forms-client==0.2.2
# via -r requirements/base.in
django-ordered-model==3.4.3
# via
# -r requirements/base.in
Expand Down Expand Up @@ -176,6 +179,7 @@ django-sniplates==0.7.0
django-solo==1.2.0
# via
# -r requirements/base.in
# django-open-forms-client
# mozilla-django-oidc-db
# zgw-consumers
django-timeline-logger==2.0.0
Expand Down Expand Up @@ -323,6 +327,7 @@ redis==3.5.3
# via django-redis
requests==2.26.0
# via
# django-open-forms-client
# django-rosetta
# gemma-zds-client
# mozilla-django-oidc
Expand Down
7 changes: 7 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ django==3.2.15
# django-hijack
# django-import-export
# django-localflavor
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-polymorphic
Expand Down Expand Up @@ -233,6 +234,10 @@ django-mptt==0.13.4
# -c requirements/base.txt
# -r requirements/base.txt
# django-filer
django-open-forms-client==0.2.2
# via
# -c requirements/base.txt
# -r requirements/base.txt
django-ordered-model==3.4.3
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -297,6 +302,7 @@ django-solo==1.2.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-open-forms-client
# mozilla-django-oidc-db
# zgw-consumers
django-timeline-logger==2.0.0
Expand Down Expand Up @@ -614,6 +620,7 @@ requests==2.26.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-open-forms-client
# django-rosetta
# gemma-zds-client
# mozilla-django-oidc
Expand Down
7 changes: 7 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ django==3.2.15
# django-hijack
# django-import-export
# django-localflavor
# django-open-forms-client
# django-otp
# django-phonenumber-field
# django-polymorphic
Expand Down Expand Up @@ -264,6 +265,10 @@ django-mptt==0.13.4
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-filer
django-open-forms-client==0.2.2
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
django-ordered-model==3.4.3
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -328,6 +333,7 @@ django-solo==1.2.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-open-forms-client
# mozilla-django-oidc-db
# zgw-consumers
django-timeline-logger==2.0.0
Expand Down Expand Up @@ -712,6 +718,7 @@ requests==2.26.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# ddt-api-calls
# django-open-forms-client
# django-rosetta
# gemma-zds-client
# mozilla-django-oidc
Expand Down
10 changes: 9 additions & 1 deletion src/open_inwoner/conf/app/csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from ..utils import config

# The Open Forms SDK files might differ from the API domain.
OPEN_FORMS_API_DOMAIN = config("OPEN_FORMS_DOMAIN", "")
OPEN_FORMS_SDK_DOMAIN = OPEN_FORMS_API_DOMAIN

#
# Django CSP settings
#
Expand All @@ -13,22 +17,26 @@
"'self'",
) # ideally we'd use BASE_URI but it'd have to be lazy or cause issues
CSP_BASE_URI = ("'self'",)
CSP_FONT_SRC = ("'self'",)
CSP_FONT_SRC = ("'self'", OPEN_FORMS_SDK_DOMAIN)
CSP_FRAME_ANCESTORS = ["'self'"]
CSP_FRAME_SRC = ["'self'"]
CSP_OBJECT_SRC = "'none'"
CSP_SCRIPT_SRC = (
"'self'",
"https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:28992/",
OPEN_FORMS_SDK_DOMAIN,
) # See if the unsafe-eval can be removed....
CSP_STYLE_SRC = (
"'self'",
OPEN_FORMS_SDK_DOMAIN,
) # Fix this. I do not want to have the unsafe-inline here....
CSP_IMG_SRC = (
"'self'",
"data:",
"https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:28992/",
OPEN_FORMS_SDK_DOMAIN,
)
CSP_CONNECT_SRC = ("'self'", OPEN_FORMS_API_DOMAIN)

CSP_UPGRADE_INSECURE_REQUESTS = False # TODO enable on production?
CSP_INCLUDE_NONCE_IN = [
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"mozilla_django_oidc",
"mozilla_django_oidc_db",
"sessionprofile",
"openformsclient",
# Project applications.
"open_inwoner.accounts",
"open_inwoner.components",
Expand Down
33 changes: 33 additions & 0 deletions src/open_inwoner/pdc/migrations/0042_auto_20220929_1726.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.15 on 2022-09-29 15:26

from django.db import migrations, models
import openformsclient.models


class Migration(migrations.Migration):

dependencies = [
("pdc", "0041_auto_20220724_1357"),
]

operations = [
migrations.AddField(
model_name="product",
name="form",
field=openformsclient.models.OpenFormsSlugField(
blank=True,
help_text="Select a form to show this form on the product page. If a form is selected, the link will not be shown.",
verbose_name="Request form",
),
),
migrations.AlterField(
model_name="product",
name="link",
field=models.URLField(
blank=True,
default="",
help_text="Action link to request the product.",
verbose_name="Link",
),
),
]
14 changes: 13 additions & 1 deletion src/open_inwoner/pdc/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from filer.fields.file import FilerFileField
from filer.fields.image import FilerImageField
from openformsclient.models import OpenFormsSlugField
from ordered_model.models import OrderedModel

from open_inwoner.utils.validators import validate_phone_number
Expand Down Expand Up @@ -57,7 +58,14 @@ class Product(models.Model):
verbose_name=_("Link"),
blank=True,
default="",
help_text=_("Action link to request the product"),
help_text=_("Action link to request the product."),
)
form = OpenFormsSlugField(
_("Request form"),
blank=True,
help_text=_(
"Select a form to show this form on the product page. If a form is selected, the link will not be shown."
),
)
content = models.TextField(
verbose_name=_("Content"),
Expand Down Expand Up @@ -154,6 +162,10 @@ class Meta:
def __str__(self):
return self.name

@property
def form_link(self):
return reverse("pdc:product_form", kwargs={"slug": self.slug})

def get_absolute_url(self, category=None):
if not category:
return reverse("pdc:product_detail", kwargs={"slug": self.slug})
Expand Down
12 changes: 12 additions & 0 deletions src/open_inwoner/pdc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CategoryListView,
ProductDetailView,
ProductFinderView,
ProductFormView,
)

app_name = "pdc"
Expand All @@ -26,5 +27,16 @@
ProductDetailView.as_view(),
name="product_detail",
),
path(
f"{PRODUCT_PATH_NAME}/<str:slug>/formulier/",
ProductFormView.as_view(),
name="product_form",
),
# Required to handle dynamic URL-paths appended by Open Forms.
path(
f"{PRODUCT_PATH_NAME}/<str:slug>/formulier/<path:rest>",
ProductFormView.as_view(),
name="product_form",
),
path("finder/", ProductFinderView.as_view(), name="product_finder"),
]
27 changes: 27 additions & 0 deletions src/open_inwoner/pdc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ def get_context_data(self, **kwargs):
return context


class ProductFormView(BaseBreadcrumbMixin, CategoryBreadcrumbMixin, DetailView):
template_name = "pages/product/form.html"
model = Product
breadcrumb_use_pk = False
no_list = True

@cached_property
def crumbs(self):
base_list = [(_("Thema's"), reverse("pdc:category_list"))]
base_list += self.get_categories_breadcrumbs(slug_name="theme_slug")
return base_list + [
(self.get_object().name, self.get_object().get_absolute_url()),
(_("Formulier"), self.request.path),
]

def get_context_data(self, **kwargs):
product = self.get_object()
context = super().get_context_data(**kwargs)

anchors = [
("#title", product.name),
]

context["anchors"] = anchors
return context


class ProductFinderView(FormView):
template_name = "pages/product/finder.html"
form_class = ProductFinderForm
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/master.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load static i18n header_tags card_tags footer_tags button_tags notification_tags anchor_menu_tags view_breadcrumbs utils session_tags %}<!DOCTYPE html>
<html lang="en" class="view {% block view_class %}view--{{ request.resolver_match.namespaces|join:'-' }}-{{ request.resolver_match.url_name }}{% endblock %}">
<html lang="nl" class="view {% block view_class %}view--{{ request.resolver_match.namespaces|join:'-' }}-{{ request.resolver_match.url_name }}{% endblock %}">
<head>
<meta charset="utf-8">
<title>{% block title %}{{ site_name }}{% endblock %}</title>
Expand Down
12 changes: 10 additions & 2 deletions src/open_inwoner/templates/pages/product/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

{% block sidebar_content %}
{% anchor_menu anchors=anchors desktop=True %}
{% if product.link %}
{% if product.form %}
<li class="anchor-menu__list-item">
{% button href=product.form_link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
{% elif product.link %}
<li class="anchor-menu__list-item">
{% button href=product.link size="big" text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
</li>
Expand All @@ -30,7 +34,11 @@ <h1 class="h1" id="title">
<p class="p">{{ object.summary }}</p>
{{ object.content|ckeditor_content|safe }}

{% if product.link %}
{% if product.form %}
{% button_row mobile=True %}
{% button href=product.form_link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
{% elif product.link %}
{% button_row mobile=True %}
{% button href=product.link text=_("Aanvraag starten") primary=True icon="arrow_forward" icon_position="before" %}
{% endbutton_row %}
Expand Down
26 changes: 26 additions & 0 deletions src/open_inwoner/templates/pages/product/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "pages/product/detail.html" %}
{% load openforms button_tags tag_tags %}

{% block extra_css %}

{{ block.super }}
{% openforms_sdk_media %}

{% endblock %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, the side bar {% block sidebar_content %} can be removed and add only a "back or cancel" button, but this can be done when we improve the layout generally.

{% block content %}

<h1 class="h1" id="title">
{{ object.name }}
{% if request.user.is_staff %}
{% button icon="edit" text=_("Bewerken in de Admin") hide_text=True href="admin:pdc_product_change" object_id=object.pk %}
{% endif %}
</h1>
{% tag tags=object.tags.all %}
<p class="p">{{ object.summary }}</p>

{% if object.form %}
{% openforms_form object.form csp_nonce=request.csp_nonce %}
{% endif %}

{% endblock %}