Commit 0fbdc363 by Kálmán Viktor

dashboard: access user profiles by username

parent 89dc52ae
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</ul> </ul>
{% if user.is_authenticated and user.pk %} {% if user.is_authenticated and user.pk %}
<a class="navbar-brand pull-right" href="{% url "logout" %}?next={% url "login" %}" style="color: white; font-size: 10px;"><i class="icon-signout icon-sign-out"></i> {% trans "Log out" %}</a> <a class="navbar-brand pull-right" href="{% url "logout" %}?next={% url "login" %}" style="color: white; font-size: 10px;"><i class="icon-signout icon-sign-out"></i> {% trans "Log out" %}</a>
<a class="navbar-brand pull-right" href="{% url "dashboard.views.profile" pk=user.pk %}" title="{% trans "User profile" %}" style="color: white; font-size: 10px;"><i class="icon-user "></i> {{user}}</a> <a class="navbar-brand pull-right" href="{% url "dashboard.views.profile" username=user.username %}" title="{% trans "User profile" %}" style="color: white; font-size: 10px;"><i class="icon-user "></i> {{user}}</a>
{% if user.is_superuser %} {% if user.is_superuser %}
<a class="navbar-brand pull-right" href="/network/" style="color: white; font-size: 10px;"><i class="icon-globe"></i> {% trans "Network" %}</a> <a class="navbar-brand pull-right" href="/network/" style="color: white; font-size: 10px;"><i class="icon-globe"></i> {% trans "Network" %}</a>
<a class="navbar-brand pull-right" href="/admin/" style="color: white; font-size: 10px;"><i class="icon-cogs"></i> {% trans "Admin" %}</a> <a class="navbar-brand pull-right" href="/admin/" style="color: white; font-size: 10px;"><i class="icon-cogs"></i> {% trans "Admin" %}</a>
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<i class="icon-user"></i> <i class="icon-user"></i>
</td> </td>
<td> <td>
<a href="{% url "dashboard.views.profile" pk=i.pk %}" title="{{ i.username }}" <a href="{% url "dashboard.views.profile" username=i.username %}" title="{{ i.username }}"
>{% include "dashboard/_display-name.html" with user=i show_org=True %}</a> >{% include "dashboard/_display-name.html" with user=i show_org=True %}</a>
</td> </td>
<td> <td>
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
<i class="icon-user"></i> <i class="icon-user"></i>
</td> </td>
<td> <td>
<a href="{% url "dashboard.views.profile" pk=i.user.pk %}" title="{{ i.user.username }}" <a href="{% url "dashboard.views.profile" username=i.user.username %}" title="{{ i.user.username }}"
>{% include "dashboard/_display-name.html" with user=i.user show_org=True %}</a> >{% include "dashboard/_display-name.html" with user=i.user show_org=True %}</a>
</td> </td>
<td> <td>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
{% if request.user == profile %} {% if request.user == profile %}
<p> <p>
{% trans "Use email address as Gravatar profile image" %}: {% trans "Use email address as Gravatar profile image" %}:
<input id="dashboard-profile-use-gravatar" data-user="{{ profile.pk }}" <input id="dashboard-profile-use-gravatar" data-user="{{ profile.username }}"
{% if profile.profile.use_gravatar %}checked="checked"{% endif %} {% if profile.profile.use_gravatar %}checked="checked"{% endif %}
type="checkbox"/> <a href="https://gravatar.com">{% trans "What's Gravatar?" %}</a> type="checkbox"/> <a href="https://gravatar.com">{% trans "What's Gravatar?" %}</a>
</p> </p>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
{{ a.get_readable_name }}{% if user.is_superuser %}</a>{% endif %} {{ a.get_readable_name }}{% if user.is_superuser %}</a>{% endif %}
</strong> </strong>
{{ a.started|date:"Y-m-d H:i" }}{% if a.user %}, {{ a.started|date:"Y-m-d H:i" }}{% if a.user %},
<a class="no-style-link" href="{% url "dashboard.views.profile" pk=a.user.pk %}"> <a class="no-style-link" href="{% url "dashboard.views.profile" username=a.user.username %}">
{% include "dashboard/_display-name.html" with user=a.user show_org=True %} {% include "dashboard/_display-name.html" with user=a.user show_org=True %}
</a> </a>
{% endif %} {% endif %}
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<tr> <tr>
<td><i class="icon-user"></i></td> <td><i class="icon-user"></i></td>
<td> <td>
<a href="{% url "dashboard.views.profile" pk=i.user.pk %}" title="{{ i.user.username }}" <a href="{% url "dashboard.views.profile" username=i.user.username %}" title="{{ i.user.username }}"
>{% include "dashboard/_display-name.html" with user=i.user show_org=True %}</a> >{% include "dashboard/_display-name.html" with user=i.user show_org=True %}</a>
</td> </td>
<td> <td>
......
...@@ -135,9 +135,9 @@ urlpatterns = patterns( ...@@ -135,9 +135,9 @@ urlpatterns = patterns(
url(r'^profile/$', MyPreferencesView.as_view(), url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile-preferences"), name="dashboard.views.profile-preferences"),
url(r'^profile/(?P<pk>\d+)/$', ProfileView.as_view(), url(r'^profile/(?P<username>\w+)/$', ProfileView.as_view(),
name="dashboard.views.profile"), name="dashboard.views.profile"),
url(r'^profile/(?P<pk>\d+)/use_gravatar/$', toggle_use_gravatar), url(r'^profile/(?P<username>\w+)/use_gravatar/$', toggle_use_gravatar),
url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<member_pk>\d+)/$', url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<member_pk>\d+)/$',
GroupRemoveAclUserView.as_view(), GroupRemoveAclUserView.as_view(),
......
...@@ -2656,6 +2656,8 @@ class InterfaceDeleteView(DeleteView): ...@@ -2656,6 +2656,8 @@ class InterfaceDeleteView(DeleteView):
class ProfileView(LoginRequiredMixin, DetailView): class ProfileView(LoginRequiredMixin, DetailView):
template_name = "dashboard/profile.html" template_name = "dashboard/profile.html"
model = User model = User
slug_field = "username"
slug_url_kwarg = "username"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ProfileView, self).get_context_data(**kwargs) context = super(ProfileView, self).get_context_data(**kwargs)
...@@ -2697,7 +2699,7 @@ class ProfileView(LoginRequiredMixin, DetailView): ...@@ -2697,7 +2699,7 @@ class ProfileView(LoginRequiredMixin, DetailView):
@require_POST @require_POST
def toggle_use_gravatar(request, **kwargs): def toggle_use_gravatar(request, **kwargs):
user = get_object_or_404(User, pk=kwargs['pk']) user = get_object_or_404(User, username=kwargs['username'])
if not request.user == user: if not request.user == user:
raise PermissionDenied() raise PermissionDenied()
......
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 sign in to comment