Skip to content
Snippets Groups Projects
Verified Commit 8e6ddbc9 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Generalise default callback name

parent 7d486f6a
No related branches found
No related tags found
No related merge requests found
...@@ -10,13 +10,15 @@ from .types import IconifyJSON ...@@ -10,13 +10,15 @@ from .types import IconifyJSON
class BaseJSONView(View): class BaseJSONView(View):
default_callback: str = "Console.log"
def get_data(self, request: HttpRequest) -> dict: def get_data(self, request: HttpRequest) -> dict:
raise NotImplementedError("You must implement this method in your view.") raise NotImplementedError("You must implement this method in your view.")
def get(self, request: HttpRequest, format_: str = "json", *args, **kwargs) -> HttpResponse: def get(self, request: HttpRequest, format_: str = "json", *args, **kwargs) -> HttpResponse:
# For JSONP, the callback name has to be passed # For JSONP, the callback name has to be passed
if format_ == "js": if format_ == "js":
callback = request.GET.get("callback", "SimpleSVG._loaderCallback") callback = request.GET.get("callback", self.default_callback)
# Client can request pretty-printing of JSON # Client can request pretty-printing of JSON
if request.GET.get("pretty", "0").lower() in ("1", "true"): if request.GET.get("pretty", "0").lower() in ("1", "true"):
...@@ -60,6 +62,8 @@ class CollectionsView(BaseJSONView): ...@@ -60,6 +62,8 @@ class CollectionsView(BaseJSONView):
class IconifyJSONView(BaseJSONView): class IconifyJSONView(BaseJSONView):
"""Serve the Iconify icon data retrieval API.""" """Serve the Iconify icon data retrieval API."""
default_callback: str = "SimpleSVG._loaderCallback"
def get_data(self, request: HttpRequest, collection: str) -> dict: def get_data(self, request: HttpRequest, collection: str) -> dict:
"""Retrieve a set of icons using a GET request. """Retrieve a set of icons using a GET request.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment