Skip to content

Commit

Permalink
🐛 [#426] fix ObjectKanaal
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Aug 12, 2024
1 parent 1b7ae88 commit 2d5efa3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/objects/api/kanalen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.db import models

from notifications_api_common.kanalen import Kanaal
from notifications_api_common.kanalen import KANAAL_REGISTRY, Kanaal

from objects.core.models import ObjectRecord

Expand All @@ -20,6 +20,8 @@ def __init__(
# check that we're refering to existing fields
self.kenmerken = kenmerken or ()

KANAAL_REGISTRY.add(self)

def get_kenmerken(self, obj: models.Model, data: dict = None) -> dict:
data = data or {}
return {
Expand All @@ -29,6 +31,28 @@ def get_kenmerken(self, obj: models.Model, data: dict = None) -> dict:
for kenmerk in self.kenmerken
}

@property
def description(self):
"""For Objects endpoint main resource is ObjectRecord, so adjust info here"""
kenmerk_template = "* `{kenmerk}`: {help_text}"
main_resource = self.main_resource.object.field.related_model
kenmerken = [
kenmerk_template.format(
kenmerk=kenmerk,
help_text=main_resource._meta.get_field(kenmerk).help_text,
)
for kenmerk in self.kenmerken
]

description = (
"**Main resource**\n\n"
"`{options.model_name}`\n\n\n\n"
"**Kenmerken**\n\n"
"{kenmerken}"
).format(options=main_resource._meta, kenmerken="\n".join(kenmerken))

return description


KANAAL_OBJECTEN = ObjectKanaal(
settings.NOTIFICATIONS_KANAAL,
Expand Down

0 comments on commit 2d5efa3

Please sign in to comment.