本文整理汇总了Python中filebrowser.forms.RenameForm.errors['name']方法的典型用法代码示例。如果您正苦于以下问题:Python RenameForm.errors['name']方法的具体用法?Python RenameForm.errors['name']怎么用?Python RenameForm.errors['name']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filebrowser.forms.RenameForm
的用法示例。
在下文中一共展示了RenameForm.errors['name']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rename
# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors['name'] [as 别名]
def rename(request):
"""
Rename existing File/Directory.
Includes renaming existing Image Versions/Thumbnails.
"""
from filebrowser.forms import RenameForm
# QUERY / PATH CHECK
query = request.GET
path = get_path(query.get('dir', ''))
if 'pop' in query:
is_popup = True
else:
is_popup = False
filename = get_file(query.get('dir', ''), query.get('filename', ''))
if path is None or filename is None:
if path is None:
msg = _('The requested Folder does not exist.')
else:
msg = _('The requested File does not exist.')
messages.warning(request, message=msg)
return HttpResponseRedirect(reverse("fb_browse"))
abs_path = _check_access(request, path)
file_extension = os.path.splitext(filename)[1].lower()
if request.method == 'POST':
form = RenameForm(abs_path, file_extension, request.POST)
if form.is_valid():
relative_server_path = os.path.join(fb_settings.DIRECTORY, path, filename)
new_filename = form.cleaned_data['name'] + file_extension
new_relative_server_path = os.path.join(fb_settings.DIRECTORY, path, new_filename)
try:
# PRE RENAME SIGNAL
filebrowser_pre_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
# DELETE IMAGE VERSIONS/THUMBNAILS
# regenerating versions/thumbs will be done automatically
for version in VERSIONS:
try:
os.unlink(os.path.join(fb_settings.MEDIA_ROOT, get_version_path(relative_server_path, version)))
except:
pass
# RENAME ORIGINAL
os.rename(os.path.join(fb_settings.MEDIA_ROOT, relative_server_path),
os.path.join(fb_settings.MEDIA_ROOT, new_relative_server_path))
# POST RENAME SIGNAL
filebrowser_post_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
# MESSAGE & REDIRECT
msg = _('Renaming was successful.')
messages.success(request, message=msg)
redirect_url = reverse("fb_browse") + query_helper(query, "", "filename")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error.')])
示例2: rename
# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors['name'] [as 别名]
def rename(request, dir_name=None, file_name=None):
"""
Rename existing File/Directory.
"""
path = _get_path(request, dir_name)
query = _get_query(request.GET)
if os.path.isfile(os.path.join(PATH_SERVER, path, file_name)): # file
file_type = _get_file_type(file_name)
file_extension = os.path.splitext(file_name)[1].lower()
else:
file_extension = ""
file_type = ""
if request.method == 'POST':
form = RenameForm(PATH_SERVER, path, file_extension, request.POST)
if form.is_valid():
old_path = os.path.join(PATH_SERVER, path, file_name)
new_path = os.path.join(PATH_SERVER, path, request.POST.get('name').lower() + file_extension)
try:
os.rename(old_path, new_path)
# RENAME IMAGE_THUMBNAILS
if file_type == 'Image':
old_thumb_path = os.path.join(PATH_SERVER, path, THUMB_PREFIX + file_name)
new_thumb_path = os.path.join(PATH_SERVER, path, THUMB_PREFIX + request.POST.get('name').lower() + file_extension)
try:
os.rename(old_thumb_path, new_thumb_path)
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error renaming Thumbnail.')])
# RENAME IMAGE VERSIONS? TOO MUCH MAGIC?
# MESSAGE & REDIRECT
if not form.errors:
msg = _('Renaming was successful.')
request.user.message_set.create(message=msg)
# on redirect, sort by date desc to see the new stuff on top of the list
return HttpResponseRedirect(URL_ADMIN + path + "?&ot=desc&o=3&" + query['pop'])
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error.')])
示例3: rename
# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors['name'] [as 别名]
def rename(request):
"""
Rename existing File/Directory.
Includes renaming existing Image Versions/Thumbnails.
"""
from filebrowser.forms import RenameForm
# QUERY / PATH CHECK
query = request.GET
path = _get_path(query.get('dir', ''))
filename = _get_file(query.get('dir', ''), query.get('filename', ''))
if path is None or filename is None:
msg = _('Directory/File does not exist.')
request.user.message_set.create(message=msg)
return HttpResponseRedirect(reverse("fb_browse"))
abs_path = os.path.join(MEDIA_ROOT, DIRECTORY, path)
file_extension = os.path.splitext(filename)[1].lower()
if request.method == 'POST':
form = RenameForm(abs_path, file_extension, request.POST)
if form.is_valid():
relative_server_path = os.path.join(DIRECTORY, path, filename)
new_relative_server_path = os.path.join(DIRECTORY, path, form.cleaned_data['name'] + file_extension)
try:
# PRE RENAME SIGNAL
filebrowser_pre_delete.send(sender=request, path=path, filename=filename)
# DELETE IMAGE VERSIONS/THUMBNAILS
# regenerating versions/thumbs will be done automatically
for version in VERSIONS:
try:
_delete(MEDIA_ROOT, _get_version_path(relative_server_path, version))
#os.unlink(os.path.join(MEDIA_ROOT, _get_version_path(relative_server_path, version)))
except:
pass
# RENAME ORIGINAL
newfile = os.path.join(MEDIA_ROOT, new_relative_server_path)
oldfile = os.path.join(MEDIA_ROOT, relative_server_path)
# opening and saving might not be efficient, but it works with all storages
default_storage.save(newfile, default_storage.open(oldfile))
default_storage.delete(oldfile)
# POST RENAME SIGNAL
filebrowser_post_delete.send(sender=request, path=path, filename=filename)
# MESSAGE & REDIRECT
msg = _('Renaming was successful.')
request.user.message_set.create(message=msg)
redirect_url = reverse("fb_browse") + query_helper(query, "", "filename")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error.')])
示例4: rename
# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors['name'] [as 别名]
def rename(request):
"""
Rename existing File/Directory.
Includes renaming existing Image Versions/Thumbnails.
"""
from filebrowser.forms import RenameForm
# QUERY / PATH CHECK
result = _get_path_and_filename(request)
if isinstance(result, HttpResponse):
# path or filename doesn't exist
return result
path, filename, abs_path = result
file_extension = os.path.splitext(filename)[1].lower()
if request.method == 'POST':
form = RenameForm(abs_path, file_extension, request.POST)
if form.is_valid():
relative_server_path = os.path.join(DIRECTORY, path, filename)
new_filename = form.cleaned_data['name'] + file_extension
new_relative_server_path = os.path.join(DIRECTORY, path, new_filename)
try:
# PRE RENAME SIGNAL
filebrowser_pre_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
# DELETE IMAGE VERSIONS/THUMBNAILS
# regenerating versions/thumbs will be done automatically
for version in VERSIONS:
try:
os.unlink(os.path.join(MEDIA_ROOT, get_version_path(relative_server_path, version)))
except:
pass
# RENAME ORIGINAL
os.rename(os.path.join(MEDIA_ROOT, relative_server_path), os.path.join(MEDIA_ROOT, new_relative_server_path))
# POST RENAME SIGNAL
filebrowser_post_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
# MESSAGE & REDIRECT
msg = _('Renaming was successful.')
request.user.message_set.create(message=msg)
redirect_url = reverse("fb_browse") + query_helper(request.GET, "", "filename")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error.')])
示例5: rename
# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors['name'] [as 别名]
def rename(request):
"""
Rename existing File/Directory.
Includes renaming existing Image Versions/Thumbnails.
"""
from filebrowser.forms import RenameForm
# QUERY / PATH CHECK
query = request.GET
path = _get_path(query.get('dir', ''))
filename = _get_file(query.get('dir', ''), query.get('filename', ''))
if path is None or filename is None:
msg = _('Directory/File does not exist.')
request.user.message_set.create(message=msg)
return HttpResponseRedirect(reverse("fb_browse"))
abs_path = os.path.join(settings.MEDIA_ROOT, DIRECTORY, path)
file_extension = os.path.splitext(filename)[1].lower()
if request.method == 'POST':
form = RenameForm(abs_path, file_extension, request.POST)
if form.is_valid():
relative_server_path = os.path.join(DIRECTORY, path, filename)
new_relative_server_path = os.path.join(DIRECTORY, path, form.cleaned_data['name'] + file_extension)
try:
# DELETE IMAGE VERSIONS/THUMBNAILS
# regenerating versions/thumbs will be done automatically
for version in VERSIONS:
try:
os.unlink(os.path.join(MEDIA_ROOT, _get_version_path(relative_server_path, version)))
except:
pass
# RENAME ORIGINAL
os.rename(os.path.join(MEDIA_ROOT, relative_server_path), os.path.join(MEDIA_ROOT, new_relative_server_path))
msg = _('Renaming was successful.')
request.user.message_set.create(message=msg)
redirect_url = reverse("fb_browse") + query_helper(query, "", "filename")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
form.errors['name'] = forms.util.ErrorList([_('Error.')])