class _Form(TranslationFormMixin, happyforms.ModelForm): the_reason = TransField(widget=TransTextarea(), required=fields_required, label=the_reason_label) the_future = TransField(widget=TransTextarea(), required=fields_required, label=the_future_label) class Meta: model = Addon fields = ('the_reason', 'the_future')
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')
class AppFormDetails(addons.forms.AddonFormBase): default_locale = forms.TypedChoiceField(required=False, choices=Addon.LOCALES) homepage = TransField.adapt(forms.URLField)(required=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
class AppVersionForm(happyforms.ModelForm): releasenotes = TransField(widget=TransTextarea(), required=False) approvalnotes = forms.CharField( widget=TranslationTextarea(attrs={'rows': 4}), required=False) publish_immediately = forms.BooleanField(required=False) class Meta: model = Version fields = ('releasenotes', 'approvalnotes') def __init__(self, *args, **kwargs): super(AppVersionForm, self).__init__(*args, **kwargs) self.fields['publish_immediately'].initial = ( self.instance.addon.make_public == amo.PUBLIC_IMMEDIATELY) def save(self, *args, **kwargs): rval = super(AppVersionForm, self).save(*args, **kwargs) if self.instance.all_files[0].status == amo.STATUS_PENDING: # If version is pending, allow changes to make_public, which lives # on the app itself. if self.cleaned_data.get('publish_immediately'): make_public = amo.PUBLIC_IMMEDIATELY else: make_public = amo.PUBLIC_WAIT self.instance.addon.update(make_public=make_public) return rval
class AppFormDetails(addons.forms.AddonFormBase): description = TransField(required=False, label=_(u'Provide a more detailed description of your app'), help_text=_(u'This description will appear on the details page.'), widget=TransTextarea) 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 = ('description', 'default_locale', 'homepage', 'privacy_policy') def clean(self): # Make sure we have the required translations in the new locale. required = 'name', 'summary', '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 = self.cleaned_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] # They might be setting description right now. if 'description' in missing and locale in data['description']: missing.remove('description') if missing: raise forms.ValidationError( _('Before changing your default locale you must have a ' 'name, summary, and description in that locale. ' 'You are missing %s.') % ', '.join(map(repr, missing))) return data
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
class AppFormBasic(addons.forms.AddonFormBase): """Form to edit basic app info.""" name = TransField(max_length=128, widget=TransInput) slug = forms.CharField(max_length=30, widget=forms.TextInput) manifest_url = forms.URLField(verify_exists=False) summary = TransField(widget=TransTextarea(attrs={'rows': 4}), max_length=250) class Meta: model = Addon fields = ('name', 'slug', 'manifest_url', 'summary') def __init__(self, *args, **kw): # Force the form to use app_slug if this is a webapp. We want to keep # this under "slug" so all the js continues to work. if kw['instance'].is_webapp(): kw.setdefault('initial', {})['slug'] = kw['instance'].app_slug super(AppFormBasic, self).__init__(*args, **kw) # Do not simply append validators, as validators will persist between # instances. validate_name = lambda x: clean_name(x, self.instance) name_validators = list(self.fields['name'].validators) name_validators.append(validate_name) self.fields['name'].validators = name_validators def _post_clean(self): # Switch slug to app_slug in cleaned_data and self._meta.fields so # we can update the app_slug field for webapps. try: self._meta.fields = list(self._meta.fields) slug_idx = self._meta.fields.index('slug') data = self.cleaned_data if 'slug' in data: data['app_slug'] = data.pop('slug') self._meta.fields[slug_idx] = 'app_slug' super(AppFormBasic, self)._post_clean() finally: self._meta.fields[slug_idx] = 'slug' def clean_slug(self): target = self.cleaned_data['slug'] slug_validator(target, lower=False) slug_field = 'app_slug' if self.instance.is_webapp() else 'slug' if target != getattr(self.instance, slug_field): if Addon.objects.filter(**{slug_field: target}).exists(): raise forms.ValidationError(_('This slug is already in use.')) if BlacklistedSlug.blocked(target): raise forms.ValidationError(_('The slug cannot be: %s.' % target)) return target def clean_manifest_url(self): manifest_url = self.cleaned_data['manifest_url'] # Only verify if manifest changed. if 'manifest_url' in self.changed_data: # Only Admins can edit the manifest_url. if not acl.action_allowed(self.request, 'Admin', '%'): return self.instance.manifest_url verify_app_domain(manifest_url, exclude=self.instance) return manifest_url def save(self, addon, commit=False): # We ignore `commit`, since we need it to be `False` so we can save # the ManyToMany fields on our own. addonform = super(AppFormBasic, self).save(commit=False) addonform.save() return addonform
class AppFormBasic(addons.forms.AddonFormBase): """Form to edit basic app info.""" slug = forms.CharField(max_length=30, widget=forms.TextInput) manifest_url = forms.URLField(verify_exists=False) summary = TransField(widget=TransTextarea(attrs={'rows': 4}), max_length=1024) class Meta: model = Addon fields = ('slug', 'manifest_url', 'summary') def __init__(self, *args, **kw): # Force the form to use app_slug if this is a webapp. We want to keep # this under "slug" so all the js continues to work. if kw['instance'].is_webapp(): kw.setdefault('initial', {})['slug'] = kw['instance'].app_slug super(AppFormBasic, self).__init__(*args, **kw) def _post_clean(self): # Switch slug to app_slug in cleaned_data and self._meta.fields so # we can update the app_slug field for webapps. try: self._meta.fields = list(self._meta.fields) slug_idx = self._meta.fields.index('slug') data = self.cleaned_data if 'slug' in data: data['app_slug'] = data.pop('slug') self._meta.fields[slug_idx] = 'app_slug' super(AppFormBasic, self)._post_clean() finally: self._meta.fields[slug_idx] = 'slug' def clean_slug(self): slug = self.cleaned_data['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 clean_manifest_url(self): manifest_url = self.cleaned_data['manifest_url'] # Only verify if manifest changed. if 'manifest_url' in self.changed_data: # Only Admins can edit the manifest_url. if not acl.action_allowed(self.request, 'Admin', '%'): return self.instance.manifest_url verify_app_domain(manifest_url, exclude=self.instance) return manifest_url def save(self, addon, commit=False): # We ignore `commit`, since we need it to be `False` so we can save # the ManyToMany fields on our own. addonform = super(AppFormBasic, self).save(commit=False) addonform.save() return addonform