Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Authentication Users and Authorization Checkpoints

Chris Komaroff
PLUS
Chris Komaroff
Courses Plus Student 14,198 Points

Any chance of supplying the "snippet" code for template community_detail.html?

This is the template code that requires the user viewing community_detail.html to have the ban_member permission to ban a member from the community. I will try to copy from video screenshots. I don't see the source code in S2V5 projects files.

4 Answers

Chris Komaroff
PLUS
Chris Komaroff
Courses Plus Student 14,198 Points

Here is missing template code I added, copied from video, no guarantees, but it appears to work for me:

communities/community_detail.html

    <div class="card card-with-shadow">
        <div class="content">
            <h5 class="title">Members</h5>
            <ul class="list-unstyled">
                {% for membership in community.good_members %}
                    <li class="row">
                        <a href="{% url 'posts:for_user' username=membership.user.username %}" class="col-md-9">{{ membership.user.display_name }}</a>
                        <div class="col-md-3 text-right">
                            {% if user.id in community.admins or user.id in community.moderators %}
                                {% if membership.user.id in community.moderators %}
                                    <a href="{% url 'communities:change_status' slug=community.slug user_id=membership.user.id status=1 %}"><i class="glyphicon glyphicon-thumbs-down text-warning"></i></a>
                                {% endif %}
                                {% if membership.user.id not in community.moderators and membership.user.id not in community.admins %}
                                    <a href="{% url 'communities:change_status' slug=community.slug user_id=membership.user.id status=2 %}"><i class="glyphicon glyphicon-thumbs-up text-warning"></i></a>
                                {% endif %}
                                {% if perms.communities.ban_member %}
                                    <a href="{% url 'communities:change_status' slug=community.slug user_id=membership.user.id status=0 %}"><i class="glyphicon glyphicon-ban-circle text-danger"></i></a>
                                {% endif %}
                            {% endif %}
                        </div>
                    </li>
                {% endfor %}
            </ul>
        </div>
    </div>
Greg Kaleka
Greg Kaleka
39,021 Points

Chris,

Thanks for this! I found one small error - the second class for the top level div should be card-with-shadow instead of card-with-shadows.

I took the liberty of editing your answer just in case others use it.

Cheers :beers:

-Greg

How to use multiple user type in django with some example please?