-
Notifications
You must be signed in to change notification settings - Fork 322
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
Update template loaders and static file storage for Django > 2.0 #198
Update template loaders and static file storage for Django > 2.0 #198
Conversation
af6e355
to
5d7010b
Compare
Ok, I think this PR is ready for review. It resolves a large number of long-standing issues related to static file handling. Apologies for the large commit - most of the diffs are generated by documentation changes and new test cases.
|
+1 this will resolve the tests, which do not currently pass when running |
@jcass77 Thanks for this. |
django_tenants.template.loaders.filesystem.Loader get initialized only once. It happens with the first request and directories are set based on that tenant. Same template directories get utilized for all further requests from any tenant. |
Not relying on self.dirs and overriding get_dirs is the way to go? Any performance considerations? Can they be mitigated using CachedLoader? |
Hmmm...I thought I tested that scenario but you are right @rdraju, the Loader is only initialised once so I can see how the same template might be returned for all subsequent tenants. Have a look at |
Unfortunately, This change breaks other functionalities. |
2. |
The issue seems to be that the {% static %} is always replaced by the STATIC_ROOT path and the schema name of the tenant appended ( STATIC_ROOT/tenant_schema ) even though there is no specific folder for tenant static files |
@gnalbandian can you log a ticket so that we can track an resolve this separately. If there are no tenant-specific static files for the project, then removing it from the |
If that is the intended behavior, then it's working as its intended. |
Thanks for the feedback @gnalbandian. Yes I think that is the intended behaviour: each For |
…tenants#249 because the both depend on the current schema_name they can't be cached, nor can be initialized only once in the constructor. An important reason is that the `default_storage` class in Django is initialized only once! Also includes a small performance improvement which prevents the raising and catching of exceptions when MULTITENANT_RELATIVE_MEDIA_ROOT is not specified at all! Note: looks like this changed in django-tenants#198 but looking at the PR doesn't reveal why that is. There is a discussion about static file finders and template loaders but nothing for TenantFileSystemStorage().
It looks like TenantStaticFileStorage has not been updated since Django 1.8, and is no longer compatible with Django > 2.0.
This PR just rebases the implementation on the standard django.template.loaders package to bring django-tenants back up to parity.
Fixes #197.