@login_required
def topic_manage(request, topic_slug):
    topic = get_topic(request, topic_slug)
    "if logged in user, not a moderator bail out."
    try:
        subs = SubscribedUser.objects.get(topic = topic, user = request.user)
        if not subs.is_moderator():
            return HttpResponseForbidden("%s is not a moderator for %s. You can't access this page." % (request.user.username, topic.full_name))
    except SubscribedUser.DoesNotExist:
        return HttpResponseForbidden("%s is not a moderator for %s. You can't access this page." % (request.user.username, topic.full_name))
    subs = SubscribedUser.objects.select_related().filter(topic = topic)
    inviteform = bforms.InviteUserForm(topic = topic)
    if request.method=='POST':
        username = request.POST['username']
        user = User.objects.get(username = username)
        if request.POST.has_key('promote'):
            sub = SubscribedUser.objects.get(user = user, topic = topic)
            sub.set_group('Moderator')
        if request.POST.has_key('demote'):
            sub = SubscribedUser.objects.get(user = user, topic = topic)
            sub.set_group('Member')
        if request.POST.has_key('Invite'):
            inviteform = bforms.InviteUserForm(topic = topic, data = request.POST)
            if inviteform.is_valid():
                inviteform.save()
                return HttpResponseRedirect('.')
    payload = {'topic':topic, 'subs':subs, 'inviteform':inviteform}
    return render(request, payload, 'news/manage_topic.html')
Allow moderators to manage a topic.
dataset/ETHPy150Open agiliq/django-socialnews/socialnews/news/topics.py/topic_manage