Skip to content

Commit

Permalink
Ch22: Create Profile Detail web page.
Browse files Browse the repository at this point in the history
  • Loading branch information
jambonrose committed Jul 30, 2015
1 parent 6b8d9ef commit de5e3e3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions templates/base.html
Expand Up @@ -30,6 +30,8 @@
<div class="offset-by-eight four columns">
<ul class="inline">
{% if user.is_authenticated %}
<li><a href="{% url 'dj-auth:profile' %}">
View Profile</a></li>
<li><a href="{% url 'dj-auth:logout' %}?next={{ request.path }}">
Log Out</a></li>
{% else %}
Expand Down
27 changes: 27 additions & 0 deletions user/templates/user/profile_detail.html
@@ -0,0 +1,27 @@
{% extends parent_template|default:"user/base_user.html" %}

{% block title %}
{{ block.super }} -
{{ profile.user.get_username }}'s Profile
{% endblock %}

{% block content %}
<div class="row">
<div class="offset-by-two five columns">

<h2>About {{ profile.user.get_username }}</h2>
{{ profile.about|default:"No Profile"|linebreaks }}

</div><!-- columns -->

<div class="three columns">
<ul class="task-list">
<li><a href="{% url 'dj-auth:pw_change' %}">
Change Password</a></li>
<li><a href="{% url 'dj-auth:disable' %}">
Disable Account</a></li>
</ul>
</div>

</div><!-- row -->
{% endblock %}
6 changes: 5 additions & 1 deletion user/urls.py
Expand Up @@ -9,7 +9,8 @@

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

password_urls = [
url(r'^$',
Expand Down Expand Up @@ -104,4 +105,7 @@
{'form': AuthenticationForm}},
name='logout'),
url(r'^password/', include(password_urls)),
url(r'^profile/$',
ProfileDetail.as_view(),
name='profile'),
]
8 changes: 8 additions & 0 deletions user/utils.py
Expand Up @@ -4,6 +4,7 @@
from smtplib import SMTPException

from django.conf import settings
from django.contrib.auth import get_user
from django.contrib.auth.tokens import \
default_token_generator as token_generator
from django.contrib.sites.shortcuts import \
Expand Down Expand Up @@ -164,3 +165,10 @@ def get_save_kwargs(self, request):
'subject_template_name':
self.subject_template_name,
}


class ProfileGetObjectMixin:

def get_object(self, queryset=None):
current_user = get_user(self.request)
return current_user.profile
13 changes: 11 additions & 2 deletions user/views.py
Expand Up @@ -21,11 +21,14 @@
csrf_protect
from django.views.decorators.debug import \
sensitive_post_parameters
from django.views.generic import View
from django.views.generic import DetailView, View

from .decorators import class_login_required
from .forms import (
ResendActivationEmailForm, UserCreationForm)
from .utils import MailContextViewMixin
from .models import Profile
from .utils import (
MailContextViewMixin, ProfileGetObjectMixin)


class ActivateAccount(View):
Expand Down Expand Up @@ -120,6 +123,12 @@ def post(self, request):
return redirect(self.success_url)


@class_login_required
class ProfileDetail(
ProfileGetObjectMixin, DetailView):
model = Profile


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

0 comments on commit de5e3e3

Please sign in to comment.