Exemplo n.º 1
0
class AppFormDetails(addons.forms.AddonFormBase):
    default_locale = forms.TypedChoiceField(required=False,
                                            choices=Addon.LOCALES)
    homepage = TransField.adapt(forms.URLField)(required=False,
                                                verify_exists=False)
    privacy_policy = TransField(widget=TransTextarea(), required=True,
        label=_lazy(u"Please specify your app's Privacy Policy"))

    class Meta:
        model = Addon
        fields = ('default_locale', 'homepage', 'privacy_policy')

    def clean(self):
        # Make sure we have the required translations in the new locale.
        required = ['name', 'description']
        data = self.cleaned_data
        if not self.errors and 'default_locale' in self.changed_data:
            fields = dict((k, getattr(self.instance, k + '_id'))
                          for k in required)
            locale = data['default_locale']
            ids = filter(None, fields.values())
            qs = (Translation.objects.filter(locale=locale, id__in=ids,
                                             localized_string__isnull=False)
                  .values_list('id', flat=True))
            missing = [k for k, v in fields.items() if v not in qs]
            if missing:
                raise forms.ValidationError(
                    _('Before changing your default locale you must have a '
                      'name and description in that locale. '
                      'You are missing %s.') % ', '.join(map(repr, missing)))
        return data
Exemplo n.º 2
0
class AddonFormSupport(AddonFormBase):
    support_url = TransField.adapt(forms.URLField)(required=False)
    support_email = TransField.adapt(forms.EmailField)(required=False)

    class Meta:
        model = Addon
        fields = ('support_email', 'support_url')

    def __init__(self, *args, **kw):
        super(AddonFormSupport, self).__init__(*args, **kw)
        if self.instance.is_premium():
            self.fields['support_email'].required = True

    def save(self, addon, commit=True):
        instance = self.instance
        url = instance.support_url.localized_string
        return super(AddonFormSupport, self).save(commit)
Exemplo n.º 3
0
class Step3WebappForm(Step3Form):
    """Form to override certain fields for webapps"""
    name = TransField(max_length=128)
    homepage = TransField.adapt(forms.URLField)(required=False)
    support_url = TransField.adapt(forms.URLField)(required=False)
    support_email = TransField.adapt(forms.EmailField)(required=False)
Exemplo n.º 4
0
class AppDetailsBasicForm(TranslationFormMixin, happyforms.ModelForm):
    """Form for "Details" submission step."""

    app_slug = forms.CharField(max_length=30,
                               widget=forms.TextInput(attrs={'class': 'm'}))
    summary = TransField(max_length=1024,
                         label=_lazy(u"Brief Summary:"),
                         help_text=_lazy(
                             u'This summary will be shown in listings and '
                             'searches.'),
                         widget=TransTextarea(attrs={
                             'rows': 2,
                             'class': 'full'
                         }))
    description = TransField(
        required=False,
        label=_lazy(u'Additional Information:'),
        help_text=_lazy(u'This description will appear on the details page.'),
        widget=TransTextarea(attrs={'rows': 4}))
    privacy_policy = TransField(
        widget=TransTextarea(attrs={'rows': 6}),
        label=_lazy(u'Privacy Policy:'),
        help_text=_lazy(u"A privacy policy that explains what "
                        "data is transmitted from a user's computer and how "
                        "it is used is required."))
    homepage = TransField.adapt(forms.URLField)(
        required=False,
        verify_exists=False,
        label=_lazy(u'Homepage:'),
        help_text=_lazy(u'If your app has another homepage, enter its address '
                        'here.'),
        widget=TransInput(attrs={'class': 'full'}))
    support_url = TransField.adapt(forms.URLField)(
        required=False,
        verify_exists=False,
        label=_lazy(u'Support Website:'),
        help_text=_lazy(u'If your app has a support website or forum, enter '
                        'its address here.'),
        widget=TransInput(attrs={'class': 'full'}))
    support_email = TransField.adapt(forms.EmailField)(
        label=_lazy(u'Support Email:'),
        help_text=_lazy(u'The email address used by end users to contact you '
                        'with support issues and refund requests.'),
        widget=TransInput(attrs={'class': 'full'}))
    flash = forms.TypedChoiceField(
        required=False,
        coerce=lambda x: bool(int(x)),
        label=_lazy(u'Does your app require Flash support?'),
        initial=0,
        choices=(
            (1, _lazy(u'Yes')),
            (0, _lazy(u'No')),
        ),
        widget=forms.RadioSelect)
    publish = forms.BooleanField(
        required=False,
        initial=1,
        label=_lazy(u"Publish my app in the Firefox Marketplace as soon as "
                    "it's reviewed."),
        help_text=_lazy(u"If selected your app will be published immediately "
                        "following its approval by reviewers.  If you don't "
                        "select this option you will be notified via email "
                        "about your app's approval and you will need to log "
                        "in and manually publish it."))

    class Meta:
        model = Addon
        fields = ('app_slug', 'summary', 'description', 'privacy_policy',
                  'homepage', 'support_url', 'support_email')

    def __init__(self, *args, **kw):
        self.request = kw.pop('request')
        kw.setdefault('initial', {})

        # Prefill support email.
        locale = self.base_fields['support_email'].default_locale.lower()
        kw['initial']['support_email'] = {locale: self.request.amo_user.email}

        super(AppDetailsBasicForm, self).__init__(*args, **kw)

    def clean_app_slug(self):
        slug = self.cleaned_data['app_slug']
        slug_validator(slug, lower=False)

        if slug != self.instance.app_slug:
            if Webapp.objects.filter(app_slug=slug).exists():
                raise forms.ValidationError(
                    _('This slug is already in use. Please choose another.'))

            if BlacklistedSlug.blocked(slug):
                raise forms.ValidationError(
                    _('The slug cannot be "%s". Please choose another.' %
                      slug))

        return slug

    def save(self, *args, **kw):
        uses_flash = self.cleaned_data.get('flash')
        af = self.instance.get_latest_file()
        if af is not None:
            af.update(uses_flash=bool(uses_flash))

        form = super(AppDetailsBasicForm, self).save(commit=False)
        form.save()

        return form