From e5fa55ea6c899b30b27e04960b4f5af08b2867fa Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 25 Mar 2015 18:56:29 +0000 Subject: [PATCH 1/4] Added viewing user profiles --- RIGS/templates/RIGS/profile_detail.html | 37 +++++++++++++++++++++++++ RIGS/urls.py | 7 +++++ RIGS/views.py | 14 +++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 RIGS/templates/RIGS/profile_detail.html diff --git a/RIGS/templates/RIGS/profile_detail.html b/RIGS/templates/RIGS/profile_detail.html new file mode 100644 index 00000000..f21251b3 --- /dev/null +++ b/RIGS/templates/RIGS/profile_detail.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %} + +{% block title %}RIGS Profile {{object.pk}}{% endblock %} + +{% block content %} +
+
+

{{object.name}}

+
+
First Name
+
{{object.first_name}}
+ +
Last Name
+
{{object.last_name}}
+ +
Email
+
{{object.email}}
+ +
Last Login
+
{{object.last_login}}
+ +
Date Joined
+
{{object.date_joined}}
+ +
Initials
+
{{object.initials}}
+ +
Phone
+
{{object.phone}}
+
+
+
+
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/RIGS/urls.py b/RIGS/urls.py index d50b78cb..dd095bbe 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -106,6 +106,13 @@ urlpatterns = patterns('', permission_required_with_403('RIGS.add_payment')(finance.PaymentDelete.as_view()), name='payment_delete'), + # User editing + url(r'^user/$', login_required(views.ProfileDetail.as_view()), name='profile_detail'), + url(r'^user/(?P\d+)/$', + permission_required_with_403('RIGS.view_profile')(views.ProfileDetail.as_view()), + name='profile_detail'), + # url(r'^user/edit/') + # API url(r'^api/(?P\w+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"), url(r'^api/(?P\w+)/(?P\d+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"), diff --git a/RIGS/views.py b/RIGS/views.py index 6d82cb5c..dfb68d69 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -249,4 +249,16 @@ class SecureAPIRequest(generic.View): json = simplejson.dumps(results[:20]) return HttpResponse(json, content_type="application/json") # Always json - return HttpResponse(model) \ No newline at end of file + return HttpResponse(model) + +class ProfileDetail(generic.DetailView): + model = models.Profile + + def get_queryset(self): + try: + pk = self.kwargs['pk'] + except KeyError: + pk = self.request.user.id + self.kwargs['pk'] = pk + + return self.model.objects.filter(pk=pk) \ No newline at end of file From 048c4b801aee1889b976d29d24a054e19389fd03 Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 25 Mar 2015 20:21:54 +0000 Subject: [PATCH 2/4] Add user editing --- PyRIGS/settings.py | 4 +++- RIGS/templates/RIGS/profile_detail.html | 15 +++++++++++++-- RIGS/urls.py | 3 ++- RIGS/views.py | 18 ++++++++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 795db80d..8c6d78b6 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -23,7 +23,7 @@ DEBUG = True TEMPLATE_DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] INTERNAL_IPS = ['127.0.0.1', '10.20.30.20'] @@ -143,4 +143,6 @@ TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), ) +USE_GRAVATAR=True + TERMS_OF_HIRE_URL = "http://dev.nottinghamtec.co.uk/wp-content/uploads/2014/11/terms.pdf" diff --git a/RIGS/templates/RIGS/profile_detail.html b/RIGS/templates/RIGS/profile_detail.html index f21251b3..a9d9bbaf 100644 --- a/RIGS/templates/RIGS/profile_detail.html +++ b/RIGS/templates/RIGS/profile_detail.html @@ -4,8 +4,19 @@ {% block content %}
-
+

{{object.name}}

+
+ {% if object.pk == user.pk %} +
+ +
+ {% endif %} +
First Name
{{object.first_name}}
@@ -29,7 +40,7 @@
{{object.phone}}
-
+
diff --git a/RIGS/urls.py b/RIGS/urls.py index dd095bbe..27c932f9 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -111,7 +111,8 @@ urlpatterns = patterns('', url(r'^user/(?P\d+)/$', permission_required_with_403('RIGS.view_profile')(views.ProfileDetail.as_view()), name='profile_detail'), - # url(r'^user/edit/') + url(r'^user/edit/$', login_required(views.ProfileUpdateSelf.as_view()), + name='profile_update_self'), # API url(r'^api/(?P\w+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"), diff --git a/RIGS/views.py b/RIGS/views.py index dfb68d69..151a4117 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -9,7 +9,7 @@ from django.core import serializers import simplejson from django.contrib import messages -from RIGS import models +from RIGS import models, forms """ Displays the current rig count along with a few other bits and pieces @@ -261,4 +261,18 @@ class ProfileDetail(generic.DetailView): pk = self.request.user.id self.kwargs['pk'] = pk - return self.model.objects.filter(pk=pk) \ No newline at end of file + return self.model.objects.filter(pk=pk) + +class ProfileUpdateSelf(generic.UpdateView): + model = models.Profile + fields = ['first_name', 'last_name', 'email', 'initials', 'phone'] + + def get_queryset(self): + pk = self.request.user.id + self.kwargs['pk'] = pk + + return self.model.objects.filter(pk=pk) + + def get_success_url(self): + url = reverse_lazy('profile_detail') + return url \ No newline at end of file From cc27822b34fd2b9fb792122a6ddd3c19325f5dbe Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 25 Mar 2015 20:44:58 +0000 Subject: [PATCH 3/4] Add links to user details to base. Improve issues with logout not looking correct. --- templates/base.html | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/templates/base.html b/templates/base.html index 00b8c183..496d372b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -76,18 +76,22 @@ {% else %} From f1e75d1656ba4622d4ea6106764f17bc33b4c77a Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 25 Mar 2015 21:10:45 +0000 Subject: [PATCH 4/4] Add missing profile_form.html template --- RIGS/templates/RIGS/profile_form.html | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 RIGS/templates/RIGS/profile_form.html diff --git a/RIGS/templates/RIGS/profile_form.html b/RIGS/templates/RIGS/profile_form.html new file mode 100644 index 00000000..baa33424 --- /dev/null +++ b/RIGS/templates/RIGS/profile_form.html @@ -0,0 +1,71 @@ +{% extends 'base.html' %} +{% load widget_tweaks %} + +{% block title %}Update Profile {{object.name}}{% endblock %} + +{% block content %} +
+
+ {% include 'form_errors.html' %} +

Update Profile

+
+
{% csrf_token %} +
+ + +
+ {% render_field form.first_name class+="form-control" placeholder=form.first_name.label %} +
+
+ +
+ + +
+ {% render_field form.last_name class+="form-control" placeholder=form.last_name.label %} +
+
+ +
+ + +
+ {% render_field form.email type="email" class+="form-control" placeholder=form.email.label %} +
+
+ +
+ + +
+ {% render_field form.initials class+="form-control" placeholder=form.initials.label %} +
+
+ +
+ + +
+ {% render_field form.phone type="tel" class+="form-control" placeholder=form.phone.label %} +
+
+ +
+ +
+
+
+ + +
+
+{% endblock %} \ No newline at end of file