Commit c79b80db authored by Claude Paroz's avatar Claude Paroz

Change person edit view as class-based view

parent 58ceebfa
from django.conf.urls.defaults import *
from django.contrib.auth.decorators import login_required
from people.views import PeopleListView, PersonDetailView
from people import views
# Regex order is really important here
urlpatterns = patterns('people.views',
url(
regex = r'^detail_change/$',
view = 'person_detail_change',
name='person_detail_change'),
r'^detail_change/$',
login_required(views.PersonEditView.as_view()),
name = 'person_detail_change'),
url(
regex = r'^password_change/$',
view = 'person_password_change',
......@@ -23,15 +24,15 @@ urlpatterns = patterns('people.views',
name='person_team_leave'),
url(
r'^(?P<pk>\d+)/$',
PersonDetailView.as_view(),
views.PersonDetailView.as_view(),
name = 'person_detail_id'),
# Equivalent to the previous, but using username instead of user pk
url(
r'^(?P<slug>[\w@\.\-]+)/$',
PersonDetailView.as_view(),
views.PersonDetailView.as_view(),
name = 'person_detail_username'),
)
urlpatterns += patterns('',
url(r'^$', PeopleListView.as_view(), name='people'),
url(r'^$', views.PeopleListView.as_view(), name='people'),
)
......@@ -33,7 +33,7 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.utils import formats
from django.utils.translation import ugettext_lazy, ugettext as _
from django.views.generic import ListView, DetailView
from django.views.generic import ListView, DetailView, UpdateView
from people.models import Person
from teams.models import Team, Role
......@@ -68,27 +68,25 @@ class PersonDetailView(DetailView):
})
return context
@login_required
def person_detail_change(request):
"""Handle the form to change the details"""
person = get_object_or_404(Person, username=request.user.username)
if request.method == 'POST':
form = DetailForm(request.POST, instance=person)
if form.is_valid():
form.save()
else:
messages.error(request, _("Sorry, the form is not valid."))
else:
form = DetailForm(instance=person)
class PersonEditView(UpdateView):
model = Person
slug_field = 'username'
form_class = DetailForm
template_name = 'people/person_detail_change_form.html'
context = {
'pageSection': "teams",
'person': person,
'on_own_page': person.username == request.user.username,
'form': form,
}
return render_to_response('people/person_detail_change_form.html', context,
context_instance=RequestContext(request))
def get_object(self):
self.kwargs['slug'] = self.request.user.username
return super(PersonEditView, self).get_object()
def get_context_data(self, **kwargs):
context = super(PersonEditView, self).get_context_data(**kwargs)
context['pageSection'] = "teams"
context['on_own_page'] = self.object.username == self.request.user.username,
return context
def form_invalid(self, form):
messages.error(self.request, _("Sorry, the form is not valid."))
return super(PersonEditView, self).form_invalid(form)
@login_required
def person_team_join(request):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment