Skip to content

Commit

Permalink
Revert "Merge pull request #256 from Develatio/fix_248"
Browse files Browse the repository at this point in the history
This reverts commit 73110c5, reversing
changes made to b750aa2.
  • Loading branch information
tomturner committed Oct 15, 2019
1 parent 73110c5 commit 855453f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
49 changes: 1 addition & 48 deletions django_tenants/staticfiles/finders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from django.contrib.staticfiles.finders import AppDirectoriesFinder, FileSystemFinder
from django.contrib.staticfiles.finders import FileSystemFinder
from django.conf import settings
from django.core.checks import Error
from collections import OrderedDict
Expand All @@ -9,39 +8,6 @@
from django_tenants import utils as tenant_utils
from django_tenants.files.storage import TenantFileSystemStorage

class TenantAppDirectoriesFinder(AppDirectoriesFinder):
"""
This is a replacement for the AppDirectoriesFinder. The only difference between
this and the standard AppDirectoriesFinder implementation is that this one will
understand how tenant-aware file handling works and where to search for your
files.
In-detail explanation:
Let's say that we have a Tenant called "Foo" (foo.com).
When we try to access, let's say, foo.com/admin, the browser will issue a request
to (among others) foo.com/static/foo/admin/css/base.css , instead of the
usual request if we didn't use django-tenants (foo.com/static/admin/css/base.css).
See the "foo" right before "admin"?
In order for this to work as expected we must remove the "foo", as we have
already added the path "tenants/%s/static" to the paths that Django will
look.
If we didn't remove the "foo" from the path, Django would look in
/code/tenants/foo/static/foo/admin/css/base.css , which is wrong.
Note: Keep in mind that this code won't run at all when behind uWSGI/NGINX/whatever
web server you're using. Django won't even know where your static files are at!
"""
def find_in_app(self, app, path):
"""
Find a requested static file in an app's static locations.
"""
if getattr(settings, "MULTITENANT_STATICFILES_DIRS", False):
path = os.path.sep.join(path.split(os.path.sep)[1:])
return super().find_in_app(app, path)

class TenantFileSystemFinder(FileSystemFinder):
"""
Expand All @@ -61,19 +27,6 @@ def __init__(self, app_names=None, *args, **kwargs):
self._locations = {}
self._storages = {}

def find_location(self, root, path, prefix=None):
"""
Find a requested static file in a location and return the found
absolute path (or ``None`` if no match).
"""
# This will remove the name of the tenant from the path. This will
# allow is to correctly match the path when using Djang's built-in
# server.
# Note that this doesn't matter at all when running in production
# mode as Django won't be handling the static files.
path = os.path.sep.join(path.split(os.path.sep)[1:])
return super().find_location(root, path, prefix)

@property
def locations(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions docs/files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Start by inserting django-tenants' ``django_tenants.staticfiles.finders.TenantFi
STATICFILES_FINDERS = [
"django_tenants.staticfiles.finders.TenantFileSystemFinder", # Must be first
"django.contrib.staticfiles.finders.FileSystemFinder",
"django_tenants.staticfiles.finders.TenantAppDirectoriesFinder", # This replaces Django's AppDirectoriesFinder
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
Expand Down Expand Up @@ -102,7 +102,7 @@ The path specified in ``MULTITENANT_RELATIVE_STATIC_ROOT`` tells ``TenantStaticF
The command to collect the static files for all tenants is ``collectstatic_schemas``. The optional ``--schema`` argument can be used to only collect files for a single tenant.

.. code-block:: bash
./manage.py collectstatic_schemas --schema=your_tenant_schema_name
.. note::
Expand Down

0 comments on commit 855453f

Please sign in to comment.