Add UserView and GroupView part 2

This commit is contained in:
Norman Jäckel 2012-10-30 00:07:25 +01:00
parent b213e75223
commit c13f4ba52d
10 changed files with 117 additions and 15 deletions

View File

@ -78,14 +78,17 @@ class User(DjangoUser, PersonMixin, Person):
self.save() self.save()
@models.permalink @models.permalink
def get_absolute_url(self, link='edit'): def get_absolute_url(self, link='view'):
""" """
Return the URL to this user. Return the URL to this user.
link can be: link can be:
* view
* edit * edit
* delete * delete
""" """
if link == 'view':
return ('user_view', [str(self.id)])
if link == 'edit': if link == 'edit':
return ('user_edit', [str(self.id)]) return ('user_edit', [str(self.id)])
if link == 'delete': if link == 'delete':
@ -114,14 +117,17 @@ class Group(DjangoGroup, PersonMixin, Person):
description = models.TextField(blank=True) description = models.TextField(blank=True)
@models.permalink @models.permalink
def get_absolute_url(self, link='edit'): def get_absolute_url(self, link='view'):
""" """
Return the URL to this user. Return the URL to this user.
link can be: link can be:
* view
* edit * edit
* delete * delete
""" """
if link == 'view':
return ('user_group_view', [str(self.id)])
if link == 'edit': if link == 'edit':
return ('user_group_edit', [str(self.id)]) return ('user_group_edit', [str(self.id)])
if link == 'delete': if link == 'delete':

View File

@ -27,4 +27,51 @@
<li><a href="{% url print_passwords %}"><img src="{% static 'images/icons/pdf.png' %}"> {% trans 'First time passwords as PDF' %}</a></li> <li><a href="{% url print_passwords %}"><img src="{% static 'images/icons/pdf.png' %}"> {% trans 'First time passwords as PDF' %}</a></li>
{% endif %} {% endif %}
</ul> </ul>
{# second submenu #}
{% if shown_user %}
<br>
<h3>{{ shown_user.clean_name }}</h3>
<ul>
{# view shown_user #}
<li class="{% if request.path == 'foo' %}selected{% endif %}">
<a href="{% model_url shown_user 'view' %}">{% trans 'View participant' %}</a>
</li>
{% if perms.participant.can_manage_participant %}
{# edit shown_user #}
<li class="{% if request.path == 'foo' %}selected{% endif %}">
<a href="{% model_url shown_user 'edit' %}"><img src="{% static 'images/icons/edit.png' %}"> {% trans 'Edit participant' %}</a>
</li>
{# delete shown_user #}
<li>
<a href="{% model_url shown_user 'delete' %}"><img src="{% static 'images/icons/delete.png' %}"> {% trans 'Delete participant' %}</a>
</li>
{% endif %}
</ul>
{% elif group %}
<br>
<h3>{{ group.name }}</h3>
<ul>
{# view group #}
<li class="{% if request.path == 'foo' %}selected{% endif %}">
<a href="{% model_url group 'view' %}">{% trans 'View group' %}</a>
</li>
{# edit group #}
<li class="{% if request.path == 'foo' %}selected{% endif %}">
<a href="{% model_url group 'edit' %}"><img src="{% static 'images/icons/edit.png' %}"> {% trans 'Edit group' %}</a>
</li>
{# delete group #}
{% if group.name != 'Anonymous' %}
<li>
<a href="{% model_url group 'delete' %}"><img src="{% static 'images/icons/delete.png' %}"> {% trans 'Delete group' %}</a>
</li>
{% endif %}
</ul>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -1,9 +1,20 @@
{% extends "participant/base_participant.html" %} {% extends "participant/base_participant.html" %}
{% block title %}{{ block.super }} {{ object }}{% endblock %} {% load i18n %}
{% load tags %}
{% block title %}{{ block.super }} {{ group }}{% endblock %}
{% block content %} {% block content %}
{{ object }} <h1>{{ group }}</h1>
<p>{{ group.description }}</p>
<h2>{% trans "Members" %}</h2>
{% for member in group.user_set.all %}
<p>{{ member }}</p>
{% endfor %}
{% endblock %} {% endblock %}

View File

@ -2,6 +2,7 @@
{% load i18n %} {% load i18n %}
{% load staticfiles %} {% load staticfiles %}
{% load tags %}
{% block title %}{{ block.super }} {% trans "User groups" %}{% endblock %} {% block title %}{{ block.super }} {% trans "User groups" %}{% endblock %}
@ -14,7 +15,7 @@
</tr> </tr>
{% for group in groups %} {% for group in groups %}
<tr class="{% cycle '' 'odd' %}"> <tr class="{% cycle '' 'odd' %}">
<td>{{ group.name }}</td> <td><a href="{% model_url group 'view' %}">{{ group.name }}</a></td>
<td><a href="{% url user_group_edit group.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit group' %}"></a> <td><a href="{% url user_group_edit group.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit group' %}"></a>
{% if group.name != 'Anonymous' %} {% if group.name != 'Anonymous' %}
<a href="{% url user_group_delete group.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete group' %}"></a> <a href="{% url user_group_delete group.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete group' %}"></a>

View File

@ -17,7 +17,7 @@
<a href="{% url projctor_preview_slide group.sid %}" title="{% trans 'Preview' %}" class="icon preview right"> <a href="{% url projctor_preview_slide group.sid %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span> <span></span>
</a> </a>
<a href="{% model_url group 'edit' %}">{{ group }}</a> <a href="{% model_url group 'view' %}">{{ group }}</a>
</li> </li>
{% endif %} {% endif %}
{% empty %} {% empty %}

View File

@ -76,7 +76,7 @@
</tr> </tr>
{% for user in users %} {% for user in users %}
<tr class="{% cycle '' 'odd' %}"> <tr class="{% cycle '' 'odd' %}">
<td>{{ user.first_name }}</td> <td><a href="{% model_url user 'view' %}">{{ user.first_name }}</a></td>
<td>{{ user.last_name }}</td> <td>{{ user.last_name }}</td>
<td>{{ user.detail }}</td> <td>{{ user.detail }}</td>
<td>{{ user.get_type_display }}</td> <td>{{ user.get_type_display }}</td>

View File

@ -1,9 +1,40 @@
{% extends "participant/base_participant.html" %} {% extends "participant/base_participant.html" %}
{% block title %}{{ block.super }} {{ object }}{% endblock %} {% load i18n %}
{% load tags %}
{% block title %}{{ block.super }} {{ shown_user }}{% endblock %}
{% block content %} {% block content %}
{{ object }} <h1>{{ shown_user }}</h1>
<p>{{ shown_user.email }}</p>
<h2>{% trans "Groups" %}</h2>
<p>
{% for group in shown_user.groups.all %}
{{ group }},
{% endfor %}
</p>
<h2>{% trans "Gender" %}</h2>
<p>{{ shown_user.get_gender_display }}</p>
<h2>{% trans "Type" %}</h2>
<p>{{ shown_user.get_type_display }}</p>
<h2>{% trans "Committee" %}</h2>
<p>{{ shown_user.committee }}</p>
{% if perms.participant.can_manage_participant %}
<h2>{% trans "Comment" %}</h2>
<p>{{ shown_user.comment }}</p>
<h2>{% trans "Last Login" %}</h2>
{% if shown_user.last_login > shown_user.date_joined %}
<p>{{ shown_user.last_login }}</p>
{% endif %}
{% endif %}
{% endblock %} {% endblock %}

View File

@ -16,7 +16,7 @@
<a href="{% url projctor_preview_slide user.sid %}" title="{% trans 'Preview' %}" class="icon preview right"> <a href="{% url projctor_preview_slide user.sid %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span> <span></span>
</a> </a>
<a href="{% model_url user 'edit' %}">{{ user }}</a> <a href="{% model_url user 'view' %}">{{ user }}</a>
</li> </li>
{% empty %} {% empty %}
<li>{% trans 'No users available.' %}</li> <li>{% trans 'No users available.' %}</li>

View File

@ -34,7 +34,7 @@ urlpatterns = patterns('',
url(r'^(?P<pk>\d+)/$', url(r'^(?P<pk>\d+)/$',
UserDetailView.as_view(), UserDetailView.as_view(),
name='user_detail', name='user_view',
), ),
url(r'^(?P<pk>\d+)/edit/$', url(r'^(?P<pk>\d+)/edit/$',
@ -88,7 +88,7 @@ urlpatterns = patterns('',
url(r'^group/(?P<pk>\d+)/$', url(r'^group/(?P<pk>\d+)/$',
GroupDetailView.as_view(), GroupDetailView.as_view(),
name='user_group_detail', name='user_group_view',
), ),
url(r'^group/(?P<pk>\d+)/edit/$', url(r'^group/(?P<pk>\d+)/edit/$',

View File

@ -140,19 +140,25 @@ class UserOverview(ListView):
return context return context
from django.views.generic.detail import DetailView from openslides.utils.views import DetailView, PermissionMixin
class UserDetailView(DetailView): class UserDetailView(DetailView, PermissionMixin):
""" """
Classed based view to show a specific user in the interface. Classed based view to show a specific user in the interface.
""" """
permission_required = 'participant.can_see_participant'
model = User model = User
template_name = 'participant/user_detail.html'
context_object_name = 'shown_user'
class GroupDetailView(DetailView): class GroupDetailView(DetailView, PermissionMixin):
""" """
Classed based view to show a specific group in the interface. Classed based view to show a specific group in the interface.
""" """
permission_required = 'participant.can_manage_participant'
model = Group model = Group
template_name = 'participant/group_detail.html'
context_object_name = 'group'
class UserCreateView(CreateView): class UserCreateView(CreateView):