Python django.conf.settings 模块,MEDIAFILES_LOCATION 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用django.conf.settings.MEDIAFILES_LOCATION

项目:asset-manager    作者:emfoundation    | 项目源码 | 文件源码
def save(self, *args, **kwargs):

        # if first save
        if not self.id:
            self.update_filetype()

        # if a new file is uploaded, will update filename even if parent has also changed...
        elif self.tracker.has_changed('file'):
            old_s3_key = settings.MEDIAFILES_LOCATION + '/' + self.tracker.previous('file').name
            s3_utils.delete_s3_object(old_s3_key)
            # update filetype
            self.update_filetype()

        # but if file has not changed and parent has, must be handled manually
        elif self.tracker.has_changed('parent_id'):
            old_file_name = self.file.name
            self.file.name = str(self.parent.id) + '/' + self.get_filename()
            logging.info('Filename changed from {0} to {1}'.format(old_file_name, self.file.name))

            media_dir = settings.MEDIAFILES_LOCATION

            s3_utils.update_s3_key(media_dir + '/' + old_file_name, media_dir + '/' + self.file.name)

        super(Asset, self).save(*args, **kwargs)
项目:itaplay    作者:lhalam    | 项目源码 | 文件源码
def save_on_amazon_with_boto(clipfile):
    """Function that uploads clip on amazon

        Returns :
            str : url
    """
    if clipfile.size > MAX_CLIP_SIZE:
        raise ValidationError("Your file is too large. Please enter valid file")
    else:
        conn = S3Connection(local_settings.AWS_ACCESS_KEY_ID,
                            local_settings.AWS_SECRET_ACCESS_KEY)
        bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
        k = boto.s3.key.Key(bucket)
        k.key = settings.MEDIAFILES_LOCATION + clipfile.name
        # save on S3
        k.set_contents_from_file(clipfile)
        # make public
        k.set_acl('public-read')
        # generate url which will be save in database 
        url = k.generate_url(expires_in=0, query_auth=False)
        return url
项目:asset-manager    作者:emfoundation    | 项目源码 | 文件源码
def delete_file(sender, instance, **kwargs):
    """
    When an Asset is deleted, will delete the corresponding S3 Object
    """
    s3_key = settings.MEDIAFILES_LOCATION + '/' + instance.file.name
    s3_utils.delete_s3_object(s3_key)
项目:asset-manager    作者:emfoundation    | 项目源码 | 文件源码
def __str__(self):
        path = self.get_path()
        if path.startswith(settings.MEDIAFILES_LOCATION + '/'):
            path = path[6:]
        return path
项目:asset-manager    作者:emfoundation    | 项目源码 | 文件源码
def get_path(self):
        """
        Returns an up to date Folder path based on its location in the Django \
        model.
        """
        if not self.parent:
            return settings.MEDIAFILES_LOCATION + '/' + self.name
        else:
            return self.parent.get_path() + '/' + self.name
项目:asset-manager    作者:emfoundation    | 项目源码 | 文件源码
def get_filename(self):
        """
        Asset.file.name contains the full filepath, relative to MEDIAFILES_LOCATION ie 'parent_id/filename'
        To get just the filename, we split the string from the right, once, on first '/'
        """
        filename = self.file.name
        if '/' in filename:
            return filename.rsplit('/',1)[1]
        return filename
项目:itaplay    作者:lhalam    | 项目源码 | 文件源码
def delete_from_amazon_with_boto(url):
    """Function that delete clip from amazon

        Returns : True
    """
    conn = S3Connection(local_settings.AWS_ACCESS_KEY_ID,
                        local_settings.AWS_SECRET_ACCESS_KEY)
    bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
    k = boto.s3.key.Key(bucket)
    filename_from_url = url.split('/')[-1]
    k.key = settings.MEDIAFILES_LOCATION + filename_from_url
    bucket.delete_key(k)
    return True
项目:perdiem-django    作者:RevolutionTech    | 项目源码 | 文件源码
def get_temporary_url(self, ttl=60):
        if hasattr(settings, 'AWS_STORAGE_BUCKET_NAME'):
            s3 = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, is_secure=True)
            key = "{media}/{filename}".format(media=settings.MEDIAFILES_LOCATION, filename=self.file.name)
            return s3.generate_url(ttl, 'GET', bucket=settings.AWS_STORAGE_BUCKET_NAME, key=key)
        return self.file.url