Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with djangoadmin_reorder #106

Open
pakal opened this issue Mar 9, 2022 · 0 comments
Open

Compatibility with djangoadmin_reorder #106

pakal opened this issue Mar 9, 2022 · 0 comments

Comments

@pakal
Copy link

pakal commented Mar 9, 2022

Just in case someone stumbles on this :

the mass-edit form page doesn't get updated by djangoadmin_reorder middleware, because it uses direct render() and not template reponse ;

so one should replace in massadmin/massadmin.py the calls to "render" with calls to "TemplateResponse".

This is only the first step, because djangoadmin_reorder doesn't have a way to detect that django-mass-edit urls belong to the admin category. I have no idea what's the best way to make apps recognize each other, for example django-adminsortable uses get_urls() method of Admin to register itself, and thus naturally gets recognzied as part of the admin.

For now here is a quick hack to force recognition:

def patched_ModelAdminReorder_process_template_response(self, request, response):
    try:
        url = resolve(request.path_info)
    except Resolver404:
        return response

    if not url.app_name == 'admin' and \
            url.url_name not in ['index', 'app_list', 'massadmin_change_view']:  # HACKED
        # current view is not a django admin index
        # or app_list view, bail out!
        return response

    if 'app_list' in response.context_data:
        app_list = response.context_data['app_list']
        context_key = 'app_list'
    # handle django 3.1 sidebar
    elif 'available_apps' in response.context_data:
        app_list = response.context_data['available_apps']
        context_key = 'available_apps'
    else:  # nothing to reorder, return response
        return response

    self.init_config(request, app_list)
    ordered_app_list = self.get_app_list()
    response.context_data[context_key] = ordered_app_list
    return response

import admin_reorder.middleware
admin_reorder.middleware.ModelAdminReorder.process_template_response = patched_ModelAdminReorder_process_template_response```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant