Skip to content

Commit

Permalink
Ch22: Create Public 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 8316796 commit a1d420b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions user/models.py
Expand Up @@ -14,5 +14,10 @@ class Profile(models.Model):
def __str__(self):
return self.user.get_username()

def get_absolute_url(self):
return reverse(
'dj-auth:public_profile',
kwargs={'slug': self.slug})

def get_update_url(self):
return reverse('dj-auth:profile_update')
6 changes: 6 additions & 0 deletions user/templates/user/profile_detail.html
Expand Up @@ -7,13 +7,18 @@

{% block content %}
<div class="row">
{% if user.pk == profile.user.pk %}
<div class="offset-by-two five columns">
{% else %}
<div class="offset-by-two eight columns">
{% endif%}

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

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

{% if user.pk == profile.user.pk %}
<div class="three columns">
<ul class="task-list">
<li><a href="{{ profile.get_update_url }}">
Expand All @@ -24,6 +29,7 @@ <h2>About {{ profile.user.get_username }}</h2>
Disable Account</a></li>
</ul>
</div>
{% endif%}

</div><!-- row -->
{% endblock %}
5 changes: 4 additions & 1 deletion user/urls.py
Expand Up @@ -10,7 +10,7 @@
from .views import (
ActivateAccount, CreateAccount,
DisableAccount, ProfileDetail, ProfileUpdate,
ResendActivationEmail)
PublicProfileDetail, ResendActivationEmail)

password_urls = [
url(r'^$',
Expand Down Expand Up @@ -111,4 +111,7 @@
url(r'^profile/edit/$',
ProfileUpdate.as_view(),
name='profile_update'),
url(r'^(?P<slug>[\w\-]+)/$',
PublicProfileDetail.as_view(),
name='public_profile'),
]
4 changes: 4 additions & 0 deletions user/views.py
Expand Up @@ -131,6 +131,10 @@ class ProfileDetail(
model = Profile


class PublicProfileDetail(DetailView):
model = Profile


@class_login_required
class ProfileUpdate(
ProfileGetObjectMixin, UpdateView):
Expand Down

0 comments on commit a1d420b

Please sign in to comment.