class AppFormSupport(AppSupportFormMixin, AddonFormBase): support_url = TransField.adapt(forms.URLField)(required=False) support_email = TransField.adapt(forms.EmailField)(required=False) class Meta: model = Webapp fields = ('support_email', 'support_url')
class AppFormDetails(AddonFormBase): LOCALES = [(translation.to_locale(k).replace('_', '-'), v) for k, v in do_dictsort(settings.LANGUAGES)] default_locale = forms.TypedChoiceField(required=False, choices=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 = Webapp 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 AppDetailsBasicForm(TranslationFormMixin, happyforms.ModelForm): """Form for "Details" submission step.""" PRIVACY_MDN_URL = ('https://developer.mozilla.org/Marketplace/' 'Publishing/Policies_and_Guidelines/Privacy_policies') PUBLISH_CHOICES = ( (amo.PUBLISH_IMMEDIATE, _lazy(u'Publish my app and make it visible to everyone in the ' u'Marketplace and include it in search results.')), (amo.PUBLISH_PRIVATE, _lazy(u'Do not publish my app. Notify me and I will adjust app ' u'visibility after it is approved.')), ) app_slug = forms.CharField(max_length=30, widget=forms.TextInput(attrs={'class': 'm'})) description = TransField( label=_lazy(u'Description:'), help_text=_lazy(u'This description will appear on the details page.'), widget=TransTextarea(attrs={'rows': 4})) privacy_policy = TransField( label=_lazy(u'Privacy Policy:'), widget=TransTextarea(attrs={'rows': 6}), help_text=_lazy( u'A privacy policy explains how you handle data received ' u'through your app. For example: what data do you receive? ' u'How do you use it? Who do you share it with? Do you ' u'receive personal information? Do you take steps to make ' u'it anonymous? What choices do users have to control what ' u'data you and others receive? Enter your privacy policy ' u'link or text above. If you don\'t have a privacy ' u'policy, <a href="{url}" target="_blank">learn more on how to ' u'write one.</a>')) homepage = TransField.adapt(forms.URLField)( label=_lazy(u'Homepage:'), required=False, widget=TransInput(attrs={'class': 'full'}), help_text=_lazy( u'If your app has another homepage, enter its address here.')) support_url = TransField.adapt(forms.URLField)( label=_lazy(u'Support Website:'), required=False, widget=TransInput(attrs={'class': 'full'}), help_text=_lazy( u'If your app has a support website or forum, enter its address ' u'here.')) support_email = TransField.adapt(forms.EmailField)( label=_lazy(u'Support Email:'), widget=TransInput(attrs={'class': 'full'}), help_text=_lazy( u'This email address will be listed publicly on the Marketplace ' u'and used by end users to contact you with support issues. This ' u'email address will be listed publicly on your app details page.') ) flash = forms.TypedChoiceField( label=_lazy(u'Does your app require Flash support?'), required=False, coerce=lambda x: bool(int(x)), initial=0, widget=forms.RadioSelect, choices=((1, _lazy(u'Yes')), (0, _lazy(u'No')))) notes = forms.CharField( label=_lazy(u'Your comments for reviewers'), required=False, widget=forms.Textarea(attrs={'rows': 2}), help_text=_lazy( u'Your app will be reviewed by Mozilla before it becomes publicly ' u'listed on the Marketplace. Enter any special instructions for ' u'the app reviewers here.')) publish_type = forms.TypedChoiceField( label=_lazy(u'Once your app is approved, choose a publishing option:'), choices=PUBLISH_CHOICES, initial=amo.PUBLISH_IMMEDIATE, widget=forms.RadioSelect()) class Meta: model = Webapp fields = ('app_slug', 'description', 'privacy_policy', 'homepage', 'support_url', 'support_email', 'publish_type') def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') # TODO: remove this and put it in the field definition above. # See https://bugzilla.mozilla.org/show_bug.cgi?id=1072513 privacy_field = self.base_fields['privacy_policy'] privacy_field.help_text = mark_safe( privacy_field.help_text.format(url=self.PRIVACY_MDN_URL)) super(AppDetailsBasicForm, self).__init__(*args, **kwargs) 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.lower() def save(self, *args, **kw): if self.data['notes']: create_comm_note(self.instance, self.instance.versions.latest(), self.request.user, self.data['notes'], note_type=comm.SUBMISSION) self.instance = super(AppDetailsBasicForm, self).save(commit=True) 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)) return self.instance