Skip to content

Commit

Permalink
Add endpoint to get "zones" from a campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
boulch committed Feb 18, 2025
1 parent 123847b commit c3a749c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/imio/smartweb/core/contents/rest/campaign/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@
layer="imio.smartweb.core.interfaces.IImioSmartwebCoreLayer"
/>

<plone:service
name="@zones"
method="GET"
accept="application/json"
for="imio.smartweb.core.contents.ICampaignView"
factory=".endpoint.ZonesEndpointGet"
permission="zope2.View"
layer="imio.smartweb.core.interfaces.IImioSmartwebCoreLayer"
/>

</configure>
26 changes: 26 additions & 0 deletions src/imio/smartweb/core/contents/rest/campaign/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ def query_url(self):
return url


@implementer(IExpandableElement)
@adapter(Interface, Interface)
class ZonesEndpoint(BaseEndpoint):

def __call__(self):
json_res = {}
user = api.portal.get_registry_record("smartweb.iaideabox_api_username")
pwd = api.portal.get_registry_record("smartweb.iaideabox_api_password")
json = get_basic_auth_json(self.query_url, user, pwd)
json_res["items"] = json["data"]
json_res["items_total"] = json.get("count")
return json_res

@property
def query_url(self):
wcs_api = get_ts_api_url("wcs")
campaign_id = self.context.linked_campaign
url = f"{wcs_api}/cards/imio-ideabox-zone/list?campagne={campaign_id}&full=on"
return url


class CampaignEndpointGet(BaseService):
def reply(self):
return CampaignEndpoint(self.context, self.request)()
Expand All @@ -96,6 +117,11 @@ def reply(self):
return get_ideabox_basic_auth_header()


class ZonesEndpointGet(BaseService):
def reply(self):
return ZonesEndpoint(self.context, self.request)()


def get_ideabox_basic_auth_header() -> str:
user = api.portal.get_registry_record("smartweb.iaideabox_api_username")
pwd = api.portal.get_registry_record("smartweb.iaideabox_api_password")
Expand Down
3 changes: 2 additions & 1 deletion src/imio/smartweb/core/contents/rest/campaign/view.pt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<body>
<metal:main fill-slot="content-core">
<div class="full-width">
<smartweb-campaign tal:attributes="query-url view/local_query_url;
<smartweb-campaign tal:attributes="query-url view/local_query_url;
query-zones-url view/local_query_zones_url;
batch-size view/batch_size;
current-language view/current_language;
display-map view/display_map;
Expand Down
5 changes: 5 additions & 0 deletions src/imio/smartweb/core/contents/rest/campaign/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ class CampaignViewView(BaseRestView):
@property
def display_map(self):
return self.context.display_map

@property
def local_query_zones_url(self):
base_url = self.context.absolute_url()
return f"{base_url}/@zones"

0 comments on commit c3a749c

Please sign in to comment.