diff options
-rw-r--r-- | experiment/views.py | 6 | ||||
-rw-r--r-- | myadmin/urls.py | 2 | ||||
-rw-r--r-- | myadmin/views.py | 13 | ||||
-rw-r--r-- | templates/admin/index.html | 5 |
4 files changed, 23 insertions, 3 deletions
diff --git a/experiment/views.py b/experiment/views.py index cf507a7..e4ab2ab 100644 --- a/experiment/views.py +++ b/experiment/views.py @@ -58,8 +58,12 @@ def initiation(req): key = str(user_board.mid) settings.boards[key]["experiment_id"] = e.id + global_logfile = settings.SBHS_GLOBAL_LOG_DIR + "/" + key + ".log" + with open(global_logfile, "a") as global_loghandler: + data = "\n\n===================New experiment====================\nUsername :", user.username, "\nExperiment Id :", e.id, "\n" + global_loghandler.write(data) + reset(req) - STATUS = 1 MESSAGE = filename diff --git a/myadmin/urls.py b/myadmin/urls.py index 4e929c7..417fbb0 100644 --- a/myadmin/urls.py +++ b/myadmin/urls.py @@ -12,7 +12,7 @@ urlpatterns = [ url(r'^admin/setdevice/?$', views.set_device_params, name='admin_set_device'), url(r'^admin/gettemp/?$', views.get_device_temp, name='admin_get_temp'), url(r'^admin/monitor/?$', views.monitor_experiment, name='admin_monitor'), - + url(r'^admin/logs/([0-9]+)/?$', views.download_log, name='admin_logs'), url(r'^admin/toggle_allotment_mode/?$', views.toggle_allotment_mode, name='admin_toggle_allotment_mode'), ]
\ No newline at end of file diff --git a/myadmin/views.py b/myadmin/views.py index b4a4f33..bd896e3 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -128,6 +128,19 @@ def monitor_experiment(req): data = {"user": current_user, "logs": logs} return HttpResponse(json.dumps({"status_code":200, "message":data}), content_type="application/json") +@login_required(redirect_field_name=None) +def download_log(req, mid): + checkadmin(req) + try: + global_logfile = settings.SBHS_GLOBAL_LOG_DIR + "/" + mid + ".log" + f = open(global_logfile, "r") + data = f.read() + f.close() + return HttpResponse(data, content_type='text/text') + except: + return HttpResponse("Requested log file doesn't exist.") + + @csrf_exempt def reset_device(req): """Resets the device to fan = 100 and heat = 0 diff --git a/templates/admin/index.html b/templates/admin/index.html index 95956f5..3e9ce15 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -15,6 +15,8 @@ <th>Board MID</th> <th>Status</th> <th>Webcam</th> + <th>Temperature Profile</th> + <th>Download Logs</th> </tr> </thead> <tbody> @@ -23,7 +25,8 @@ <td>{{ b.mid }}</td> <td><span class="label label-{% if b.online %}success{% else %}important{% endif %}">{% if b.online %}Online{% else %}Offline{% endif %}</span></td> <td><a href="{% url 'webcam_show_video_to_admin' b.mid %}" target="_blank">View image</a></td> - <td><a href="{% url 'admin_profile' b.mid %}">View temperature profile</a></td> + <td><a href="{% url 'admin_profile' b.mid %}">View</a></td> + <td><a href="{% url 'admin_logs' b.mid %}">Download</a></td> </tr> {% endfor %} </tbody> |