Esempio n. 1
0
def get_directory():
    """
    Returns FB's ``DIRECTORY`` setting, appending a directory using
    the site's ID if ``MEDIA_LIBRARY_PER_SITE`` is ``True``, and also
    creating the root directory if missing.
    """
    from mezzanine.conf import settings as mezz_settings
    from mezzanine.utils.sites import current_site_id
    from mezzanine.core.request import current_request
    #from mezzanine.utils.models import get_user_model_name
    dirname = DIRECTORY
    if getattr(mezz_settings, "MEDIA_LIBRARY_PER_SITE", False):
        dirname = os.path.join(dirname, "site-%s" % current_site_id())
    request = current_request()
    username = request.user.username
    if(username=='admin'):
        fullpath = os.path.join(mezz_settings.MEDIA_ROOT, dirname)
        if not default_storage.isdir(fullpath):
            default_storage.makedirs(fullpath)
    else:
        dirname = os.path.join(dirname, "username-%s" % username)
        fullpath = os.path.join(mezz_settings.MEDIA_ROOT, dirname)
        if not default_storage.isdir(fullpath):
            default_storage.makedirs(fullpath)
    return dirname
Esempio n. 2
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ""
     directory = self.directory
     if self.directory:
         if callable(self.directory):
             directory = self.directory()
         directory = os.path.normpath(
             datetime.datetime.now().strftime(directory))
         fullpath = os.path.join(get_directory(), directory)
         if not default_storage.isdir(fullpath):
             default_storage.makedirs(fullpath)
     final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
     final_attrs[
         'search_icon'] = URL_FILEBROWSER_MEDIA + 'img/filebrowser_icon_show.gif'
     final_attrs['directory'] = directory
     final_attrs['extensions'] = self.extensions
     final_attrs['format'] = self.format
     final_attrs['ADMIN_THUMBNAIL'] = ADMIN_THUMBNAIL
     final_attrs['DEBUG'] = DEBUG
     if value != "":
         try:
             final_attrs['directory'] = os.path.split(
                 value.path_relative_directory)[0]
         except:
             pass
     return render_to_string("filebrowser/custom_field.html",
                             dict(locals(), MEDIA_URL=MEDIA_URL))
Esempio n. 3
0
 def render(self, name, value, attrs=None, renderer=None):
     if value is None:
         value = ""
     directory = self.directory
     if self.directory:
         if callable(self.directory):
             directory = self.directory()
         directory = os.path.normpath(
             datetime.datetime.now().strftime(directory))
         fullpath = os.path.join(get_directory(), directory)
         if not default_storage.isdir(fullpath):
             default_storage.makedirs(fullpath)
     final_attrs = dict(type=self.input_type, name=name, **attrs)
     final_attrs["search_icon"] = (fb_settings.URL_FILEBROWSER_MEDIA +
                                   "img/filebrowser_icon_show.gif")
     final_attrs["directory"] = directory
     final_attrs["extensions"] = self.extensions
     final_attrs["format"] = self.format
     final_attrs["DEBUG"] = fb_settings.DEBUG
     if renderer is not None:
         return mark_safe(
             renderer.render(
                 "filebrowser/custom_field.html",
                 dict(locals(), MEDIA_URL=fb_settings.MEDIA_URL),
             ))
     else:
         return render_to_string(
             "filebrowser/custom_field.html",
             dict(locals(), MEDIA_URL=fb_settings.MEDIA_URL),
         )
Esempio n. 4
0
def get_path(path):
    """
    Get Path.
    """    
    if path.startswith('.') or os.path.isabs(path) or not default_storage.isdir(os.path.join(get_directory(), path)):
        return None
    return path
Esempio n. 5
0
def get_path(path):
    """
    Get Path.
    """
    if path.startswith('.') or os.path.isabs(path) or not default_storage.isdir(os.path.join(get_directory(), path)):
        return None
    return path
Esempio n. 6
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ""
     directory = self.directory
     if self.directory:
         instance = attrs.pop('instance', None)
         if callable(self.directory):
             if instance and instance.id:
                 directory = self.directory(instance)
             else:
                 directory = self.directory()
         directory = os.path.normpath(datetime.datetime.now().strftime(directory))
         fullpath = os.path.join(get_directory(), directory)
         if not default_storage.isdir(fullpath):
             default_storage.makedirs(fullpath)
     final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
     final_attrs['search_icon'] = URL_FILEBROWSER_MEDIA + 'img/filebrowser_icon_show.gif'
     final_attrs['directory'] = directory
     final_attrs['extensions'] = self.extensions
     final_attrs['format'] = self.format
     final_attrs['ADMIN_THUMBNAIL'] = ADMIN_THUMBNAIL
     final_attrs['DEBUG'] = DEBUG
     if value != "":
         try:
             final_attrs['directory'] = os.path.split(value.path_relative_directory)[0]
         except:
             pass
     return render_to_string("filebrowser/custom_field.html", dict(locals(), MEDIA_URL=MEDIA_URL))
Esempio n. 7
0
def get_path(path):
    """
    Get Path.
    """

    if path.startswith(".") or os.path.isabs(path) or not default_storage.isdir(os.path.join(DIRECTORY, path)):
        return None
    return path
Esempio n. 8
0
def get_directory():
    """
    Returns FB's ``DIRECTORY`` setting, appending a directory using
    the site's ID if ``MEDIA_LIBRARY_PER_SITE`` is ``True``, and also
    creating the root directory if missing.
    """
    dirname = DIRECTORY
    if getattr(mezz_settings, "MEDIA_LIBRARY_PER_SITE", False):
        dirname = os.path.join(dirname, "site-%s" % current_site_id())
    fullpath = os.path.join(mezz_settings.MEDIA_ROOT, dirname)
    if not default_storage.isdir(fullpath):
        default_storage.makedirs(fullpath)
    return dirname
Esempio n. 9
0
def get_directory():
    """
    Returns FB's ``DIRECTORY`` setting, appending a directory using
    the site's ID if ``MEDIA_LIBRARY_PER_SITE`` is ``True``, and also
    creating the root directory if missing.
    """

    dirname = fb_settings.DIRECTORY
    if getattr(dj_settings, "MEDIA_LIBRARY_PER_SITE", False):
        dirname = os.path.join(dirname, "site-%s" % current_site_id())
    fullpath = os.path.join(dj_settings.MEDIA_ROOT, dirname)
    if not default_storage.isdir(fullpath):
        default_storage.makedirs(fullpath)
    return dirname
Esempio n. 10
0
 def render(self, name, value, attrs=None, renderer=None):
     if value is None:
         value = ""
     directory = self.directory
     if self.directory:
         if callable(self.directory):
             directory = self.directory()
         directory = os.path.normpath(datetime.datetime.now().strftime(directory))
         fullpath = os.path.join(get_directory(), directory)
         if not default_storage.isdir(fullpath):
             default_storage.makedirs(fullpath)
     final_attrs = dict(type=self.input_type, name=name, **attrs)
     final_attrs['search_icon'] = URL_FILEBROWSER_MEDIA + 'img/filebrowser_icon_show.gif'
     final_attrs['directory'] = directory
     final_attrs['extensions'] = self.extensions
     final_attrs['format'] = self.format
     final_attrs['DEBUG'] = DEBUG
     return render_to_string("filebrowser/custom_field.html", dict(locals(), MEDIA_URL=MEDIA_URL))
Esempio n. 11
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ""
     directory = self.directory
     if self.directory:
         if callable(self.directory):
             directory = self.directory()
         directory = os.path.normpath(datetime.datetime.now().strftime(directory))
         fullpath = os.path.join(get_directory(), directory)
         if not default_storage.isdir(fullpath):
             default_storage.makedirs(fullpath)
     final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
     final_attrs["search_icon"] = URL_FILEBROWSER_MEDIA + "img/filebrowser_icon_show.gif"
     final_attrs["directory"] = directory
     final_attrs["extensions"] = self.extensions
     final_attrs["format"] = self.format
     final_attrs["DEBUG"] = DEBUG
     return render_to_string("filebrowser/custom_field.html", dict(locals(), MEDIA_URL=MEDIA_URL))
Esempio n. 12
0
def get_directory():
    """
    Returns FB's ``DIRECTORY`` setting, appending a directory using
    the site's ID if ``MEDIA_LIBRARY_PER_SITE`` is ``True``, and also
    creating the root directory if missing.
    """
    from mezzanine.conf import settings as mezz_settings
    from mezzanine.utils.sites import current_site_id
    from mezzanine.core.request import current_request
    username = current_request().user.get_username()
    DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", '/' + username)
    dirname = DIRECTORY
    if getattr(mezz_settings, "MEDIA_LIBRARY_PER_SITE", False):
        dirname = os.path.join(dirname, "site-%s" % current_site_id())
    fullpath = os.path.join(mezz_settings.MEDIA_ROOT, dirname)
    if not default_storage.isdir(fullpath):
        default_storage.makedirs(fullpath)
    return dirname
Esempio n. 13
0
 def is_folder(self):
     return default_storage.isdir(self.path)
Esempio n. 14
0
 def _is_folder(self):
     if self._is_folder_stored == None:
         self._is_folder_stored = default_storage.isdir(self.path)
     return self._is_folder_stored
Esempio n. 15
0
 def is_folder(self):
     if self._is_folder is not None:
         return self._is_folder
     return default_storage.isdir(self.path)
Esempio n. 16
0
 def _is_folder(self):
     if self._is_folder_stored == None:
         self._is_folder_stored = default_storage.isdir(self.path)
     return self._is_folder_stored
Esempio n. 17
0
 def is_folder(self):
     return default_storage.isdir(self.path)
Esempio n. 18
0
 def handle(self, *args, **options):
     print site.storage.__class__
     print default_storage.__class__
     print default_storage.isdir("uploads/")
     print site.storage.isdir("uploads/")