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


Python CategoryForm.is_valid方法代码示例

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


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

示例1: addons_section

# 需要导入模块: from mkt.developers.forms import CategoryForm [as 别名]
# 或者: from mkt.developers.forms.CategoryForm import is_valid [as 别名]
def addons_section(request, addon_id, addon, section, editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {'basic': basic,
              'media': AppFormMedia,
              'details': AppFormDetails,
              'support': AppFormSupport,
              'technical': AppFormTechnical,
              'admin': forms.AdminSettingsForm}

    is_dev = acl.check_addon_ownership(request, addon, dev=True)

    if section not in models:
        raise http.Http404()

    # Only show the list of features if app isn't packaged.
    show_features = waffle.switch_is_active('buchets') and not addon.is_packaged
    appfeatures = appfeatures_form = None
    if show_features:
        appfeatures = addon.current_version.features
        appfeatures_form = AppFeaturesForm(instance=appfeatures)

    tags = image_assets = previews = restricted_tags = []
    cat_form = None

    # Permissions checks.
    # Only app owners can edit any of the details of their apps.
    # Users with 'Apps:Configure' can edit the admin settings.
    if (section != 'admin' and not is_dev) or (section == 'admin' and
          not acl.action_allowed(request, 'Apps', 'Configure') and
          not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    if section == 'basic':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        cat_form = CategoryForm(request.POST or None, product=addon,
                                request=request)
        restricted_tags = addon.tags.filter(restricted=True)

    elif section == 'media':
        image_assets = ImageAssetFormSet(
            request.POST or None, prefix='images', app=addon)
        previews = PreviewFormSet(
            request.POST or None, prefix='files',
            queryset=addon.get_previews())

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if show_features:
                appfeatures_form = AppFeaturesForm(request.POST,
                                                   instance=appfeatures)

            if (section == 'admin' and
                not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST, request.FILES,
                                   instance=addon, request=request)

            all_forms = [form, previews, image_assets]
            if show_features:
                all_forms.append(appfeatures_form)
            if all(not f or f.is_valid() for f in all_forms):

                addon = form.save(addon)

                if show_features:
                    appfeatures_form.save()

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                if image_assets:
                    image_assets.save()

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
#.........这里部分代码省略.........
开发者ID:KryDos,项目名称:zamboni,代码行数:103,代码来源:views.py

示例2: addons_section

# 需要导入模块: from mkt.developers.forms import CategoryForm [as 别名]
# 或者: from mkt.developers.forms.CategoryForm import is_valid [as 别名]
def addons_section(request, addon_id, addon, section, editable=False,
                   webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {'basic': basic,
              'media': AppFormMedia,
              'details': AppFormDetails,
              'support': AppFormSupport,
              'technical': AppFormTechnical,
              'admin': forms.AdminSettingsForm}

    if section not in models:
        raise http.Http404()

    tags = image_assets = previews = restricted_tags = []
    cat_form = None

    if section == 'basic':
        tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)
        cat_form = CategoryForm(request.POST or None, product=addon,
                                request=request)
        restricted_tags = addon.tags.filter(restricted=True)

    elif section == 'media':
        image_assets = ImageAssetFormSet(
            request.POST or None, prefix='images', app=addon)
        previews = PreviewFormSet(
            request.POST or None, prefix='files',
            queryset=addon.get_previews())

    elif (section == 'admin' and
          not acl.action_allowed(request, 'Apps', 'Configure') and
          not acl.action_allowed(request, 'Apps', 'ViewConfiguration')):
        raise PermissionDenied

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == 'POST':

            if (section == 'admin' and
                not acl.action_allowed(request, 'Apps', 'Configure')):
                raise PermissionDenied

            form = models[section](request.POST, request.FILES,
                                   instance=addon, request=request)
            if (form.is_valid()
                and (not previews or previews.is_valid())
                and (not image_assets or image_assets.is_valid())):

                addon = form.save(addon)

                if 'manifest_url' in form.changed_data:
                    addon.update(
                        app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                if image_assets:
                    image_assets.save()

                editable = False
                if section == 'media':
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {'addon': addon,
            'webapp': webapp,
            'form': form,
            'editable': editable,
            'tags': tags,
            'restricted_tags': restricted_tags,
            'image_sizes': APP_IMAGE_SIZES,
            'cat_form': cat_form,
            'preview_form': previews,
            'image_asset_form': image_assets,
            'valid_slug': valid_slug, }

    return jingo.render(request,
                        'developers/apps/edit/%s.html' % section, data)
开发者ID:bearstech,项目名称:zamboni,代码行数:97,代码来源:views.py

示例3: addons_section

# 需要导入模块: from mkt.developers.forms import CategoryForm [as 别名]
# 或者: from mkt.developers.forms.CategoryForm import is_valid [as 别名]
def addons_section(request, addon_id, addon, section, editable=False, webapp=False):
    basic = AppFormBasic if webapp else addon_forms.AddonFormBasic
    models = {
        "basic": basic,
        "media": AppFormMedia,
        "details": AppFormDetails,
        "support": AppFormSupport,
        "technical": addon_forms.AddonFormTechnical,
        "admin": forms.AdminSettingsForm,
    }

    if section not in models:
        raise http.Http404()

    tags = previews = restricted_tags = []
    cat_form = device_type_form = region_form = None

    if section == "basic":
        tags = addon.tags.not_blacklisted().values_list("tag_text", flat=True)
        cat_form = CategoryForm(request.POST or None, product=addon, request=request)
        restricted_tags = addon.tags.filter(restricted=True)
        device_type_form = DeviceTypeForm(request.POST or None, addon=addon)

    elif section == "media":
        previews = PreviewFormSet(request.POST or None, prefix="files", queryset=addon.get_previews())

    elif section == "details" and settings.REGION_STORES:
        region_form = RegionForm(request.POST or None, product=addon)

    elif (
        section == "admin"
        and not acl.action_allowed(request, "Apps", "Configure")
        and not acl.action_allowed(request, "Apps", "ViewConfiguration")
    ):
        return http.HttpResponseForbidden()

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.app_slug
    if editable:
        if request.method == "POST":

            if section == "admin" and not acl.action_allowed(request, "Apps", "Configure"):
                return http.HttpResponseForbidden()

            form = models[section](request.POST, request.FILES, instance=addon, request=request)
            if (
                form.is_valid()
                and (not previews or previews.is_valid())
                and (not region_form or region_form.is_valid())
            ):

                if region_form:
                    region_form.save()

                addon = form.save(addon)

                if "manifest_url" in form.changed_data:
                    addon.update(app_domain=addon.domain_from_url(addon.manifest_url))
                    update_manifests([addon.pk])

                if previews:
                    for preview in previews.forms:
                        preview.save(addon)

                editable = False
                if section == "media":
                    amo.log(amo.LOG.CHANGE_ICON, addon)
                else:
                    amo.log(amo.LOG.EDIT_PROPERTIES, addon)

                valid_slug = addon.app_slug
            if cat_form:
                if cat_form.is_valid():
                    cat_form.save()
                    addon.save()
                else:
                    editable = True
            if device_type_form:
                if device_type_form.is_valid():
                    device_type_form.save(addon)
                    addon.save()
                else:
                    editable = True
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {
        "addon": addon,
        "webapp": webapp,
        "form": form,
        "editable": editable,
        "tags": tags,
        "restricted_tags": restricted_tags,
        "cat_form": cat_form,
        "preview_form": previews,
        "valid_slug": valid_slug,
        "device_type_form": device_type_form,
        "region_form": region_form,
#.........这里部分代码省略.........
开发者ID:dbialer,项目名称:zamboni,代码行数:103,代码来源:views.py


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