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


Python MakeDirForm.is_valid方法代码示例

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


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

示例1: mkdir

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
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.')])
开发者ID:callowayproject,项目名称:django-filebrowser,代码行数:28,代码来源:views.py

示例2: mkdir

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
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.')])
开发者ID:nailor,项目名称:asteriski-www,代码行数:36,代码来源:views.py

示例3: mkdir

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
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))
开发者ID:YDS19872712,项目名称:django-filebrowser-no-grappelli,代码行数:55,代码来源:views.py

示例4: test_make_dir_form

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
    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'))
开发者ID:miguelramos,项目名称:django-media-manager,代码行数:26,代码来源:test_forms.py

示例5: mkdir

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
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.')])
开发者ID:oppian,项目名称:oppian,代码行数:46,代码来源:views.py

示例6: mkdir

# 需要导入模块: from filebrowser.forms import MakeDirForm [as 别名]
# 或者: from filebrowser.forms.MakeDirForm import is_valid [as 别名]
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.")])
开发者ID:pavelm2007,项目名称:django-filebrowser-no-grappelli,代码行数:45,代码来源:views.py


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