本文整理汇总了Python中filebrowser.forms.MakeDirForm类的典型用法代码示例。如果您正苦于以下问题:Python MakeDirForm类的具体用法?Python MakeDirForm怎么用?Python MakeDirForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MakeDirForm类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mkdir
def mkdir(request, dir_name=None):
"""
Make directory
"""
path = _get_path(request, dir_name)
query = _get_query(request.GET)
if request.method == 'POST':
form = MakeDirForm(PATH_SERVER, path, request.POST)
if form.is_valid():
server_path = os.path.join(PATH_SERVER, path, form.cleaned_data['dir_name'].lower())
try:
os.mkdir(server_path)
os.chmod(server_path, 0775)
# MESSAGE & REDIRECT
msg = _('The Folder %s was successfully created.') % (form.cleaned_data['dir_name'].lower())
request.user.message_set.create(message=msg)
# on redirect, sort by date desc to see the new directory on top of the list
return HttpResponseRedirect(URL_ADMIN + path + "?&ot=desc&o=3&" + query['pop'])
except OSError, (errno, strerror):
if errno == 13:
form.errors['dir_name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['dir_name'] = forms.util.ErrorList([_('Error creating directory.')])
示例2: mkdir
def mkdir(request):
"""
Make Directory.
"""
from filebrowser.forms import MakeDirForm
# QUERY / PATH CHECK
query = request.GET
path = _get_path(query.get('dir', ''))
if path 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)
if request.method == 'POST':
form = MakeDirForm(abs_path, request.POST)
if form.is_valid():
server_path = os.path.join(abs_path, form.cleaned_data['dir_name'])
try:
os.mkdir(server_path)
os.chmod(server_path, 0775)
msg = _('The Folder %s was successfully created.') % (form.cleaned_data['dir_name'])
request.user.message_set.create(message=msg)
# on redirect, sort by date desc to see the new directory on top of the list
# remove filter in order to actually _see_ the new folder
redirect_url = reverse("fb_browse") + query_helper(query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
if errno == 13:
form.errors['dir_name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['dir_name'] = forms.util.ErrorList([_('Error creating directory.')])
示例3: mkdir
def mkdir(request):
"""
Make Directory.
"""
from filebrowser.forms import MakeDirForm
# QUERY / PATH CHECK
query = request.GET
path = get_path(query.get('dir', ''))
if path is None:
msg = _('The requested Folder does not exist.')
messages.warning(request,message=msg)
return HttpResponseRedirect(reverse("fb_browse"))
abs_path = _check_access(request, path)
if request.method == 'POST':
form = MakeDirForm(abs_path, request.POST)
if form.is_valid():
_new_dir_name = form.cleaned_data['dir_name']
server_path = _check_access(request, path, _new_dir_name)
try:
# PRE CREATE SIGNAL
filebrowser_pre_createdir.send(sender=request, path=path, dirname=_new_dir_name)
# CREATE FOLDER
os.mkdir(server_path)
os.chmod(server_path, 0o775)
# POST CREATE SIGNAL
filebrowser_post_createdir.send(sender=request, path=path, dirname=_new_dir_name)
# MESSAGE & REDIRECT
msg = _('The Folder %s was successfully created.') % (_new_dir_name)
messages.success(request,message=msg)
# on redirect, sort by date desc to see the new directory on top of the list
# remove filter in order to actually _see_ the new folder
# remove pagination
redirect_url = reverse("fb_browse") + query_helper(query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q,p")
return HttpResponseRedirect(redirect_url)
except OSError(errno, strerror):
if errno == 13:
form.errors['dir_name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['dir_name'] = forms.util.ErrorList([_('Error creating folder.')])
else:
form = MakeDirForm(abs_path)
return render_to_response('filebrowser/makedir.html', {
'form': form,
'query': query,
'title': _(u'New Folder'),
'settings_var': get_settings_var(),
'breadcrumbs': get_breadcrumbs(query, path),
'breadcrumbs_title': _(u'New Folder')
}, context_instance=Context(request))
示例4: mkdir
def mkdir(request):
"""
Make Directory.
"""
from filebrowser.forms import MakeDirForm
# QUERY / PATH CHECK
query = request.GET
path = _get_path(query.get('dir', ''))
if path 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)
if request.method == 'POST':
form = MakeDirForm(abs_path, request.POST)
if form.is_valid():
server_path = os.path.join(abs_path, form.cleaned_data['dir_name'])
try:
dirname = form.cleaned_data['dir_name']
# PRE CREATE SIGNAL
filebrowser_pre_createdir.send(sender=request, path=path, dirname=dirname)
# CREATE FOLDER
if _supports_os():
os.mkdir(server_path)
os.chmod(server_path, 0775)
# POST CREATE SIGNAL
filebrowser_post_createdir.send(sender=request, path=path, dirname=dirname)
# MESSAGE & REDIRECT
msg = _('The Folder %s was successfully created.') % (dirname)
request.user.message_set.create(message=msg)
# on redirect, sort by date desc to see the new directory on top of the list
# remove filter in order to actually _see_ the new folder
from urllib import quote
new_path=quote(_normpath(os.path.join(path, dirname)))
redirect_url = reverse("fb_browse") + query_helper(query, "ot=desc,o=date,dir=%s" %(new_path), "ot,o,filter_type,filter_date,q")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
if errno == 13:
form.errors['dir_name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['dir_name'] = forms.util.ErrorList([_('Error creating directory.')])
示例5: mkdir
def mkdir(request):
"""
Make Directory.
"""
from filebrowser.forms import MakeDirForm
# QUERY / PATH CHECK
query = request.GET
path = get_path(query.get("dir", ""))
if path is None:
msg = _("The requested Folder does not exist.")
messages.warning(request, message=msg)
return HttpResponseRedirect(reverse("fb_browse"))
abs_path = os.path.join(fb_settings.MEDIA_ROOT, fb_settings.DIRECTORY, path)
if request.method == "POST":
form = MakeDirForm(abs_path, request.POST)
if form.is_valid():
server_path = os.path.join(abs_path, form.cleaned_data["dir_name"])
try:
# PRE CREATE SIGNAL
filebrowser_pre_createdir.send(sender=request, path=path, dirname=form.cleaned_data["dir_name"])
# CREATE FOLDER
os.mkdir(server_path)
os.chmod(server_path, 0775)
# POST CREATE SIGNAL
filebrowser_post_createdir.send(sender=request, path=path, dirname=form.cleaned_data["dir_name"])
# MESSAGE & REDIRECT
msg = _("The Folder %s was successfully created.") % (form.cleaned_data["dir_name"])
messages.success(request, message=msg)
# on redirect, sort by date desc to see the new directory on top of the list
# remove filter in order to actually _see_ the new folder
# remove pagination
redirect_url = reverse("fb_browse") + query_helper(
query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q,p"
)
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
if errno == 13:
form.errors["dir_name"] = forms.util.ErrorList([_("Permission denied.")])
else:
form.errors["dir_name"] = forms.util.ErrorList([_("Error creating folder.")])
示例6: test_make_dir_form
def test_make_dir_form(self):
data = {'dir_name': 'test_dir%$'}
form = MakeDirForm(self.working_dir, data)
self.assertFalse(form.is_valid())
self.assertEquals(
form.errors['dir_name'],
['Only letters, numbers, underscores, '
'spaces and hyphens are allowed.']
)
data = {'dir_name': 'test_dir'}
form = MakeDirForm(self.working_dir, data)
self.assertTrue(form.is_valid())
os.makedirs(os.path.join(self.working_dir, 'test_dir'))
data = {'dir_name': 'test_dir'}
form = MakeDirForm(self.working_dir, data)
self.assertFalse(form.is_valid())
self.assertEquals(
form.errors['dir_name'], ['The Folder already exists.']
)
os.rmdir(os.path.join(self.working_dir, 'test_dir'))