Python Django Authentication Users and Authorization Checkpoints

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 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.

3 Answers

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 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
38,993 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