add child groups to view

This commit is contained in:
Andreas Zweili 2022-04-04 09:57:46 +02:00
parent aa0b7f8fc0
commit 8d703a9175
3 changed files with 34 additions and 1 deletions

View File

@ -17,6 +17,21 @@
</tr>
{% endfor %}
</table>
{% if groups %}
<table class="table table-bordered">
<tr>
<th>Group Name</th>
<th>Address</th>
</tr>
{% for group in groups %}
<tr>
<td>{{ group.name }}</td>
<td><a href="mailto:{{ group.mail_address }}">{{ group.mail_address }}</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>
</div>

View File

@ -50,3 +50,17 @@ def test_group_detail_view_with_user(create_admin_user):
user.groups.add(group)
response = client.get("/group/" + str(group.id) + "/")
assert response.status_code == 200 and helper.in_content(response, user)
def test_group_detail_view_with_child_group(create_admin_user):
create_admin_user()
group = mixer.blend("users.Group", customer=mixer.SELECT)
child_group = mixer.blend(
"users.Group", customer=mixer.SELECT, parent_group=mixer.SELECT
)
client = Client()
client.login(username="pharma-admin", password="password")
response = client.get("/group/" + str(group.id) + "/")
assert response.status_code == 200 and helper.in_content(
response, child_group
)

View File

@ -86,8 +86,12 @@ def group_detail_view(request, pk):
Group, user=request.user, pk=pk
)
users = group.user_set.all()
groups = Group.objects.filter(parent_group=group)
print(groups)
return render(
request, "groups/group_details.html", {"group": group, "users": users}
request,
"groups/group_details.html",
{"group": group, "users": users, "groups": groups},
)