From 9497eb7c892d2be83c2e4dc0020b9a1ae7593b78 Mon Sep 17 00:00:00 2001 From: Retspen Date: Tue, 24 Mar 2015 14:45:38 +0200 Subject: [PATCH] Added profile page --- accounts/views.py | 24 ++++++++++++++++++ instances/views.py | 14 +++++------ templates/profile.html | 55 ++++++++++++++++++++++++++++++++++++++++-- vrtManager/instance.py | 3 --- 4 files changed, 83 insertions(+), 13 deletions(-) diff --git a/accounts/views.py b/accounts/views.py index 27bcf11..e2025cd 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -16,6 +16,30 @@ def profile(request): if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('index')) + error_messages = [] + user = User.objects.get(id=request.user.id) + + if request.method == 'POST': + if 'username' in request.POST: + username = request.POST.get('username', '') + email = request.POST.get('email', '') + user.first_name = username + user.email = email + user.save() + return HttpResponseRedirect(request.get_full_path()) + if 'oldpasswd' in request.POST: + oldpasswd = request.POST.get('oldpasswd', '') + password1 = request.POST.get('passwd1', '') + password2 = request.POST.get('passwd2', '') + if password1 and password2 and password1 != password2: + error_messages.append("Passwords don't match") + if not user.check_password(oldpasswd): + error_messages.append("Old password is wrong!") + if not error_messages: + user.set_password(password1) + user.save() + return HttpResponseRedirect(request.get_full_path()) + return render(request, 'profile.html', locals()) diff --git a/instances/views.py b/instances/views.py index b03c82a..cc3c1e8 100644 --- a/instances/views.py +++ b/instances/views.py @@ -411,7 +411,7 @@ def instance(request, compute_id, vname): return render(request, 'instance.html', locals()) -def inst_status(request, compute_id, vname): +def inst_status(request, host_id, vname): """ :param request: :return: @@ -420,7 +420,9 @@ def inst_status(request, compute_id, vname): if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('login')) - compute = Compute.objects.get(id=compute_id) + compute = Compute.objects.get(id=host_id) + response = HttpResponse() + response['Content-Type'] = "text/javascript" try: conn = wvmInstance(compute.hostname, @@ -428,14 +430,10 @@ def inst_status(request, compute_id, vname): compute.password, compute.type, vname) - status = conn.get_status() + data = json.dumps({'status': conn.get_status()}) conn.close() except libvirtError: - status = None - - data = json.dumps({'status': status}) - response = HttpResponse() - response['Content-Type'] = "text/javascript" + data = json.dumps({'error': 'Error 500'}) response.write(data) return response diff --git a/templates/profile.html b/templates/profile.html index d2a0b1c..75d15fc 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% block title %}{% trans "Logs" %}{% endblock %} +{% block title %}{% trans "Profile" %}{% endblock %} {% block content %}
@@ -14,7 +14,58 @@
- + +
{% csrf_token %} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
{% csrf_token %} +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
{% endblock %} \ No newline at end of file diff --git a/vrtManager/instance.py b/vrtManager/instance.py index f284f25..49baf4a 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -347,9 +347,7 @@ class wvmInstance(wvmConnect): else: rd_diff_usage = 0 wr_diff_usage = 0 - dev_usage.append({'dev': dev[1], 'rd': rd_diff_usage, 'wr': wr_diff_usage}) - return dev_usage def net_usage(self): @@ -371,7 +369,6 @@ class wvmInstance(wvmConnect): else: for i, dev in enumerate(self.get_net_device()): dev_usage.append({'dev': i, 'rx': 0, 'tx': 0}) - return dev_usage def get_telnet_port(self):