本文整理汇总了Python中filebrowser.settings.VERSIONS.items方法的典型用法代码示例。如果您正苦于以下问题:Python VERSIONS.items方法的具体用法?Python VERSIONS.items怎么用?Python VERSIONS.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filebrowser.settings.VERSIONS
的用法示例。
在下文中一共展示了VERSIONS.items方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_noargs
# 需要导入模块: from filebrowser.settings import VERSIONS [as 别名]
# 或者: from filebrowser.settings.VERSIONS import items [as 别名]
def handle_noargs(self, **options):
import os, re
from filebrowser.settings import EXTENSION_LIST, EXCLUDE, VERSIONS, EXTENSIONS
from filebrowser.conf import fb_settings
# Precompile regular expressions
filter_re = []
for exp in EXCLUDE:
filter_re.append(re.compile(exp))
for k, v in VERSIONS.items():
exp = (r"_{0}.({1})").format(k, "|".join(EXTENSION_LIST))
filter_re.append(re.compile(exp))
path = os.path.join(fb_settings.MEDIA_ROOT, fb_settings.DIRECTORY)
# walkt throu the filebrowser directory
# for all/new files (except file versions itself and excludes)
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
filtered = False
# no "hidden" files (stating with ".")
if filename.startswith("."):
continue
# check the exclude list
for re_prefix in filter_re:
if re_prefix.search(filename):
filtered = True
if filtered:
continue
(tmp, extension) = os.path.splitext(filename)
if extension in EXTENSIONS["Image"]:
self.createVersions(os.path.join(dirpath, filename))
示例2: browse
# 需要导入模块: from filebrowser.settings import VERSIONS [as 别名]
# 或者: from filebrowser.settings.VERSIONS import items [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.items():
exp = (r'_%s(%s)$') % (k, '|'.join(EXTENSION_LIST))
filter_re.append(re.compile(exp, re.IGNORECASE))
def filter_browse(item):
"Defining a browse filter"
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)
context = {
'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
}
if hasattr(admin_site,'has_permission'):
context['has_permission'] = admin_site.has_permission(request)
if hasattr(admin_site, 'site_url'):
context['site_url'] = admin_site.site_url
return render_to_response(
'filebrowser/index.html',
context,
context_instance=Context(request, current_app=self.name)
)
示例3: Command
# 需要导入模块: from filebrowser.settings import VERSIONS [as 别名]
# 或者: from filebrowser.settings.VERSIONS import items [as 别名]
import re
# DJANGO IMPORTS
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.utils.six.moves import input
# FILEBROWSER IMPORTS
from filebrowser.settings import EXTENSION_LIST, EXCLUDE, DIRECTORY, VERSIONS
from filebrowser.base import FileListing
filter_re = []
for exp in EXCLUDE:
filter_re.append(re.compile(exp))
for k, v in VERSIONS.items():
exp = (r'_%s(%s)') % (k, '|'.join(EXTENSION_LIST))
filter_re.append(re.compile(exp))
class Command(BaseCommand):
args = '<media_path>'
help = "(Re)Generate image versions."
def handle(self, *args, **options):
media_path = ""
if len(args):
media_path = args[0]
path = media_path
else:
示例4: browse
# 需要导入模块: from filebrowser.settings import VERSIONS [as 别名]
# 或者: from filebrowser.settings.VERSIONS import items [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.items():
exp = (r"_%s(%s)$") % (k, "|".join(EXTENSION_LIST))
filter_re.append(re.compile(exp, re.IGNORECASE))
def filter_browse(item):
"Defining a browse filter"
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")
re_q = None
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": "",
"filebrowser_site": self,
},
context_instance=Context(request, current_app=self.name),
)