Skip to content

Commit

Permalink
Adding Objects API client integration
Browse files Browse the repository at this point in the history
  • Loading branch information
alextreme committed Sep 27, 2023
1 parent c294eef commit de1a533
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 0 deletions.
Empty file.
14 changes: 14 additions & 0 deletions src/open_inwoner/cms/objects/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.utils.translation import ugettext_lazy as _

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

from .models import ObjectsList


@plugin_pool.register_plugin
class ObjectsListPlugin(CMSPluginBase):
model = ObjectsList
name = _("Object List Plugin")
render_template = "cms/objects/objects_list.html"
cache = False
46 changes: 46 additions & 0 deletions src/open_inwoner/cms/objects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.2.20 on 2023-09-17 20:14

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

import objectsapiclient.models


class Migration(migrations.Migration):

initial = True

dependencies = [
("cms", "0022_auto_20180620_1551"),
]

operations = [
migrations.CreateModel(
name="ObjectsList",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
related_name="objects_objectslist",
serialize=False,
to="cms.cmsplugin",
),
),
("title", models.CharField(max_length=250, verbose_name="Title")),
(
"object_type",
objectsapiclient.models.ObjectTypeField(
db_index=False, max_length=100
),
),
],
options={
"abstract": False,
},
bases=("cms.cmsplugin",),
),
]
Empty file.
20 changes: 20 additions & 0 deletions src/open_inwoner/cms/objects/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from django.db import models
from django.utils.translation import ugettext_lazy as _

from cms.models import CMSPlugin
from objectsapiclient.models import Configuration, ObjectTypeField


class ObjectsList(CMSPlugin):
title = models.CharField(_("Title"), max_length=250)
object_type = ObjectTypeField() # Stores the UUID of the selected object_type

def get_objects(self):
return Configuration.get_solo().client.get_objects(
object_type_uuid=self.object_type
)

def __str__(self):
return self.title
3 changes: 3 additions & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"mozilla_django_oidc_db",
"sessionprofile",
"openformsclient",
"objectsapiclient",
"django_htmx",
"django_yubin",
"log_outgoing_requests",
Expand Down Expand Up @@ -215,6 +216,7 @@
"open_inwoner.cms.banner",
"open_inwoner.cms.extensions",
"open_inwoner.cms.footer",
"open_inwoner.cms.objects",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -536,6 +538,7 @@
"QuestionnairePlugin",
"ProductFinderPlugin",
"ProductLocationPlugin",
"ObjectsListPlugin",
],
"text_only_plugins": ["LinkPlugin"],
"name": _("Content"),
Expand Down
17 changes: 17 additions & 0 deletions src/open_inwoner/templates/cms/objects/objects_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% load i18n sekizai_tags %}

{% load i18n button_tags card_tags utils icon_tags %}
<h2 class="h2">
{{ instance.title }}
</h2>
<div class="plans-cards card-container card-container--columns-4">
{% for object in instance.get_objects %}
{% render_card image_object_fit="cover" %}
<div class="card__content">
<h3 class="h3 object-list">{{ object.record.index }}</h3>
{{ object.uuid }}
</div>
{% endrender_card %}
{% endfor %}
</div>

0 comments on commit de1a533

Please sign in to comment.