예제 #1
0
파일: forms.py 프로젝트: superduper/zamboni
class AppDetailsBasicForm(AddonFormBasic):
    """Form for "Details" submission step."""
    name = TransField(max_length=128,
                      widget=TransInput(attrs={'class': 'name l'}))
    slug = forms.CharField(max_length=30,
                           widget=forms.TextInput(attrs={'class': 'm'}))
    summary = TransField(max_length=250,
                         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'}))

    class Meta:
        model = Addon
        fields = ('name', 'slug', 'summary', 'tags', 'description',
                  'privacy_policy', 'homepage', 'support_url', 'support_email')
예제 #2
0
파일: forms.py 프로젝트: zzdjk6/zamboni
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