0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/ee/clickhouse/views/paths.py
Michael Matloka 4ae063d0e6
Add project-nested version of all project-dependent endpoints (#6203)
* Add project-nested version of all project-dependent endpoints

* Fix hook `perform_create`

* Adjust `plugin-configs` to adhere to style of other endpoints
2021-10-01 13:38:33 +02:00

29 lines
989 B
Python

from django.db import connection
from rest_framework import request, viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from ee.clickhouse.client import sync_execute
from ee.clickhouse.queries import ClickhousePaths
from ee.clickhouse.sql.events import ELEMENT_TAG_COUNT
from posthog.api.paths import PathsViewSet
from posthog.models import Event, Filter
from posthog.models.filters.path_filter import PathFilter
class ClickhousePathsViewSet(PathsViewSet):
@action(methods=["GET"], detail=False)
def elements(self, request: request.Request, **kwargs): # type: ignore
team = self.team
response = sync_execute(ELEMENT_TAG_COUNT, {"team_id": team.pk, "limit": 20})
resp = []
for row in response:
resp.append({"name": row[0], "id": row[1], "count": row[2]})
return Response(resp)
class LegacyClickhousePathsViewSet(ClickhousePathsViewSet):
legacy_team_compatibility = True