'Main object permissions view. Presents all users and groups with any
object permissions for the current model *instance*. Users or groups
without object permissions for related *instance* would **not** be
shown. In order to add or manage user or group one should use links or
forms presented within the page.'

def obj_perms_manage_view(self, request, object_pk):

    if (not self.has_change_permission(request, None)):
        post_url = reverse(u'admin:index', current_app=self.admin_site.name)
        return redirect(post_url)
    try:
        from django.contrib.admin.utils import unquote
    except ImportError:
        from django.contrib.admin.util import unquote
    obj = get_object_or_404(self.get_queryset(request), pk=unquote(object_pk))
    users_perms = OrderedDict(sorted(get_users_with_perms(obj, attach_perms=True, with_group_users=False).items(), key=(lambda user: getattr(user[0], get_user_model().USERNAME_FIELD))))
    groups_perms = OrderedDict(sorted(get_groups_with_perms(obj, attach_perms=True).items(), key=(lambda group: group[0].name)))
    if ((request.method == u'POST') and (u'submit_manage_user' in request.POST)):
        user_form = self.get_obj_perms_user_select_form(request)(request.POST)
        group_form = self.get_obj_perms_group_select_form(request)(request.POST)
        info = (self.admin_site.name, self.model._meta.app_label, get_model_name(self.model))
        if user_form.is_valid():
            user_id = user_form.cleaned_data[u'user'].pk
            url = reverse((u'%s:%s_%s_permissions_manage_user' % info), args=[obj.pk, user_id])
            return redirect(url)
    elif ((request.method == u'POST') and (u'submit_manage_group' in request.POST)):
        user_form = self.get_obj_perms_user_select_form(request)(request.POST)
        group_form = self.get_obj_perms_group_select_form(request)(request.POST)
        info = (self.admin_site.name, self.model._meta.app_label, get_model_name(self.model))
        if group_form.is_valid():
            group_id = group_form.cleaned_data[u'group'].id
            url = reverse((u'%s:%s_%s_permissions_manage_group' % info), args=[obj.pk, group_id])
            return redirect(url)
    else:
        user_form = self.get_obj_perms_user_select_form(request)()
        group_form = self.get_obj_perms_group_select_form(request)()
    context = self.get_obj_perms_base_context(request, obj)
    context[u'users_perms'] = users_perms
    context[u'groups_perms'] = groups_perms
    context[u'user_form'] = user_form
    context[u'group_form'] = group_form
    request.current_app = self.admin_site.name
    if (django.VERSION >= (1, 10)):
        return render(request, self.get_obj_perms_manage_template(), context)
    return render_to_response(self.get_obj_perms_manage_template(), context, RequestContext(request))
