当前位置: 首页>>代码示例>>Python>>正文


Python FileListing.files_walk_filtered方法代码示例

本文整理汇总了Python中filebrowser.base.FileListing.files_walk_filtered方法的典型用法代码示例。如果您正苦于以下问题:Python FileListing.files_walk_filtered方法的具体用法?Python FileListing.files_walk_filtered怎么用?Python FileListing.files_walk_filtered使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在filebrowser.base.FileListing的用法示例。


在下文中一共展示了FileListing.files_walk_filtered方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: listfile

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
def listfile(request):
	filelist ={} 
	if request.method == 'GET':
		filelisting = FileListing(settings.MEDIA_ROOT ,filter_func = filter_filelisting)
		for file in filelisting.files_walk_filtered():
			rel_file_path = file.url[len(settings.MEDIA_ROOT):]
			filelist[rel_file_path]= file.filename
			print file.url.find(settings.MEDIA_ROOT) + len(settings.MEDIA_ROOT)
	else : 
		delfile= request.POST.get('Delete')
		os.remove(delfile)
		filelisting = FileListing(settings.MEDIA_ROOT ,filter_func = filter_filelisting)
		for file in filelisting.files_walk_filtered():
			filelist[file.url]= file.filename
	return render_to_response('listfiles.html', { 'filelist' : filelist },  context_instance = RequestContext(request))
开发者ID:shtpkl,项目名称:dss,代码行数:17,代码来源:views.py

示例2: imagesFromSubfolder

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
def imagesFromSubfolder( subfolder ):

    directory = FB_DIRECTORY

    path = u'%s' % join( directory, 'gallery', subfolder )

    filelisting = FileListing(
        path,
        #filter_func=filter_browse,
        sorting_by='name',
        sorting_order='desc',
        #site=self
        )

    images = []

    for fileObject in filelisting.files_walk_filtered():#files_walk_total():
        image = {}
        if fileObject.width != None:
            thumbnail = getImage( fileObject, 'thumbnail' )
            fileName  = fileObject.url
            #thumbnail = loader.render_to_string( 'simple/subs/image.html', { 'fileObject': fileObject, 'size': 'thumbnail' } )
            #fileName  = loader.render_to_string( 'simple/subs/image.html', { 'fileObject': fileObject } )
            image[ 'url' ] = fileName
            image[ 'thumbnailUrl' ] = thumbnail
            image[ 'title' ] = fileObject.filename_root
            images.append( image )
    return images;
开发者ID:oofaish,项目名称:ucbc,代码行数:30,代码来源:views.py

示例3: browse

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
def browse(request):
    """
    Browse Files/Directories.
    """
    
    query = request.GET.copy()
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, query.get('dir', ''))

    filelisting = FileListing(abs_path,
        filter_func=filter_browse,
        sorting_by=query.get('o', DEFAULT_SORTING_BY),
        sorting_order=query.get('ot', DEFAULT_SORTING_ORDER))
    
    files = []
    if SEARCH_TRAVERSE and query.get("q"):
        listing = filelisting.files_walk_filtered()
    else:
        listing = filelisting.files_listing_filtered()

    # If we do a search, precompile the search pattern now
    do_search = query.get("q")
    if do_search:
        re_q = re.compile(query.get("q").lower(), re.M)

    filter_type = query.get('filter_type')
    filter_date = query.get('filter_date')
    
    for fileobject in listing:
        # date/type filter
        append = False
        if (not filter_type or fileobject.filetype == filter_type) and (not filter_date or get_filterdate(filter_date, fileobject.date or 0)):
            append = True
        # search
        if do_search and not re_q.search(fileobject.filename.lower()):
            append = False
        # append
        if append:
            files.append(fileobject)

    filelisting.results_total = len(listing)
    filelisting.results_current = len(files)
    
    p = Paginator(files, LIST_PER_PAGE)
    page_nr = request.GET.get('p', '1')
    try:
        page = p.page(page_nr)
    except (EmptyPage, InvalidPage):
        page = p.page(p.num_pages)

    return render_to_response('filebrowser/index.html', {
        'p': p,
        'page': page,
        'filelisting': filelisting,
        'query': query,
        'title': _(u'FileBrowser'),
        'settings_var': get_settings_var(),
        'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
        'breadcrumbs_title': ""
    }, context_instance=Context(request))
开发者ID:dblundell,项目名称:django-filebrowser,代码行数:61,代码来源:views.py

示例4: browse

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
def browse(request):
    """
    Browse Files/Directories.
    """
    
    query = request.GET.copy()
    user = request.user.username
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, user, query.get('dir', ''))
    if not abs_path.startswith(request.user.get_profile().media_path) and \
            not request.user.is_superuser:
        raise Http403("You may not access this directory")
    filelisting = FileListing(abs_path,
        filter_func=filter_browse,
        sorting_by=query.get('o', DEFAULT_SORTING_BY),
        sorting_order=query.get('ot', DEFAULT_SORTING_ORDER))
    
    files = []
    if SEARCH_TRAVERSE and query.get("q"):
        listing = filelisting.files_walk_filtered()
    else:
        listing = filelisting.files_listing_filtered()
    for fileobject in listing:
        # date/type filter
        append = False
        if fileobject.filetype == query.get('filter_type', fileobject.filetype) and get_filterdate(query.get('filter_date', ''), fileobject.date or 0):
            append = True
        # search
        if query.get("q") and not re.compile(query.get("q").lower(), re.M).search(fileobject.filename.lower()):
            append = False
        # append
        if append:
            files.append(fileobject)
    filelisting.results_total = filelisting.results_listing_filtered
    filelisting.results_current = len(files)
    
    p = Paginator(files, LIST_PER_PAGE)
    page_nr = request.GET.get('p', '1')
    try:
        page = p.page(page_nr)
    except (EmptyPage, InvalidPage):
        page = p.page(p.num_pages)
    
    return render_to_response('filebrowser/index.html', {
        'p': p,
        'page': page,
        'filelisting': filelisting,
        'query': query,
        'title': _(u'FileBrowser'),
        'settings_var': get_settings_var(),
        'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
        'breadcrumbs_title': ""
    }, context_instance=Context(request))
开发者ID:omare,项目名称:exedjango,代码行数:54,代码来源:views.py

示例5: handle

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
    def handle(self, *args, **options):
        media_path = ""

        if len(args):
            media_path = args[0]
            path = media_path
        else:
            path = DIRECTORY

        if not os.path.isdir(os.path.join(settings.MEDIA_ROOT, path)):
            raise CommandError('<media_path> must be a directory in MEDIA_ROOT (If you don\'t add a media_path the default path is DIRECTORY).\n"%s" is no directory.' % path)

        # get version name
        while 1:
            self.stdout.write('\nSelect a version you want to generate:\n')
            for version in VERSIONS:
                self.stdout.write(' * %s\n' % version)

            version_name = input('(leave blank to generate all versions): ')

            if version_name == "":
                selected_version = None
                break
            else:
                try:
                    tmp = VERSIONS[version_name]
                    selected_version = version_name
                    break
                except:
                    self.stderr.write('Error: Version "%s" doesn\'t exist.\n' % version_name)
                    version_name = None
                    continue

        # filelisting
        filelisting = FileListing(path, filter_func=self.filter_images)  # FIXME filterfunc: no hidden files, exclude list, no versions, just images!
        for fileobject in filelisting.files_walk_filtered():
            if fileobject.filetype == "Image":
                if selected_version:
                    self.stdout.write('generating version "%s" for: %s\n' % (selected_version, fileobject.path))
                    versionobject = fileobject.version_generate(selected_version)  # FIXME force?
                else:
                    self.stdout.write('generating all versions for: %s\n' % fileobject.path)
                    for version in VERSIONS:
                        versionobject = fileobject.version_generate(version)  # FIXME force?
开发者ID:dteskera,项目名称:django-filebrowser-suit,代码行数:46,代码来源:fb_version_generate.py

示例6: FileListingTests

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
class FileListingTests(TestCase):
    """
    /_test/uploads/testimage.jpg
    /_test/uploads/folder/
    /_test/uploads/folder/subfolder/
    /_test/uploads/folder/subfolder/testimage.jpg
    """

    def setUp(self):
        super(FileListingTests, self).setUp()

        self.F_LISTING_FOLDER = FileListing(self.DIRECTORY, sorting_by='date', sorting_order='desc')
        self.F_LISTING_IMAGE = FileListing(os.path.join(self.DIRECTORY, 'folder', 'subfolder', "testimage.jpg"))

        shutil.copy(self.STATIC_IMG_PATH, self.SUBFOLDER_PATH)
        shutil.copy(self.STATIC_IMG_PATH, self.DIRECTORY_PATH)

    def test_init_attributes(self):

        """
        FileListing init attributes

        # path
        # filter_func
        # sorting_by
        # sorting_order
        """
        self.assertEqual(self.F_LISTING_FOLDER.path, '_test/uploads/')
        self.assertEqual(self.F_LISTING_FOLDER.filter_func, None)
        self.assertEqual(self.F_LISTING_FOLDER.sorting_by, 'date')
        self.assertEqual(self.F_LISTING_FOLDER.sorting_order, 'desc')

    def test_listing(self):
        """
        FileObject listing

        # listing
        # files_listing_total
        # files_listing_filtered
        # results_listing_total
        # results_listing_filtered
        """

        self.assertEqual(self.F_LISTING_IMAGE.listing(), [])
        self.assertEqual(list(self.F_LISTING_FOLDER.listing()), [u'folder', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder'])
        self.assertEqual(self.F_LISTING_FOLDER.results_listing_total(), 2)
        self.assertEqual(self.F_LISTING_FOLDER.results_listing_filtered(), 2)

    def test_listing_filtered(self):
        """
        FileObject listing

        # listing
        # files_listing_total
        # files_listing_filtered
        # results_listing_total
        # results_listing_filtered
        """

        self.assertEqual(self.F_LISTING_IMAGE.listing(), [])
        self.assertEqual(list(self.F_LISTING_FOLDER.listing()), [u'folder', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_listing_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder'])
        self.assertEqual(self.F_LISTING_FOLDER.results_listing_total(), 2)
        self.assertEqual(self.F_LISTING_FOLDER.results_listing_filtered(), 2)

    def test_walk(self):
        """
        FileObject walk

        # walk
        # files_walk_total
        # files_walk_filtered
        # results_walk_total
        # results_walk_filtered
        """

        self.assertEqual(self.F_LISTING_IMAGE.walk(), [])
        self.assertEqual(list(self.F_LISTING_FOLDER.walk()), [u'folder/subfolder/testimage.jpg', u'folder/subfolder', u'folder', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_total()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder', u'_test/uploads/folder/subfolder', u'_test/uploads/folder/subfolder/testimage.jpg'])
        self.assertEqual(list(f.path for f in self.F_LISTING_FOLDER.files_walk_filtered()), [u'_test/uploads/testimage.jpg', u'_test/uploads/folder', u'_test/uploads/folder/subfolder', u'_test/uploads/folder/subfolder/testimage.jpg'])
        self.assertEqual(self.F_LISTING_FOLDER.results_walk_total(), 4)
        self.assertEqual(self.F_LISTING_FOLDER.results_walk_filtered(), 4)
开发者ID:CarlosOV,项目名称:django-filebrowser,代码行数:87,代码来源:test_base.py

示例7: browse

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
    def browse(self, request):
        """
        Browse Files/Directories.
        """

        filter_re = []
        for exp in EXCLUDE:
           filter_re.append(re.compile(exp))
        for k,v in VERSIONS.iteritems():
            exp = (r'_%s(%s)') % (k, '|'.join(EXTENSION_LIST))
            filter_re.append(re.compile(exp))

        def filter_browse(item):
            filtered = item.filename.startswith('.')
            for re_prefix in filter_re:
                if re_prefix.search(item.filename):
                    filtered = True
            if filtered:
                return False
            return True
        
        query = request.GET.copy()
        path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
        
        filelisting = FileListing(path,
            filter_func=filter_browse,
            sorting_by=query.get('o', DEFAULT_SORTING_BY),
            sorting_order=query.get('ot', DEFAULT_SORTING_ORDER),
            site=self)
        
        files = []
        if SEARCH_TRAVERSE and query.get("q"):
            listing = filelisting.files_walk_filtered()
        else:
            listing = filelisting.files_listing_filtered()
        
        # If we do a search, precompile the search pattern now
        do_search = query.get("q")
        if do_search:
            re_q = re.compile(query.get("q").lower(), re.M)
        
        filter_type = query.get('filter_type')
        filter_date = query.get('filter_date')
        
        for fileobject in listing:
            # date/type filter
            append = False
            if (not filter_type or fileobject.filetype == filter_type) and (not filter_date or get_filterdate(filter_date, fileobject.date or 0)):
                append = True
            # search
            if do_search and not re_q.search(fileobject.filename.lower()):
                append = False
            # append
            if append:
                files.append(fileobject)
        
        filelisting.results_total = len(listing)
        filelisting.results_current = len(files)
        
        p = Paginator(files, LIST_PER_PAGE)
        page_nr = request.GET.get('p', '1')
        try:
            page = p.page(page_nr)
        except (EmptyPage, InvalidPage):
            page = p.page(p.num_pages)
        
        return render_to_response('filebrowser/index.html', {
            'p': p,
            'page': page,
            'filelisting': filelisting,
            'query': query,
            'title': _(u'FileBrowser'),
            'is_popup': "pop" in request.REQUEST,   # ChangeList uses "pop"
            'settings_var': get_settings_var(directory=self.directory),
            'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
            'breadcrumbs_title': "",
            'filebrowser_site': self
        }, context_instance=Context(request, current_app=self.name))
开发者ID:bsavelev,项目名称:django-filebrowser-no-grappelli-django14,代码行数:80,代码来源:sites.py

示例8: FileListingTests

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]

#.........这里部分代码省略.........
        # create temporary test folder and move testimage
        # FIXME: find better path names
        self.tmpdir_name = os.path.join("fb_tmp_dir", "fb_tmp_dir_sub")
        self.tmpdir_path = os.path.join(site.storage.location, self.directory, self.tmpdir_name)
        if os.path.exists(self.tmpdir_path):
            self.fail("Temporary testfolder already exists.")
        else:
            os.makedirs(self.tmpdir_path)

        # copy test image to temporary test folder
        self.image_path = os.path.join(FILEBROWSER_PATH, "static", "filebrowser", "img", "testimage.jpg")
        if not os.path.exists(self.image_path):
            self.fail("Testimage not found.")
        shutil.copy(self.image_path, self.directory_path)
        shutil.copy(self.image_path, self.tmpdir_path)

        # set posixpath
        filebrowser.base.os.path = posixpath

        # filelisting/fileobject
        self.f_listing = FileListing(self.directory, sorting_by='date', sorting_order='desc')
        self.f_listing_file = FileListing(os.path.join(self.directory, self.tmpdir_name, "testimage.jpg"))

    def test_init_attributes(self):
        """
        FileListing init attributes

        # path
        # filter_func
        # sorting_by
        # sorting_order
        """
        self.assertEqual(self.f_listing.path, 'fb_test_directory/')
        self.assertEqual(self.f_listing.filter_func, None)
        self.assertEqual(self.f_listing.sorting_by, 'date')
        self.assertEqual(self.f_listing.sorting_order, 'desc')

    def test_listing(self):
        """
        FileObject listing

        # listing
        # files_listing_total
        # files_listing_filtered
        # results_listing_total
        # results_listing_filtered
        """
        self.assertEqual(self.f_listing_file.listing(), [])
        self.assertEqual(list(self.f_listing.listing()), [u'fb_tmp_dir', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.f_listing.files_listing_total()), [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir'])
        self.assertEqual(list(f.path for f in self.f_listing.files_listing_filtered()), [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir'])
        self.assertEqual(self.f_listing.results_listing_total(), 2)
        self.assertEqual(self.f_listing.results_listing_filtered(), 2)

    def test_listing_filtered(self):
        """
        FileObject listing

        # listing
        # files_listing_total
        # files_listing_filtered
        # results_listing_total
        # results_listing_filtered
        """
        self.assertEqual(self.f_listing_file.listing(), [])
        self.assertEqual(list(self.f_listing.listing()), [u'fb_tmp_dir', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.f_listing.files_listing_total()), [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir'])
        self.assertEqual(list(f.path for f in self.f_listing.files_listing_filtered()), [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir'])
        self.assertEqual(self.f_listing.results_listing_total(), 2)
        self.assertEqual(self.f_listing.results_listing_filtered(), 2)

    def test_walk(self):
        """
        FileObject walk

        # walk
        # files_walk_total
        # files_walk_filtered
        # results_walk_total
        # results_walk_filtered
        """
        self.assertEqual(self.f_listing_file.walk(), [])
        self.assertEqual(list(self.f_listing.walk()), [u'fb_tmp_dir/fb_tmp_dir_sub/testimage.jpg', u'fb_tmp_dir/fb_tmp_dir_sub', u'fb_tmp_dir', u'testimage.jpg'])
        self.assertEqual(list(f.path for f in self.f_listing.files_walk_total()),  [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir', u'fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub', u'fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage.jpg'])
        self.assertEqual(list(f.path for f in self.f_listing.files_walk_filtered()),  [u'fb_test_directory/testimage.jpg', u'fb_test_directory/fb_tmp_dir', u'fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub', u'fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage.jpg'])
        self.assertEqual(self.f_listing.results_walk_total(), 4)
        self.assertEqual(self.f_listing.results_walk_filtered(), 4)

    def tearDown(self):
        """
        Restore original values/functions
        """
        filebrowser.base.os.path = self.original_path
        site.directory = self.original_directory
        filebrowser.base.VERSIONS_BASEDIR = self.original_versions_basedir
        filebrowser.base.VERSIONS = self.original_versions
        filebrowser.base.ADMIN_VERSIONS = self.original_admin_versions

        # remove temporary directory and test folder
        shutil.rmtree(self.directory_path)
开发者ID:23critters,项目名称:django-filebrowser,代码行数:104,代码来源:base.py

示例9: browse

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
    def browse(self, request):
        """
        Browse Files/Directories.
        """

        filter_re = []
        for exp in EXCLUDE:
            filter_re.append(re.compile(exp))
        for k, v in VERSIONS.iteritems():
            exp = (r"_%s(%s)") % (k, "|".join(EXTENSION_LIST))
            filter_re.append(re.compile(exp))

        def filter_browse(item):
            filtered = item.filename.startswith(".")
            for re_prefix in filter_re:
                if re_prefix.search(item.filename):
                    filtered = True
            if filtered:
                return False
            return True

        query = request.GET.copy()
        path = u"%s" % os.path.join(self.directory, query.get("dir", ""))

        filelisting = FileListing(
            path,
            filter_func=filter_browse,
            sorting_by=query.get("o", DEFAULT_SORTING_BY),
            sorting_order=query.get("ot", DEFAULT_SORTING_ORDER),
            site=self,
        )

        files = []
        if SEARCH_TRAVERSE and query.get("q"):
            listing = filelisting.files_walk_filtered()
        else:
            listing = filelisting.files_listing_filtered()

        # If we do a search, precompile the search pattern now
        do_search = query.get("q")
        if do_search:
            re_q = re.compile(query.get("q").lower(), re.M)

        filter_type = query.get("filter_type")
        filter_date = query.get("filter_date")

        for fileobject in listing:
            # date/type filter
            append = False
            if (not filter_type or fileobject.filetype == filter_type) and (
                not filter_date or get_filterdate(filter_date, fileobject.date or 0)
            ):
                append = True
            # search
            if do_search and not re_q.search(fileobject.filename.lower()):
                append = False
            # append
            if append:
                files.append(fileobject)

        filelisting.results_total = len(listing)
        filelisting.results_current = len(files)

        p = Paginator(files, LIST_PER_PAGE)
        page_nr = request.GET.get("p", "1")
        try:
            page = p.page(page_nr)
        except (EmptyPage, InvalidPage):
            page = p.page(p.num_pages)

        return render_to_response(
            "filebrowser/index.html",
            {
                "p": p,
                "page": page,
                "filelisting": filelisting,
                "query": query,
                "title": _(u"FileBrowser"),
                "settings_var": get_settings_var(directory=self.directory),
                "breadcrumbs": get_breadcrumbs(query, query.get("dir", "")),
                "breadcrumbs_title": "",
                "site": self,
            },
            context_instance=Context(request, current_app=self.name),
        )
开发者ID:hcarvalhoalves,项目名称:django-filebrowser,代码行数:87,代码来源:sites.py

示例10: save

# 需要导入模块: from filebrowser.base import FileListing [as 别名]
# 或者: from filebrowser.base.FileListing import files_walk_filtered [as 别名]
    def save(self, *args, **kwargs):
        logger = logging.getLogger("undefcms")
        
        isFileNew = False
        
        if self.file:
            #get the mime
            mime = mimetypes.guess_type(self.file.path)[0]
            if self.extra is None:
                self.extra = {}
            self.extra["mime"] = mime
            if not "md5" in self.extra:
                self.extra["md5"] = ""
            
            #get the md5 hash
            oldMd5 = self.extra["md5"]
            self.extra["md5"] = getHash(settings.MEDIA_ROOT+self.file.path)
            
            if oldMd5 != self.extra["md5"]:
                isFileNew = True
            
            #isFileNew = True
            
            if self.type == "auto": #We don't know the mime type yet. try to guess it
                if mime == "image/jpeg" or mime == "image/png" or mime == "image/gif":
                    self.type = filetypes["image"]
                elif mime == "video/mp4":
                    self.type = filetypes["video"]
                elif mime == "video/ogg":
                    self.type = filetypes["video"]
                elif mime == "video/avi":
                    self.type = filetypes["video"]
                elif mime == 'audio/mpeg':
                    self.type = filetypes["audio"]
                else:
                    self.type = mime
            
            if self.type == "img":
                if isFileNew:
                    self.extra["width"] = self.file.width
                    self.extra["height"] = self.file.height
            
            if self.type == "listfolder":
                logger.debug("LOOKING THRU "+MEDIA_ROOT+self.file.path)
                
                def filter(item):
                    return item.is_version != True
                
                filelisting = FileListing(MEDIA_ROOT+self.file.path,  sorting_by='name', sorting_order='desc', filter_func=filter)
                for item in filelisting.files_walk_filtered():
                    #logger.debug(type(self) == type(PostFile))
                    #logger.debug(isinstance(self, PageFile))
                    newFile = None
                    if isinstance(self, PageFile):
                        newFile = PageFile(page=self.page)
                    if isinstance(self, PostFile):
                        newFile = PostFile(post = self.post)
                    if newFile is not None:
                        newFile.index = self.index
                        newFile.file = FileObject(os.path.join(self.file.path, item.filename))
                        newFile.save()
                if self.id > 0:
                    self.delete()
                return
            
            if self.type == "video":
                if isFileNew:
                    #get width and height of video
                    res = commands.getoutput("ffmpeg -i \""+settings.MEDIA_ROOT+self.file.path+"\"")
                    dimFind = re.findall(r'( \d+x\d+ )', res)
                    if len(dimFind) is 0:
                        dimFind = re.findall(r'(\d+x\d+)', res)
                    width = 0
                    height = 0
                    self.extra["width"] = 0
                    self.extra["height"] = 0
                    if len(dimFind) is not 0:
                        dim = dimFind[0].split("x")
                        width = dim[0]
                        height = dim[1]
                        self.extra["width"] = width
                        self.extra["height"] = height
                    #and now convert it to use for web
                    #from utils import convertVideo
                    #if width != 0 and height != 0:
                    #    self.extra["msg"] = convertVideo(self.file.path, width, height)

            self.extra["lastFile"] = self.file.filename
        super(File, self).save(*args, **kwargs)
开发者ID:underdoeg,项目名称:undefcms,代码行数:91,代码来源:models.py


注:本文中的filebrowser.base.FileListing.files_walk_filtered方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。