From 9c671e8ef039ac417dc2246877fc64d3879542bb Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 18 Feb 2009 22:35:18 +0100 Subject: [PATCH] [svn r8247] Enable profile setup forms. Profiles are Person model instances, and are linked to django's built in User model by a one to one foreign key. We are using the django-registration and django-profiles pluggables. --- troggle/expo/models.py | 38 +++++++++---------- troggle/profiles/urls.py | 3 ++ troggle/profiles/views.py | 29 ++++++++++++-- .../templates/profiles/create_profile.html | 2 +- troggle/templates/profiles/edit_profile.html | 13 +++++++ .../templates/profiles/profile_detail.html | 10 +++++ .../templates/profiles/select_profile.html | 13 +++++++ .../registration/registration_complete.html | 2 +- 8 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 troggle/templates/profiles/edit_profile.html create mode 100644 troggle/templates/profiles/profile_detail.html create mode 100644 troggle/templates/profiles/select_profile.html diff --git a/troggle/expo/models.py b/troggle/expo/models.py index faa4ce3f9..c55bfe8a0 100644 --- a/troggle/expo/models.py +++ b/troggle/expo/models.py @@ -66,13 +66,13 @@ class Person(models.Model): mug_shot = models.CharField(max_length=100, blank=True,null=True) blurb = models.TextField(blank=True,null=True) - href = models.CharField(max_length=200) + #href = models.CharField(max_length=200) orderref = models.CharField(max_length=200) # for alphabetic #the below have been removed and made methods. I'm not sure what the b in bisnotable stands for. - AC 16 Feb #notability = models.FloatField() # for listing the top 20 people #bisnotable = models.BooleanField() - user = models.ForeignKey(User, unique=True, null=True, blank=True) + user = models.OneToOneField(User, null=True, blank=True) def get_absolute_url(self): return settings.URL_ROOT + "/person/%s_%s/" % (self.first_name, self.last_name) @@ -93,24 +93,24 @@ class Person(models.Model): # def Lastexpedition(self): # return self.personexpedition_set.order_by('-expedition')[0] - def notability(self): - notability = 0.0 - for personexpedition in person.personexpedition_set.all(): - if not personexpedition.is_guest: - notability += 1.0 / (2012 - int(self.personexpedition.expedition.year)) - return notability + #def notability(self): + #notability = 0.0 + #for personexpedition in person.personexpedition_set.all(): + #if not personexpedition.is_guest: + #notability += 1.0 / (2012 - int(self.personexpedition.expedition.year)) + #return notability - def bisnotable(self): - return self.notability > 0.3 + #def bisnotable(self): + #return self.notability > 0.3 - def Sethref(self): - if self.last_name: - self.href = self.first_name.lower() + "_" + self.last_name.lower() - self.orderref = self.last_name + " " + self.first_name - else: - self.href = self.first_name.lower() - self.orderref = self.first_name - self.notability = 0.0 # set temporarily + #def Sethref(self): + #if self.last_name: + #self.href = self.first_name.lower() + "_" + self.last_name.lower() + #self.orderref = self.last_name + " " + self.first_name + #else: + # self.href = self.first_name.lower() + #self.orderref = self.first_name + #self.notability = 0.0 # set temporarily class PersonExpedition(models.Model): @@ -291,7 +291,7 @@ class Cave(models.Model): extent = models.CharField(max_length=100,blank=True,null=True) survex_file = models.CharField(max_length=100,blank=True,null=True) #should be filefield, need to fix parser first - href = models.CharField(max_length=100) + #href = models.CharField(max_length=100) def get_absolute_url(self): if self.kataster_number: diff --git a/troggle/profiles/urls.py b/troggle/profiles/urls.py index 05ff9e434..a703e9b89 100644 --- a/troggle/profiles/urls.py +++ b/troggle/profiles/urls.py @@ -28,6 +28,9 @@ from profiles import views urlpatterns = patterns('', + url(r'^select/$', + views.select_profile, + name='profiles_select_profile'), url(r'^create/$', views.create_profile, name='profiles_create_profile'), diff --git a/troggle/profiles/views.py b/troggle/profiles/views.py index c1191655b..b3e3672fe 100644 --- a/troggle/profiles/views.py +++ b/troggle/profiles/views.py @@ -2,7 +2,6 @@ Views for creating, editing and viewing site-specific user profiles. """ - from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist @@ -13,11 +12,35 @@ from django.shortcuts import get_object_or_404 from django.shortcuts import render_to_response from django.template import RequestContext from django.views.generic.list_detail import object_list +from django import forms + +from expo.models import Person + +from troggle.alwaysUseRequestContext import render_response from profiles import utils -import troggle.settings as settings +from django.conf import settings +class SelectPersonForm(forms.Form): #This and the select_profile view + person = forms.ModelChoiceField(queryset=Person.objects.all()) + +def select_profile(request): + + if request.method == 'POST': + form = SelectPersonForm(request.POST) + if form.is_valid(): + profile_obj=form.cleaned_data['person'] + profile_obj.user=request.user + profile_obj.save() + return HttpResponseRedirect(profile_obj.get_absolute_url()) + else: + form = SelectPersonForm() + context = RequestContext(request) + return render_to_response('profiles/select_profile.html', { + 'form':form,}, + context_instance=context + ) def create_profile(request, form_class=None, success_url=None, @@ -81,7 +104,7 @@ def create_profile(request, form_class=None, success_url=None, """ try: profile_obj = request.user.get_profile() - return HttpResponseRedirect(reverse('profiles_edit_profile')) + return HttpResponseRedirect(profile_obj.get_absolute_url()) except ObjectDoesNotExist: pass diff --git a/troggle/templates/profiles/create_profile.html b/troggle/templates/profiles/create_profile.html index 2eed3e480..7e3259799 100644 --- a/troggle/templates/profiles/create_profile.html +++ b/troggle/templates/profiles/create_profile.html @@ -3,7 +3,7 @@ {% block content %}
-{{ form }} +{{ form.as_p }}
diff --git a/troggle/templates/profiles/edit_profile.html b/troggle/templates/profiles/edit_profile.html new file mode 100644 index 000000000..7e3259799 --- /dev/null +++ b/troggle/templates/profiles/edit_profile.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} + +{% block content %} + +
+{{ form.as_p }} + +
+ +{% if form.errors %} +

Please correct the errors below

+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/troggle/templates/profiles/profile_detail.html b/troggle/templates/profiles/profile_detail.html new file mode 100644 index 000000000..543785fb4 --- /dev/null +++ b/troggle/templates/profiles/profile_detail.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} + +{{ profile }} + +{% if form.errors %} +

Please correct the errors below

+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/troggle/templates/profiles/select_profile.html b/troggle/templates/profiles/select_profile.html new file mode 100644 index 000000000..7e3259799 --- /dev/null +++ b/troggle/templates/profiles/select_profile.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} + +{% block content %} + +
+{{ form.as_p }} + +
+ +{% if form.errors %} +

Please correct the errors below

+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/troggle/templates/registration/registration_complete.html b/troggle/templates/registration/registration_complete.html index 552fa04e6..7cc8ab2ac 100644 --- a/troggle/templates/registration/registration_complete.html +++ b/troggle/templates/registration/registration_complete.html @@ -9,5 +9,5 @@ registration_complete.html | {{ block.super }} {% endblock %} {% block content %} -Thank you for signing up. An email with the activation code has been sent to your inbox. +Thank you for signing up, {{ user.username }}. An email with the activation code has been sent to your inbox. Please create your profile. If you have been on the expedition in the past, this step allows existing expedition data to be linked to your new account. {% endblock %} \ No newline at end of file