Skip to content

Commit

Permalink
Ch22: Create Profile Update web page.
Browse files Browse the repository at this point in the history
  • Loading branch information
jambonrose committed Jul 30, 2015
1 parent de5e3e3 commit 8316796
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions user/models.py
@@ -1,4 +1,5 @@
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models


Expand All @@ -12,3 +13,6 @@ class Profile(models.Model):

def __str__(self):
return self.user.get_username()

def get_update_url(self):
return reverse('dj-auth:profile_update')
2 changes: 2 additions & 0 deletions user/templates/user/profile_detail.html
Expand Up @@ -16,6 +16,8 @@ <h2>About {{ profile.user.get_username }}</h2>

<div class="three columns">
<ul class="task-list">
<li><a href="{{ profile.get_update_url }}">
Edit Your Profile</a></li>
<li><a href="{% url 'dj-auth:pw_change' %}">
Change Password</a></li>
<li><a href="{% url 'dj-auth:disable' %}">
Expand Down
21 changes: 21 additions & 0 deletions user/templates/user/profile_form_update.html
@@ -0,0 +1,21 @@
{% extends parent_template|default:"user/base_user.html" %}

{% block title %}
{{ block.super }} - Update Profile
{% endblock %}


{% block content %}
<div class="row">
<div class="offset-by-two eight columns">
<form
action="{{ profile.get_update_url }}"
method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">
Update Profile</button>
</form>
</div>
</div>
{% endblock %}
5 changes: 4 additions & 1 deletion user/urls.py
Expand Up @@ -9,7 +9,7 @@

from .views import (
ActivateAccount, CreateAccount,
DisableAccount, ProfileDetail,
DisableAccount, ProfileDetail, ProfileUpdate,
ResendActivationEmail)

password_urls = [
Expand Down Expand Up @@ -108,4 +108,7 @@
url(r'^profile/$',
ProfileDetail.as_view(),
name='profile'),
url(r'^profile/edit/$',
ProfileUpdate.as_view(),
name='profile_update'),
]
9 changes: 9 additions & 0 deletions user/views.py
Expand Up @@ -23,6 +23,8 @@
sensitive_post_parameters
from django.views.generic import DetailView, View

from core.utils import UpdateView

from .decorators import class_login_required
from .forms import (
ResendActivationEmailForm, UserCreationForm)
Expand Down Expand Up @@ -129,6 +131,13 @@ class ProfileDetail(
model = Profile


@class_login_required
class ProfileUpdate(
ProfileGetObjectMixin, UpdateView):
fields = ('about',)
model = Profile


class ResendActivationEmail(
MailContextViewMixin, View):
form_class = ResendActivationEmailForm
Expand Down

0 comments on commit 8316796

Please sign in to comment.