def pricing_table_json(request, product, locale): if product not in [c[0] for c in SoftwareProductType.CHOICES]: return HttpResponseBadRequest("Not a valid product") if locale not in [l[0] for l in settings.LANGUAGES]: return HttpResponseBadRequest("Not a supported language.") translation.activate(locale) table = PricingTable.get_table_by_product(product) table_json = json.dumps(table, cls=LazyEncoder) translation.deactivate() return HttpResponse(table_json, content_type='application/json')
def pricing_table_json(request, product, locale): if product not in [c[0] for c in SoftwareProductType.CHOICES]: return HttpResponseBadRequest("Not a valid product") if locale not in [l[0] for l in settings.LANGUAGES]: return HttpResponseBadRequest("Not a supported language.") with localize(locale): table = PricingTable.get_table_by_product(product) table_json = json.dumps(table, cls=LazyEncoder) # This is necessary for responding to requests from Internet Explorer. # IE you can FOAD. callback = request.GET.get("callback") or request.POST.get("callback") if callback is not None: table_json = "%s(%s)" % (callback, table_json) response = HttpResponse(table_json, content_type="application/json; charset=UTF-8") response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS" response["Access-Control-Max-Age"] = "1000" response["Access-Control-Allow-Headers"] = "*" return response
def pricing_table_json(request, product, locale): if product not in [c[0] for c in SoftwareProductType.CHOICES]: return HttpResponseBadRequest("Not a valid product") if locale not in [l[0] for l in settings.LANGUAGES]: return HttpResponseBadRequest("Not a supported language.") with localize(locale): table = PricingTable.get_table_by_product(product) table_json = json.dumps(table, cls=LazyEncoder) # This is necessary for responding to requests from Internet Explorer. # IE you can FOAD. callback = request.GET.get('callback') or request.POST.get('callback') if callback is not None: table_json = "%s(%s)" % (callback, table_json) response = HttpResponse(table_json, content_type='application/json; charset=UTF-8') response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS" response["Access-Control-Max-Age"] = "1000" response["Access-Control-Allow-Headers"] = "*" return response