def test_format_string(self): self.assertEqual( utils.parse_tenant_config_path("foo/%s/bar"), "foo/{}/bar".format(self.tenant.schema_name), ) # Preserve trailing slash self.assertEqual( utils.parse_tenant_config_path("foo/%s/bar/"), "foo/{}/bar/".format(self.tenant.schema_name), )
def test_format_string(self): self.assertEqual( utils.parse_tenant_config_path("foo/%s/bar"), "foo/{}/bar".format(self.tenant.schema_name), ) # Preserve trailing slash self.assertEqual( utils.parse_tenant_config_path("foo/%s/bar/"), "foo/{}/bar/".format(self.tenant.schema_name), )
def base_url(self): _url = super().base_url _url = os.path.join(_url, utils.parse_tenant_config_path(self.relative_media_root)) if not _url.endswith('/'): _url += '/' return _url
def base_url(self): # pylint: disable=invalid-overridden-method _url = super().base_url _url = os.path.join( _url, utils.parse_tenant_config_path(self.relative_media_root)) if not _url.endswith('/'): _url += '/' return _url
def get_upload_filename(upload_name, user): user_path = _get_user_path(user) tenant_path = tenantutils.parse_tenant_config_path('%s') # Generate date based path to put uploaded file. # If CKEDITOR_RESTRICT_BY_DATE is True upload file to date specific path. if getattr(settings, 'CKEDITOR_RESTRICT_BY_DATE', True): date_path = datetime.now().strftime('%Y/%m/%d') else: date_path = '' # Complete upload path (upload_path + date_path). upload_path = os.path.join( settings.CKEDITOR_UPLOAD_PATH, tenant_path, user_path, date_path ) if (getattr(settings, 'CKEDITOR_UPLOAD_SLUGIFY_FILENAME', True) and not hasattr(settings, 'CKEDITOR_FILENAME_GENERATOR')): upload_name = utils.slugify_filename(upload_name) if hasattr(settings, 'CKEDITOR_FILENAME_GENERATOR'): generator = import_string(settings.CKEDITOR_FILENAME_GENERATOR) upload_name = generator(upload_name) return storage.get_available_name( os.path.join(upload_path, upload_name) )
def base_url(self): relative_tenant_media_url = utils.parse_tenant_config_path( self.relative_media_url) if self._base_url is None: return relative_tenant_media_url relative_tenant_media_url = "/" + "/".join( s.strip("/") for s in [self._base_url, relative_tenant_media_url]) + "/" return relative_tenant_media_url
def base_url(self): if self._base_url is not None and not self._base_url.endswith('/'): self._base_url += '/' _url = self._value_or_setting(self._base_url, settings.STATIC_URL) _url = os.path.join(_url, utils.parse_tenant_config_path(self.relative_static_root)) if not _url.endswith("/"): _url += "/" check_settings(_url) return _url
def base_url(self): rewrite_on, relative_tenant_url = self.relative_static_url if rewrite_on: relative_tenant_url = utils.parse_tenant_config_path( relative_tenant_url) if not relative_tenant_url.endswith('/'): relative_tenant_url += '/' if self._base_url is not None and not self._base_url.endswith('/'): self._base_url += '/' return self._value_or_setting(self._base_url, relative_tenant_url)
def __init__(self, location=None, base_url=None, *args, **kwargs): try: relative_media_root = settings.MULTITENANT_RELATIVE_MEDIA_ROOT except AttributeError: # MULTITENANT_RELATIVE_MEDIA_ROOT is an optional setting, use the default value if none provided relative_media_root = "" relative_media_root = utils.parse_tenant_config_path( relative_media_root) if location is None: location = os.path.join(settings.MEDIA_ROOT, relative_media_root) if base_url is None: base_url = os.path.join(settings.MEDIA_URL, relative_media_root) if not base_url.endswith("/"): base_url += "/" super(TenantFileSystemStorage, self).__init__(location, base_url, *args, **kwargs)
def dirs(self): """ Lazy retrieval of list of template directories based on current tenant schema. :return: The list of template file dirs that have been configured for this tenant. """ if self._dirs.get(connection.schema_name, None) is None: try: # Use directories configured via MULTITENANT_TEMPLATE_DIRS dirs = [ utils.parse_tenant_config_path(dir_) for dir_ in settings.MULTITENANT_TEMPLATE_DIRS ] except AttributeError: raise ImproperlyConfigured( "To use {}.{} you must define the MULTITENANT_TEMPLATE_DIRS setting." .format(__name__, Loader.__name__)) self.dirs = dirs return self._dirs[connection.schema_name]
def get_image_files(user=None, path=''): """ Recursively walks all dirs under upload dir and generates a list of full paths for each file found. """ tenant_path = tenantutils.parse_tenant_config_path('%s') # If a user is provided and CKEDITOR_RESTRICT_BY_USER is True, # limit images to user specific path, but not for superusers. STORAGE_DIRECTORIES = 0 STORAGE_FILES = 1 # allow browsing from anywhere if user is superuser # otherwise use the user path if user and not user.is_superuser: user_path = _get_user_path(user) else: user_path = '' browse_path = os.path.join(settings.CKEDITOR_UPLOAD_PATH, tenant_path, user_path, path) try: storage_list = storage.listdir(browse_path) except NotImplementedError: return except OSError: return for filename in storage_list[STORAGE_FILES]: if os.path.splitext(filename)[0].endswith('_thumb') or os.path.basename(filename).startswith('.'): continue filename = os.path.join(browse_path, filename) yield filename for directory in storage_list[STORAGE_DIRECTORIES]: if directory.startswith('.'): continue directory_path = os.path.join(path, directory) for element in get_image_files(user=user, path=directory_path): yield element
def locations(self): """ Lazy retrieval of list of locations with static files based on current tenant schema. :return: The list of static file dirs that have been configured for this tenant. """ if self._locations.get(connection.schema_name, None) is None: schema_locations = [] for root in settings.MULTITENANT_STATICFILES_DIRS: root = tenant_utils.parse_tenant_config_path(root) if isinstance(root, (list, tuple)): prefix, root = root else: prefix = "" if (prefix, root) not in schema_locations: schema_locations.append((prefix, root)) self._locations[connection.schema_name] = schema_locations return self._locations[connection.schema_name]
def locations(self): """ Lazy retrieval of list of locations with static files based on current tenant schema. :return: The list of static file dirs that have been configured for this tenant. """ if self._locations.get(connection.schema_name, None) is None: schema_locations = [] for root in settings.MULTITENANT_STATICFILES_DIRS: root = utils.parse_tenant_config_path(root) if isinstance(root, (list, tuple)): prefix, root = root else: prefix = "" if (prefix, root) not in schema_locations: schema_locations.append((prefix, root)) self._locations[connection.schema_name] = schema_locations return self._locations[connection.schema_name]
def dirs(self): """ Lazy retrieval of list of template directories based on current tenant schema. :return: The list of template file dirs that have been configured for this tenant. """ if self._dirs.get(connection.schema_name, None) is None: try: # Use directories configured via MULTITENANT_TEMPLATE_DIRS dirs = [ utils.parse_tenant_config_path(dir_) for dir_ in settings.MULTITENANT_TEMPLATE_DIRS ] except AttributeError: raise ImproperlyConfigured( "To use {}.{} you must define the MULTITENANT_TEMPLATE_DIRS setting.".format( __name__, Loader.__name__ ) ) self.dirs = dirs return self._dirs[connection.schema_name]
def __init__(self, location=None, base_url=None, *args, **kwargs): try: relative_static_root = settings.MULTITENANT_RELATIVE_STATIC_ROOT except AttributeError: # MULTITENANT_RELATIVE_STATIC_ROOT is an optional setting, use the default value if none provided relative_static_root = "" relative_static_root = utils.parse_tenant_config_path(relative_static_root) if location is None: location = os.path.join(settings.STATIC_ROOT, relative_static_root) if base_url is None: base_url = os.path.join(settings.STATIC_URL, relative_static_root) if not base_url.endswith("/"): base_url += "/" check_settings(base_url) super().__init__( location, base_url, *args, **kwargs )
def location(self): _location = os.path.join(super().location, utils.parse_tenant_config_path(self.relative_media_root)) return os.path.abspath(_location)
def location(self): # pylint: disable=invalid-overridden-method _location = os.path.join( super().location, utils.parse_tenant_config_path(self.relative_media_root)) return os.path.abspath(_location)
def base_location(self): return self._value_or_setting( self._location, utils.parse_tenant_config_path(self.relative_static_root))
def location(self): _location = os.path.join(settings.STATIC_ROOT, utils.parse_tenant_config_path(self.relative_static_root)) return os.path.abspath(_location)
def test_static_string(self): self.assertEqual( utils.parse_tenant_config_path("foo"), "foo/{}".format(self.tenant.schema_name), )
def test_static_string(self): self.assertEqual( utils.parse_tenant_config_path("foo"), "foo/{}".format(self.tenant.schema_name), )