burke-software / django-mass-edit

Make bulk changes in the Django admin interface
156 stars 68 forks source link

Loading templates in Django 1.8+ #74

Open joshvillbrandt opened 6 years ago

joshvillbrandt commented 6 years ago

Howdy!

After initial installation of django-mass-edit in a Django 1.11 app, I'm getting a TemplateDoesNotExist /admin/app/mymodel-masschange/1,2/ error when selecting two items to bulk edit from an admin list page. The docs mention uncommenting django.template.loaders.eggs.Loader from TEMPLATE_LOADERS in settings.py, but TEMPLATE_LOADERS does exist in my settings settings.py. After some research, it looks like the Django template settings got changed in 1.8.

In that upgrade documentation I noticed that I could add a loaders section and, low and behold, my TemplateDoesNotExist error goes away. As a second attempt, I uncommented APP_DIRS and added some loaders and things seem to work.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        # 'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            # using loaders instead of APP_DIRS to get this stupid eggs thing to work for massadmin
            # we should probably undo this at some point
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.eggs.Loader',
            ],
        },
    },
]

So, while this works, it doesn't seem like this is the right way to do things any longer. Any idea what the right way to do this is? Maybe massadmin needs to un-egg itself during install?

This may be related to #65 and #70.

SofianeDjellouli commented 6 years ago

Hi,

Maybe the problem is using django 1.11 instead of 1.8.

joshvillbrandt commented 6 years ago

I believe Django 1.8 uses the same TEMPLATES setting that was introduced in Django 1.11, so I'm not sure how using Django 1.8 would help. Could you elaborate?

SofianeDjellouli commented 6 years ago

If you use Django 1.8 you won't need to add this TEMPLATE_LOADERS part of the settings. TEMPLATE_LOADERS is specific to use Django 1.8 templates with Django 1.1 as in the link you posted. I tried it and it worked well.

joshvillbrandt commented 6 years ago

So first, I'd like to use Django 1.11. I'd lose features, performance improvements, and bug fixes if I go backwards to Django 1.8. (Django says that 1.8 has security issues and is no longer supported whereas 1.11 is supported until April 2020.) My request here relates to Django Mass Edit not having proper installation instructions for 1.11 and I'd like to know what those are.

Second, I believe the Django Mass Edit installation instructions are also insufficient for Django 1.8. The template settings are the same for Django 1.8 and Django 1.11 as Django 1.11 uses the refactored settings that were introduced in 1.8. You are correct in that if I use Django 1.8, I won't need TEMPLATE_LOADERS, but I also don't need TEMPLATE_LOADERS in Django 1.11 as demonstrated in my settings snippet in the initial comment here. So I think I'd have the same problem even if I downgraded to Django 1.8. Unless I'm totally missing the point of your suggestion...

Maybe you're confused because I linked to the 1.11 docs which mention 1.8? Here are the 1.8 version of the template docs which has the same content.

bufke commented 6 years ago

Happy to review any pull requests to modernize things, keep in mind this is an infrequently updated repo based on some blog post from 2010.

IMO it would be acceptable to drop support for any non supported Django version, Python 2, and just note in the readme to use the older version if needed. That would make it easier to modernize.

joshvillbrandt commented 6 years ago

Hey @bufke, I don't actually know what the right answer is, otherwise I would immediately submit a PR. I think the right answer has something to do with unzipping the egg during install. If you're not sure, then let's just keep this open for now. I may glance at some other plugins and interrogate their installation processes and hopefully I can glean the correct solution.

Thanks for taking the time to comment, @bufke! (And for making this plugin in the first place!)

namanshenoy commented 6 years ago

@joshvillbrandt https://github.com/namanshenoy/django-mass-edit

Check the readme my my fork, bufke said he would not accept it due to it being 'magic' and I agree, but if you do not care, give it a shot :)

My fix is in the Installation section

baronyoung commented 6 years ago

What does it mean that something is 'magic'?

EOSIT commented 6 years ago

@baronyoung - for example: