コード例 #1
0
def filebrowser_browse(request):
    slug = 'katacontainers'
    filebrowser_site.directory = "uploads/%s/" % slug
    if get_path('', site=filebrowser_site) is None and \
            not os.path.exists(settings.MEDIA_ROOT + '/' + filebrowser_site.directory):
        dir = settings.MEDIA_ROOT + '/' + filebrowser_site.directory
        os.makedirs(dir)

    # Check and create folders named as modelname/fieldname
    url_dir = request.GET.get('dir', '')
    dir = settings.MEDIA_ROOT + '/' + filebrowser_site.directory + url_dir
    if get_path(url_dir,
                site=filebrowser_site) is None and not os.path.exists(dir):
        os.makedirs(dir)

    return path_exists(filebrowser_site,
                       filebrowser_view(filebrowser_site.browse))(request)
コード例 #2
0
ファイル: views.py プロジェクト: OpenStackweb/opendev
def filebrowser_browse(request):
    slug = request.META['HTTP_HOST'].split('.')[0]
    filebrowser_site.directory = "uploads/%s/" % slug
    # Check and create folder named as the hotel id number

    if get_path('', site=filebrowser_site) is None and \
            not os.path.exists(settings.MEDIA_ROOT + '/' + filebrowser_site.directory):
        dir = settings.MEDIA_ROOT + '/' + filebrowser_site.directory
        os.makedirs(dir)

    # Check and create folders named as modelname/fieldname
    url_dir = request.GET.get('dir', '')
    dir = settings.MEDIA_ROOT + '/' + filebrowser_site.directory + url_dir
    if get_path(url_dir, site=filebrowser_site) is None and not os.path.exists(dir):
        os.makedirs(dir)

    return path_exists(filebrowser_site, filebrowser_view(filebrowser_site.browse))(request)
コード例 #3
0
ファイル: sites.py プロジェクト: timur-orudzhov/e-travel
    def decorator(request, *args, **kwargs):

        if get_path('', site=site) is None:
            # The storage location does not exist, raise an error to prevent
            # eternal redirecting.
            raise ImproperlyConfigured(
                _("Error finding Upload-Folder (site.storage.location + site.directory)."
                  "Maybe it does not exist?")
            )
        normalized_url = slugify_url(
            request.GET.get('dir', ''),
        )
        get_params = request.GET.copy()

        if get_path(normalized_url, site=site) is None:
            site.storage.makedirs(os.path.join(site.directory, normalized_url))

        get_params['dir'] = normalized_url
        request.GET = get_params
        return function(request, *args, **kwargs)
コード例 #4
0
 def test_valid(self):
     self.assertTrue(get_path('folder/subfolder', site))
コード例 #5
0
 def test_does_not_exist(self):
     self.assertIsNone(get_path('folder/invalid', site))
コード例 #6
0
 def test_is_absolute(self):
     self.assertIsNone(get_path('/etc/password', site))
     self.assertIsNone(get_path('/folder/subfolder', site))
コード例 #7
0
 def test_starts_with_period(self):
     self.assertIsNone(get_path('..', site))
     self.assertIsNone(get_path('.filter/subfolder', site))
コード例 #8
0
 def test_empty(self):
     self.assertEqual(get_path('', site), '')