- @param instrument: instrument name
- @param run_id: run number
+ Ajax call to get plot data as an html
+ @param instrument: instrument name
+ @param run_id: run number
"""
- data_type = PlotData.get_data_type_from_string('html')
+ data_type = PlotData.get_data_type_from_string("html")
plot_data = view_util.get_plot_data(instrument, run_id, data_type=data_type)
if plot_data is None:
@@ -102,23 +112,24 @@ def update_as_html(request, instrument, run_id):
return HttpResponseNotFound(error_msg)
response = HttpResponse(str(plot_data.data), content_type="text/html")
- response['Content-Length'] = len(response.content)
+ response["Content-Length"] = len(response.content)
return response
+
@check_credentials
def _store(request, instrument, run_id=None, as_user=False):
"""
- Store plot data
- @param instrument: instrument name or user name
- @param run_id: run number
- @param as_user: if True, we will store as user data
+ Store plot data
+ @param instrument: instrument name or user name
+ @param run_id: run number
+ @param as_user: if True, we will store as user data
"""
- if request.user.is_authenticated and 'file' in request.FILES:
- raw_data = request.FILES['file'].read().decode('utf-8')
+ if request.user.is_authenticated and "file" in request.FILES:
+ raw_data = request.FILES["file"].read().decode("utf-8")
data_type_default = PlotData.get_data_type_from_data(raw_data)
- data_type = request.POST.get('data_type', default=data_type_default)
+ data_type = request.POST.get("data_type", default=data_type_default)
if as_user:
- data_id = request.POST.get('data_id', default='')
+ data_id = request.POST.get("data_id", default="")
view_util.store_user_data(instrument, data_id, raw_data, data_type)
else:
view_util.store_plot_data(instrument, run_id, raw_data, data_type)
@@ -127,28 +138,31 @@ def _store(request, instrument, run_id=None, as_user=False):
return HttpResponse()
+
@csrf_exempt
def upload_plot_data(request, instrument, run_id):
"""
- Upload plot data
- @param instrument: instrument name
- @param run_id: run number
+ Upload plot data
+ @param instrument: instrument name
+ @param run_id: run number
"""
return _store(request, instrument, run_id, as_user=False)
+
@csrf_exempt
def upload_user_data(request, user):
"""
- Upload plot data
- @param user: user identifier to use
+ Upload plot data
+ @param user: user identifier to use
"""
return _store(request, user, as_user=True)
+
@csrf_exempt
@check_credentials
def get_data_list(request, instrument):
"""
- Get a list of user data
+ Get a list of user data
"""
if request.user.is_authenticated:
instrument_object = get_object_or_404(Instrument, name=instrument.lower())
@@ -156,11 +170,15 @@ def get_data_list(request, instrument):
for item in DataRun.objects.filter(instrument=instrument_object):
localtime = timezone.localtime(item.created_on)
df = dateformat.DateFormat(localtime)
- data_list.append(dict(id=item.id,
- run_number=str(item.run_number),
- run_id=item.run_id,
- timestamp=item.created_on.isoformat(),
- created_on=df.format(settings.DATETIME_FORMAT)))
+ data_list.append(
+ dict(
+ id=item.id,
+ run_number=str(item.run_number),
+ run_id=item.run_id,
+ timestamp=item.created_on.isoformat(),
+ created_on=df.format(settings.DATETIME_FORMAT),
+ )
+ )
response = HttpResponse(json.dumps(data_list), content_type="application/json")
return response
else:
diff --git a/live_data_server/templates/base.html b/src/live_data_server/templates/base.html
similarity index 99%
rename from live_data_server/templates/base.html
rename to src/live_data_server/templates/base.html
index ac1f4c3..6936315 100644
--- a/live_data_server/templates/base.html
+++ b/src/live_data_server/templates/base.html
@@ -23,4 +23,4 @@
{% endblock %}