def data_edit(request, hash): chart = Chart.get_by_id(pretty_decode(hash)) if chart.user != request.g_app_user: return HttpResponse("nacho chart") if request.method == "POST": old_dataset = chart.data or None if chart.data: fs = DataRowFormSet(data=request.POST, instances=chart.data.data_rows) else: fs = DataRowFormSet(data=request.POST) if fs.is_valid(): keys = [] for form in fs.forms: if hasattr(form, "cleaned_data"): dr = DataRow(**form.cleaned_data) keys.append(dr.save()) version = old_dataset.version + 1 if old_dataset else 1 cds = ChartDataSet(version=version, previous_version=old_dataset, data_rows=keys) cds.save() chart.data = cds chart.has_data = True chart.save() return HttpResponseRedirect(reverse("chart-detail", args=(chart.get_hash(),))) else: if chart.data: fs = DataRowFormSet(instances=chart.data.data_rows) else: fs = DataRowFormSet() return render_to_response("charter/data_edit.html", {"formset": fs, "user": request.g_app_user})
def oembed(request): if not request.GET.get("url"): return HttpResponse('{"error":"No Url Provided."}') url_parts = urlparse(request.GET.get("url")) keys = url_parts.path.split("/") for i in range(len(keys)): if len(keys[i]) and keys[i][-1] == "+": # stats keys[i] = keys[i][:-1] chart = Chart.get_by_id(pretty_decode(keys[1])) chart.counter += 1 chart.put() if len(keys) > 3: version = ChartDataSet.get(keys[2]) perma = reverse("chart-detail-version", args=(pretty_decocde(keys[1]), keys[2])) else: version = chart.data perma = reverse("chart-detail", args=(pretty_decode(keys[1]),)) graph_url, graph = get_graph(version, _cht[chart.chart_type], 600, 480) oembed = { "version": str(version.version), "type": "photo", "width": 600, "height": 480, "title": chart.name, "url": graph_url, "author": chart.user.email(), "provider_name": "Permachart", "provier_url": "http://permachart.appengine.com", } return HttpResponse(json.dumps(oembed, sort_keys=True, indent=4), mimetype="application/javascript")
def chart_detail(request, hash): chart = Chart.get_by_id(pretty_decode(hash)) if chart.data: graph_url, graph = get_graph(chart.data, _cht[chart.chart_type]) else: graph_url, graph = None, None return render_to_response( "charter/detail.html", {"chart": chart, "graph": graph, "graph_url": graph_url, "version": chart.data, "user": request.g_app_user}, )
def chart_detail_version(request, hash, version_key): chart = Chart.get_by_id(pretty_decode(hash)) version = ChartDataSet.get(version_key) graph_url, graph = get_graph(version, _cht[chart.chart_type]) return render_to_response( "charter/detail.html", { "chart": chart, "graph": graph, "graph_url": graph_url, "version": version, "version_specific": True, "user": request.g_app_user, }, )