def get_upload_filename(upload_name, user): user_path = _get_user_path(user) # 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, 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 get_upload_filename(upload_name, user): user_path = _get_user_path(user) # 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, 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 get_upload_filename(upload_name, user): # If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path. if getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False): user_path = user.username else: user_path = '' # Generate date based path to put uploaded file. date_path = datetime.now().strftime('%Y/%m/%d') # Complete upload path (upload_path + date_path). upload_path = os.path.join( settings.CKEDITOR_UPLOAD_PATH, user_path, date_path) if getattr(settings, "CKEDITOR_UPLOAD_SLUGIFY_FILENAME", True): upload_name = utils.slugify_filename(upload_name) return default_storage.get_available_name(os.path.join(upload_path, upload_name))
def get_upload_filename(upload_name, user): # If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path. if getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False): user_path = user.username else: user_path = '' # Generate date based path to put uploaded file. date_path = datetime.now().strftime('%Y/%m/%d') # Complete upload path (upload_path + date_path). upload_path = os.path.join( settings.CKEDITOR_UPLOAD_PATH, user_path, date_path) if getattr(settings, "CKEDITOR_UPLOAD_SLUGIFY_FILENAME", True): upload_name = utils.slugify_filename(upload_name) return default_storage.get_available_name(os.path.join(upload_path, upload_name))
def get_upload_filename(upload_name, request): user_path = _get_user_path(request.user) # 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, 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) # Does the generator accept a request argument? try: inspect.signature(generator).bind(upload_name, request) except TypeError: # Does the generator accept only an upload_name argument? try: inspect.signature(generator).bind(upload_name) except TypeError: warnings.warn( "Update %s() to accept the arguments `filename, request`." % settings.CKEDITOR_FILENAME_GENERATOR ) else: warnings.warn( "Update %s() to accept a second `request` argument." % settings.CKEDITOR_FILENAME_GENERATOR, PendingDeprecationWarning, ) upload_name = generator(upload_name) else: upload_name = generator(upload_name, request) return storage.get_available_name(os.path.join(upload_path, upload_name))
def get_upload_filename(upload_name, user): user_path = '' # If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path. RESTRICT_BY_USER = getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False) if RESTRICT_BY_USER: try: user_prop = getattr(user, RESTRICT_BY_USER) except AttributeError: user_prop = getattr(user, 'get_username') if callable(user_prop): user_path = user_prop() else: user_path = user_prop # 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, 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 default_storage.get_available_name( os.path.join(upload_path, upload_name) )
def get_upload_filename(upload_name, user): user_path = '' # If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path. RESTRICT_BY_USER = getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False) if RESTRICT_BY_USER: try: user_prop = getattr(user, RESTRICT_BY_USER) except AttributeError: user_prop = getattr(user, 'get_username') if callable(user_prop): user_path = user_prop() else: user_path = user_prop # 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, 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 default_storage.get_available_name( os.path.join(upload_path, upload_name) )