def _getPresentation(self, key_name): type = self.data.GET.get("type", "json") if type == "json": self.response["Content-Type"] = "application/json" self._presenter = JsonPresenter() elif type == "gviz": self.response["Content-Type"] = "application/json" self._presenter = GvizPresenter() else: raise UnsupportedFormatException("Requested format is not supported.") return self._presenter.get(key_name)
class StatisticFetcher(RequestHandler): """Loads data for a particular statistic. """ def __init__(self): self._presenter = None def checkAccess(self): key_name = self.data.kwargs["key_name"] # TODO(dhans): check if the statistic is visible pass def djangoURLPatterns(self): return [url(r"statistic/fetch/(?P<key_name>(\w+))$", self, name="gsoc_statistic_fetch")] def _getPresentation(self, key_name): type = self.data.GET.get("type", "json") if type == "json": self.response["Content-Type"] = "application/json" self._presenter = JsonPresenter() elif type == "gviz": self.response["Content-Type"] = "application/json" self._presenter = GvizPresenter() else: raise UnsupportedFormatException("Requested format is not supported.") return self._presenter.get(key_name) def jsonContext(self): key_name = self.data.kwargs["key_name"] presentation = self._getPresentation(key_name) return presentation