Skip to content

Commit 37ee062

Browse files
alextremepi-sigma
authored andcommitted
[#2798] Integrate objects API to fetch external tasks ("externe taken")
1 parent 1e2e548 commit 37ee062

File tree

14 files changed

+342
-14
lines changed

14 files changed

+342
-14
lines changed

requirements/base.in

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ git+https://github.com/maykinmedia/django-celery-monitor@74b1252#egg=django_cele
9494
zgw-consumers
9595
zgw-consumers-oas
9696
notifications-api-common
97+
git+https://github.com/maykinmedia/objects-api-client-django.git#egg=objects-api-client-django
9798

9899
# 2FA SMS verification
99100
oath

requirements/base.txt

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ asgiref==3.7.2
1616
# via django
1717
asn1crypto==1.5.1
1818
# via webauthn
19+
async-timeout==4.0.3
20+
# via redis
1921
attrs==21.2.0
2022
# via
2123
# glom
@@ -146,6 +148,7 @@ django==4.2.20
146148
# mozilla-django-oidc-db
147149
# notifications-api-common
148150
# sentry-sdk
151+
# objects-api-client-django
149152
# zgw-consumers
150153
# zgw-consumers-oas
151154
django-admin-index==3.1.0
@@ -274,6 +277,7 @@ django-solo==2.2.0
274277
# django-open-forms-client
275278
# mozilla-django-oidc-db
276279
# notifications-api-common
280+
# objects-api-client-django
277281
# zgw-consumers
278282
django-timeline-logger==4.0.0
279283
# via -r requirements/base.in
@@ -344,9 +348,7 @@ faker==27.0.0
344348
fontawesomefree==6.4.2
345349
# via -r requirements/base.in
346350
fonttools[woff]==4.43.0
347-
# via
348-
# fonttools
349-
# weasyprint
351+
# via weasyprint
350352
furl==2.1.3
351353
# via
352354
# -r requirements/base.in
@@ -417,6 +419,8 @@ notifications-api-common==0.2.2
417419
# via -r requirements/base.in
418420
oath==1.4.4
419421
# via -r requirements/base.in
422+
objects-api-client-django @ git+https://github.com/maykinmedia/objects-api-client-django.git
423+
# via -r requirements/base.in
420424
odfpy==1.4.1
421425
# via tablib
422426
openpyxl==3.0.9
@@ -523,6 +527,7 @@ requests==2.31.0
523527
# maykin-python3-saml
524528
# messagebird
525529
# mozilla-django-oidc
530+
# objects-api-client-django
526531
# zgw-consumers
527532
ruamel-yaml==0.18.10
528533
# via django-setup-configuration
@@ -551,9 +556,7 @@ sqlparse==0.4.4
551556
svglib==1.5.1
552557
# via easy-thumbnails
553558
tablib[html,ods,xls,xlsx,yaml]==3.1.0
554-
# via
555-
# django-import-export
556-
# tablib
559+
# via django-import-export
557560
tinycss2==1.1.1
558561
# via
559562
# -r requirements/base.in
@@ -614,6 +617,7 @@ zgw-consumers==0.36.1
614617
# via
615618
# -r requirements/base.in
616619
# notifications-api-common
620+
# objects-api-client-django
617621
zgw-consumers-oas==1.0.0
618622
# via -r requirements/base.in
619623
zopfli==0.1.9

requirements/ci.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ asn1crypto==1.5.1
3737
# webauthn
3838
astroid==2.15.8
3939
# via pylint
40+
async-timeout==4.0.3
41+
# via
42+
# -c requirements/base.txt
43+
# -r requirements/base.txt
44+
# redis
4045
attrs==21.2.0
4146
# via
4247
# -c requirements/base.txt
@@ -238,6 +243,7 @@ django==4.2.20
238243
# mozilla-django-oidc-db
239244
# notifications-api-common
240245
# sentry-sdk
246+
# objects-api-client-django
241247
# zgw-consumers
242248
# zgw-consumers-oas
243249
django-admin-index==3.1.0
@@ -462,6 +468,7 @@ django-solo==2.2.0
462468
# django-open-forms-client
463469
# mozilla-django-oidc-db
464470
# notifications-api-common
471+
# objects-api-client-django
465472
# zgw-consumers
466473
django-timeline-logger==4.0.0
467474
# via
@@ -482,7 +489,6 @@ django-two-factor-auth[phonenumberslite,webauthn]==1.16.0
482489
# via
483490
# -c requirements/base.txt
484491
# -r requirements/base.txt
485-
# django-two-factor-auth
486492
# maykin-2fa
487493
django-view-breadcrumbs==2.5.1
488494
# via
@@ -558,7 +564,6 @@ easy-thumbnails[svg]==2.8.5
558564
# -r requirements/base.txt
559565
# django-filer
560566
# djangocms-picture
561-
# easy-thumbnails
562567
ecs-logging==2.1.0
563568
# via
564569
# -c requirements/base.txt
@@ -612,7 +617,6 @@ fonttools[woff]==4.43.0
612617
# via
613618
# -c requirements/base.txt
614619
# -r requirements/base.txt
615-
# fonttools
616620
# weasyprint
617621
freezegun==1.1.0
618622
# via -r requirements/test-tools.in
@@ -771,6 +775,10 @@ oath==1.4.4
771775
# via
772776
# -c requirements/base.txt
773777
# -r requirements/base.txt
778+
objects-api-client-django @ git+https://github.com/maykinmedia/objects-api-client-django.git
779+
# via
780+
# -c requirements/base.txt
781+
# -r requirements/base.txt
774782
odfpy==1.4.1
775783
# via
776784
# -c requirements/base.txt
@@ -989,6 +997,7 @@ requests==2.31.0
989997
# maykin-python3-saml
990998
# messagebird
991999
# mozilla-django-oidc
1000+
# objects-api-client-django
9921001
# requests-mock
9931002
# sphinx
9941003
# zgw-consumers
@@ -1079,7 +1088,6 @@ tablib[html,ods,xls,xlsx,yaml]==3.1.0
10791088
# -c requirements/base.txt
10801089
# -r requirements/base.txt
10811090
# django-import-export
1082-
# tablib
10831091
tblib==1.7.0
10841092
# via -r requirements/test-tools.in
10851093
tinycss2==1.1.1
@@ -1197,6 +1205,7 @@ zgw-consumers==0.36.1
11971205
# -c requirements/base.txt
11981206
# -r requirements/base.txt
11991207
# notifications-api-common
1208+
# objects-api-client-django
12001209
zgw-consumers-oas==1.0.0
12011210
# via
12021211
# -c requirements/base.txt

requirements/dev.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ astroid==2.15.8
4343
# -c requirements/ci.txt
4444
# -r requirements/ci.txt
4545
# pylint
46+
async-timeout==4.0.3
47+
# via
48+
# -c requirements/ci.txt
49+
# -r requirements/ci.txt
50+
# redis
4651
attrs==21.2.0
4752
# via
4853
# -c requirements/ci.txt
@@ -278,6 +283,7 @@ django==4.2.20
278283
# mozilla-django-oidc-db
279284
# notifications-api-common
280285
# sentry-sdk
286+
# objects-api-client-django
281287
# zgw-consumers
282288
# zgw-consumers-oas
283289
django-admin-index==3.1.0
@@ -508,6 +514,7 @@ django-solo==2.2.0
508514
# django-open-forms-client
509515
# mozilla-django-oidc-db
510516
# notifications-api-common
517+
# objects-api-client-django
511518
# zgw-consumers
512519
django-timeline-logger==4.0.0
513520
# via
@@ -528,7 +535,6 @@ django-two-factor-auth[phonenumberslite,webauthn]==1.16.0
528535
# via
529536
# -c requirements/ci.txt
530537
# -r requirements/ci.txt
531-
# django-two-factor-auth
532538
# maykin-2fa
533539
django-view-breadcrumbs==2.5.1
534540
# via
@@ -606,7 +612,6 @@ easy-thumbnails[svg]==2.8.5
606612
# -r requirements/ci.txt
607613
# django-filer
608614
# djangocms-picture
609-
# easy-thumbnails
610615
ecs-logging==2.1.0
611616
# via
612617
# -c requirements/ci.txt
@@ -673,7 +678,6 @@ fonttools[woff]==4.43.0
673678
# via
674679
# -c requirements/ci.txt
675680
# -r requirements/ci.txt
676-
# fonttools
677681
# weasyprint
678682
freezegun==1.1.0
679683
# via
@@ -879,6 +883,10 @@ oath==1.4.4
879883
# via
880884
# -c requirements/ci.txt
881885
# -r requirements/ci.txt
886+
objects-api-client-django @ git+https://github.com/maykinmedia/objects-api-client-django.git
887+
# via
888+
# -c requirements/ci.txt
889+
# -r requirements/ci.txt
882890
odfpy==1.4.1
883891
# via
884892
# -c requirements/ci.txt
@@ -1139,6 +1147,7 @@ requests==2.31.0
11391147
# maykin-python3-saml
11401148
# messagebird
11411149
# mozilla-django-oidc
1150+
# objects-api-client-django
11421151
# requests-mock
11431152
# sphinx
11441153
# zgw-consumers
@@ -1273,7 +1282,6 @@ tablib[html,ods,xls,xlsx,yaml]==3.1.0
12731282
# -c requirements/ci.txt
12741283
# -r requirements/ci.txt
12751284
# django-import-export
1276-
# tablib
12771285
tblib==1.7.0
12781286
# via
12791287
# -c requirements/ci.txt
@@ -1420,6 +1428,7 @@ zgw-consumers==0.36.1
14201428
# -c requirements/ci.txt
14211429
# -r requirements/ci.txt
14221430
# notifications-api-common
1431+
# objects-api-client-django
14231432
zgw-consumers-oas==1.0.0
14241433
# via
14251434
# -c requirements/ci.txt
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from .appointments import UserAppointmentsPlugin
2+
from .tasks import TasksPlugin
23
from .userfeed import UserFeedPlugin
34
from .videoplayer import VideoPlayerPlugin
45

56
__all__ = [
67
"UserAppointmentsPlugin",
78
"UserFeedPlugin",
9+
"TasksPlugin",
810
"VideoPlayerPlugin",
911
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from django.utils.translation import gettext as _
2+
3+
from cms.plugin_base import CMSPluginBase
4+
from cms.plugin_pool import plugin_pool
5+
6+
from objectsapiclient.models import Configuration
7+
8+
from ..models import TasksConfig
9+
10+
11+
@plugin_pool.register_plugin
12+
class TasksPlugin(CMSPluginBase):
13+
"""
14+
Uses the Objects API to retrieve and show tasks according to the MijnTaken Objecttypes schema
15+
Reuses the UserFeedPlugin template
16+
"""
17+
18+
model = TasksConfig
19+
name = _("Task list Plugin")
20+
render_template = "cms/plugins/tasks/tasks.html"
21+
cache = False
22+
23+
def render(self, context, instance, placeholder):
24+
request = context["request"]
25+
context["instance"] = instance
26+
context["tasks"] = []
27+
28+
if not request.user.is_authenticated or not (bsn := request.user.bsn):
29+
return context
30+
31+
task_objects = self.get_tasks_by_bsn(user_bsn=bsn)
32+
tasks = []
33+
for obj in task_objects:
34+
task_dict = obj.record["data"]
35+
task_dict["task_url"] = obj.url
36+
tasks.append(task_dict)
37+
context["tasks"] = tasks
38+
39+
return context
40+
41+
def get_tasks(self):
42+
objects_client = Configuration.get_solo().client
43+
return [
44+
obj
45+
for obj in objects_client.get_objects(
46+
object_type_uuid=self.model.object_type
47+
)
48+
]
49+
50+
def get_tasks_by_bsn(self, user_bsn):
51+
tasks = []
52+
for task in self.get_tasks():
53+
data = task.record["data"]
54+
identificatie = data["identificatie"]
55+
56+
if not identificatie or identificatie["type"] != "bsn":
57+
continue
58+
59+
task_bsn = identificatie["value"]
60+
if task_bsn and task_bsn == user_bsn:
61+
tasks += [task]
62+
63+
return tasks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 4.2.16 on 2024-10-06 13:07
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
import objectsapiclient.models
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
("cms", "0022_auto_20180620_1551"),
13+
("plugins", "0005_userappointments"),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name="TasksConfig",
19+
fields=[
20+
(
21+
"cmsplugin_ptr",
22+
models.OneToOneField(
23+
auto_created=True,
24+
on_delete=django.db.models.deletion.CASCADE,
25+
parent_link=True,
26+
primary_key=True,
27+
related_name="%(app_label)s_%(class)s",
28+
serialize=False,
29+
to="cms.cmsplugin",
30+
),
31+
),
32+
(
33+
"title",
34+
models.CharField(
35+
default="Mijn Taken",
36+
help_text="The title of the tasks block",
37+
max_length=250,
38+
verbose_name="Title",
39+
),
40+
),
41+
(
42+
"object_type",
43+
objectsapiclient.models.ObjectTypeField(
44+
db_index=False, max_length=100
45+
),
46+
),
47+
],
48+
options={
49+
"abstract": False,
50+
},
51+
bases=("cms.cmsplugin",),
52+
),
53+
]
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from .appointments import UserAppointments
2+
from .tasks import TasksConfig
23
from .userfeed import UserFeed
34
from .videoplayer import VideoPlayer
45

56
__all__ = [
67
"UserAppointments",
78
"UserFeed",
9+
"TasksConfig",
810
"VideoPlayer",
911
]

0 commit comments

Comments
 (0)