<commit_before>from django import forms
from django.core import validators
from django.utils.translation import ugettext_lazy as _

from meinberlin.apps.contrib import fields
from meinberlin.apps.contrib import widgets
from meinberlin.apps.contrib.mixins import ContactStorageConsentMixin
from meinberlin.apps.mapideas.forms import MapIdeaForm

from . import models


class ProposalForm(MapIdeaForm, ContactStorageConsentMixin):

    class Meta:
        model = models.Proposal
        fields = ['name', 'description', 'image', 'category',
                  'labels', 'budget', 'point', 'point_label',
                  'allow_contact', 'contact_email', 'contact_phone']
        widgets = {
            'category': widgets.Select2Widget(
                attrs={'class': 'select2__no-search'})
        }
        labels = {
            'allow_contact': _('For questions or in case of implementation '
                               'of my proposal you can contact me.'),
            'contact_phone': _('Telephone number'),
        }

    class Media:
        js = ('budgeting_disable_contact.js',)

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super().__init__(*args, **kwargs)
        choices = [(user.email,
                    _('Please contact me via the e-mail address '
                      'of my user account ({}).').format(user.email)),
                   ('other',
                    _('Please contact me via another e-mail address:'))]

        self.fields['contact_email'] = fields.ChoiceWithOtherOptionField(
            required=False,
            label=_('E-mail address'),
            choices=choices,
            widget=widgets.RadioSelectWithTextInputWidget(
                choices=choices,
                placeholder_textinput='new e-mail address'),
            validators_textinput=[validators.validate_email])

    def clean(self):
        cleaned_data = super().clean()
        allow_contact = cleaned_data.get('allow_contact')
        contact_email = cleaned_data.get('contact_email')
        if allow_contact and not contact_email:
            self.add_error('contact_email',
                           _('Please enter an email address.'))
        return cleaned_data


class ProposalModerateForm(forms.ModelForm):
    class Meta:
        model = models.Proposal
        fields = ['moderator_feedback', 'is_archived']<commit_msg>budgeting/forms: make email placeholder translatable, fixes #3498<commit_after>from django import forms
from django.core import validators
from django.utils.translation import ugettext_lazy as _

from meinberlin.apps.contrib import fields
from meinberlin.apps.contrib import widgets
from meinberlin.apps.contrib.mixins import ContactStorageConsentMixin
from meinberlin.apps.mapideas.forms import MapIdeaForm

from . import models


class ProposalForm(MapIdeaForm, ContactStorageConsentMixin):

    class Meta:
        model = models.Proposal
        fields = ['name', 'description', 'image', 'category',
                  'labels', 'budget', 'point', 'point_label',
                  'allow_contact', 'contact_email', 'contact_phone']
        widgets = {
            'category': widgets.Select2Widget(
                attrs={'class': 'select2__no-search'})
        }
        labels = {
            'allow_contact': _('For questions or in case of implementation '
                               'of my proposal you can contact me.'),
            'contact_phone': _('Telephone number'),
        }

    class Media:
        js = ('budgeting_disable_contact.js',)

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super().__init__(*args, **kwargs)
        choices = [(user.email,
                    _('Please contact me via the e-mail address '
                      'of my user account ({}).').format(user.email)),
                   ('other',
                    _('Please contact me via another e-mail address:'))]

        self.fields['contact_email'] = fields.ChoiceWithOtherOptionField(
            required=False,
            label=_('E-mail address'),
            choices=choices,
            widget=widgets.RadioSelectWithTextInputWidget(
                choices=choices,
                placeholder_textinput=_('new e-mail address')),
            validators_textinput=[validators.validate_email])

    def clean(self):
        cleaned_data = super().clean()
        allow_contact = cleaned_data.get('allow_contact')
        contact_email = cleaned_data.get('contact_email')
        if allow_contact and not contact_email:
            self.add_error('contact_email',
                           _('Please enter an email address.'))
        return cleaned_data


class ProposalModerateForm(forms.ModelForm):
    class Meta:
        model = models.Proposal
        fields = ['moderator_feedback', 'is_archived']
{'fraction_non_alphanumeric': 0.10385328662682877, 'fraction_numerical': 0.00164846486709252, 'mean_word_length': 2.3614958448753463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421072', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1274, 'n_words': 309}