[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.
This commit is contained in:
aaron 2009-02-18 22:35:18 +01:00
parent 4fc8c8ae3c
commit 9c671e8ef0
8 changed files with 86 additions and 24 deletions

View File

@ -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:

View File

@ -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'),

View File

@ -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

View File

@ -3,7 +3,7 @@
{% block content %}
<form method="post">
{{ form }}
{{ form.as_p }}
<input type="submit" />
</form>

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block content %}
<form method="post">
{{ form.as_p }}
<input type="submit" />
</form>
{% if form.errors %}
<p class="errornote">Please correct the errors below</p>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
{{ profile }}
{% if form.errors %}
<p class="errornote">Please correct the errors below</p>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block content %}
<form method="post">
{{ form.as_p }}
<input type="submit" />
</form>
{% if form.errors %}
<p class="errornote">Please correct the errors below</p>
{% endif %}
{% endblock %}

View File

@ -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 <a href={% url profiles_create_profile %}> create your profile</a>. If you have been on the expedition in the past, this step allows existing expedition data to be linked to your new account.
{% endblock %}