Split the uri so we can determine the resource that is being requested (note that because it starts with a /, the first item in the list will be a blank string) :param request_uri: (str) django.http.HttpRequest.path
(request_uri: str)
| 29 | |
| 30 | |
| 31 | def get_resource_from_uri(request_uri: str) -> Resource | None: |
| 32 | """ |
| 33 | Split the uri so we can determine the resource that is being requested |
| 34 | (note that because it starts with a /, the first item in the list will be a blank string) |
| 35 | |
| 36 | :param request_uri: (str) django.http.HttpRequest.path |
| 37 | """ |
| 38 | split_uri = request_uri.split("/")[1:] |
| 39 | if not (len(split_uri) >= 3 and split_uri[0] == "api"): |
| 40 | logger.debug("not tracking event for uri %s" % request_uri) |
| 41 | # this isn't an API request so we don't need to track an event for it |
| 42 | return None |
| 43 | |
| 44 | # uri will be in the form /api/v1/<resource>/... |
| 45 | return Resource.get_from_name(split_uri[2]) |
| 46 | |
| 47 | |
| 48 | def track_request_googleanalytics(request): # type: ignore[no-untyped-def] |
no test coverage detected
searching dependent graphs…