本文整理汇总了Python中filebrowser.forms.CreateDirForm类的典型用法代码示例。如果您正苦于以下问题:Python CreateDirForm类的具体用法?Python CreateDirForm怎么用?Python CreateDirForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CreateDirForm类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createdir
def createdir(self, request):
"""
Create Directory.
"""
from filebrowser.forms import CreateDirForm
query = request.GET
path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
if request.method == 'POST':
form = CreateDirForm(path, request.POST, filebrowser_site=self)
if form.is_valid():
server_path = os.path.join(path, form.cleaned_data['name'])
try:
self.filebrowser_pre_createdir.send(sender=request, path=server_path, name=form.cleaned_data['name'])
self.storage.makedirs(server_path)
# os.mkdir(server_path)
# os.chmod(server_path, 0775) # ??? PERMISSIONS
self.filebrowser_post_createdir.send(sender=request, path=server_path, name=form.cleaned_data['name'])
messages.add_message(request, messages.SUCCESS, _('The Folder %s was successfully created.') % form.cleaned_data['name'])
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + 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['name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['name'] = forms.util.ErrorList([_('Error creating folder.')])
示例2: createdir
def createdir(self, request):
"Create Directory"
from filebrowser.forms import CreateDirForm
query = request.GET
path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
if request.method == 'POST':
form = CreateDirForm(path, request.POST, filebrowser_site=self)
if form.is_valid():
server_path = os.path.join(path, form.cleaned_data['name'])
try:
signals.filebrowser_pre_createdir.send(sender=request, path=server_path, name=form.cleaned_data['name'], site=self)
self.storage.makedirs(server_path)
signals.filebrowser_post_createdir.send(sender=request, path=server_path, name=form.cleaned_data['name'], site=self)
messages.add_message(request, messages.SUCCESS, _('The Folder %s was successfully created.') % form.cleaned_data['name'])
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q,p")
return HttpResponseRedirect(redirect_url)
except OSError as e:
errno = e.args[0]
if errno == 13:
form.errors['name'] = forms.util.ErrorList([_('Permission denied.')])
else:
form.errors['name'] = forms.util.ErrorList([_('Error creating folder.')])
else:
form = CreateDirForm(path, filebrowser_site=self)
return render_to_response('filebrowser/createdir.html', {
'form': form,
'query': query,
'title': _(u'New Folder'),
'settings_var': get_settings_var(directory=self.directory),
'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
'breadcrumbs_title': _(u'New Folder'),
'filebrowser_site': self
}, context_instance=Context(request, current_app=self.name))
示例3: createdir
def createdir(self, request):
"Create Directory"
from filebrowser.forms import CreateDirForm
query = request.GET
path = u"%s" % os.path.join(self.directory, query.get("dir", ""))
if request.method == "POST":
form = CreateDirForm(path, request.POST, filebrowser_site=self)
if form.is_valid():
server_path = os.path.join(path, form.cleaned_data["name"])
try:
signals.filebrowser_pre_createdir.send(
sender=request, path=server_path, name=form.cleaned_data["name"], site=self
)
self.storage.makedirs(server_path)
signals.filebrowser_post_createdir.send(
sender=request, path=server_path, name=form.cleaned_data["name"], site=self
)
messages.add_message(
request,
messages.SUCCESS,
_("The Folder %s was successfully created.") % form.cleaned_data["name"],
)
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(
query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q,p"
)
return HttpResponseRedirect(redirect_url)
except OSError as e:
errno = e.args[0]
if errno == 13:
form.errors["name"] = forms.util.ErrorList([_("Permission denied.")])
else:
form.errors["name"] = forms.util.ErrorList([_("Error creating folder.")])
else:
form = CreateDirForm(path, filebrowser_site=self)
return render_to_response(
"filebrowser/createdir.html",
{
"form": form,
"query": query,
"title": _(u"New Folder"),
"settings_var": get_settings_var(directory=self.directory),
"breadcrumbs": get_breadcrumbs(query, query.get("dir", "")),
"breadcrumbs_title": _(u"New Folder"),
"filebrowser_site": self,
},
context_instance=Context(request, current_app=self.name),
)
示例4: createdir
def createdir(self, request):
"""
Create Directory.
"""
from filebrowser.forms import CreateDirForm
query = request.GET
abs_path = u"%s" % os.path.join(self.media_root, query.get("dir", ""))
if request.method == "POST":
form = CreateDirForm(abs_path, request.POST)
if form.is_valid():
abs_server_path = os.path.join(abs_path, form.cleaned_data["name"])
try:
self.filebrowser_pre_createdir.send(
sender=request, path=abs_server_path, name=form.cleaned_data["name"]
)
os.mkdir(abs_server_path)
os.chmod(abs_server_path, 0775) # ??? PERMISSIONS
self.filebrowser_post_createdir.send(
sender=request, path=abs_server_path, name=form.cleaned_data["name"]
)
messages.add_message(
request,
messages.SUCCESS,
_("The Folder %s was successfully created.") % form.cleaned_data["name"],
)
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + 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["name"] = forms.util.ErrorList([_("Permission denied.")])
else:
form.errors["name"] = forms.util.ErrorList([_("Error creating folder.")])