Пример #1
0
 def test_no_possible_categories(self):
     Category.objects.create(type=amo.ADDON_SEARCH,
                             application_id=amo.FIREFOX.id)
     addon = Addon.objects.create(type=amo.ADDON_SEARCH)
     form = forms.CategoryFormSet(addon=addon)
     apps = [f.app for f in form.forms]
     eq_(apps, [amo.FIREFOX])
Пример #2
0
def submit_describe(request, addon_id, addon, step):
    form = forms.Step3Form(request.POST or None, instance=addon,
                           request=request)
    cat_form = addon_forms.CategoryFormSet(request.POST or None, addon=addon)
    if request.method == 'POST' and form.is_valid() and cat_form.is_valid():
        addon = form.save(addon)
        cat_form.save()
        SubmitStep.objects.filter(addon=addon).update(step=4)
        return redirect('devhub.submit.4', addon.slug)
    return jingo.render(request, 'devhub/addons/submit/describe.html',
                        {'form': form, 'cat_form': cat_form, 'addon': addon,
                         'step': step})
Пример #3
0
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 = None

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

    elif section == 'media':
        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')):
        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()):

                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
    }

    return jingo.render(request, 'developers/apps/edit/%s.html' % section,
                        data)
Пример #4
0
def addons_section(request, addon_id, addon, section, editable=False):
    models = {'basic': addon_forms.AddonFormBasic,
              'media': addon_forms.AddonFormMedia,
              'details': addon_forms.AddonFormDetails,
              'support': addon_forms.AddonFormSupport,
              'technical': addon_forms.AddonFormTechnical,
              'admin': forms.AdminForm,
    }

    if section not in models:
        return http.HttpResponseNotFound()

    tags = previews = restricted_tags = []
    cat_form = None

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

    elif section == 'media':
        previews = forms.PreviewFormSet(request.POST or None,
                prefix='files', queryset=addon.previews.all())

    # Get the slug before the form alters it to the form data.
    valid_slug = addon.slug
    if editable:
        if request.method == 'POST':
            form = models[section](request.POST, request.FILES,
                                  instance=addon, request=request)
            if (form.is_valid() and (not previews or previews.is_valid()) and
                (section != 'basic' or (cat_form and cat_form.is_valid()))):
                addon = form.save(addon)

                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)

                if cat_form:
                    cat_form.save()

                valid_slug = addon.slug
        else:
            form = models[section](instance=addon, request=request)
    else:
        form = False

    data = {'addon': addon,
            'form': form,
            'editable': editable,
            'tags': tags,
            'restricted_tags': restricted_tags,
            'cat_form': cat_form,
            'preview_form': previews,
            'valid_slug': valid_slug,
            }

    return jingo.render(request,
                        'devhub/addons/edit/%s.html' % section, data)