Exemple #1
0
def addons_section(request, addon_id, addon, section, editable=False):
    models = {'basic': AddonFormBasic,
              'details': AddonFormDetails,
              'support': AddonFormSupport,
              'technical': AddonFormTechnical}

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

    if editable:
        if request.method == 'POST':
            form = models[section](request.POST, request.FILES,
                                  instance=addon)
            if form.is_valid():
                addon = form.save(addon)
                editable = False

                AddonLog.log(models[section], request, addon=addon,
                             action='edit ' + section)
        else:
            form = models[section](instance=addon)
    else:
        form = False

    tags = addon.tags.not_blacklisted().values_list('tag_text', flat=True)

    data = {'addon': addon,
            'form': form,
            'editable': editable,
            'tags': tags}

    return jingo.render(request,
                        'devhub/includes/addon_edit_%s.html' % section, data)
Exemple #2
0
def profile(request, addon_id, addon):
    profile_form = forms.ProfileForm(request.POST or None, instance=addon)

    if request.method == 'POST' and profile_form.is_valid():
        profile_form.save()
        AddonLog.log(Addon, request, action='profile', form=profile_form)
        return redirect('devhub.addons.profile', addon_id)

    return jingo.render(request, 'devhub/addons/profile.html',
                        dict(addon=addon, profile_form=profile_form))
Exemple #3
0
def ownership(request, addon_id, addon):
    fs = []
    # Authors.
    qs = AddonUser.objects.filter(addon=addon).order_by('position')
    user_form = forms.AuthorFormSet(request.POST or None, queryset=qs)
    fs.append(user_form)
    # License. Clear out initial data if it's a builtin license.
    qs = addon.versions.order_by('-version')[:1]
    version = qs[0] if qs else None
    if version:
        instance, initial = version.license, None
        if getattr(instance, 'builtin', None):
            instance, initial = None, {'builtin': instance.builtin}
        license_form = forms.LicenseForm(request.POST or None, initial=initial,
                                         instance=instance)
        fs.append(license_form)
    # Policy.
    policy_form = forms.PolicyForm(
        request.POST or None, instance=addon,
        initial=dict(has_priv=bool(addon.privacy_policy),
                     has_eula=bool(addon.eula)))
    fs.append(policy_form)

    if request.method == 'POST' and all([form.is_valid() for form in fs]):
        # Authors.
        authors = user_form.save(commit=False)
        for author in authors:
            action = 'change' if author.id else 'add'
            author.addon = addon
            author.save()
            AddonLog.log(AddonUser, request, addon=addon,
                         action=action, author=author)
        # License.
        if version:
            license = license_form.save()
            addon.current_version.update(license=license)
            AddonLog.log(License, request, addon=addon, license=license)
        # Policy.
        policy_form.save(addon=addon)
        AddonLog.log(Addon, request, action='policy', form=policy_form)

        return redirect('devhub.addons.owner', addon_id)

    license_urls = dict(License.objects.builtins()
                        .values_list('builtin', 'url'))
    return jingo.render(request, 'devhub/addons/owner.html',
        dict(addon=addon, user_form=user_form, version=version,
             license_form=version and license_form, license_urls=license_urls,
             policy_form=policy_form, license_other_val=License.OTHER))