<commit_before># -*- coding: utf-8 -*-
"CallMeBack forms"

from flask import session
from flask.ext.babel import lazy_gettext as _
from flask_wtf import Form
from wtforms import Form as NoCsrfForm
from wtforms import BooleanField, FormField, RadioField, SelectField, \
    StringField, TextAreaField
from wtforms.validators import InputRequired, Optional, Length

from cla_common.constants import ADAPTATION_LANGUAGES
from cla_public.apps.callmeback.fields import AvailabilityCheckerField
from cla_public.apps.checker.constants import CONTACT_SAFETY
from cla_public.apps.base.forms import BabelTranslationsFormMixin
from cla_public.apps.checker.validators import NotRequired
from cla_public.libs.honeypot import Honeypot


LANG_CHOICES = filter(
    lambda x: x[0] not in ('ENGLISH', 'WELSH'),
    [('', _('-- Choose a language --'))] + ADAPTATION_LANGUAGES)


class AdaptationsForm(BabelTranslationsFormMixin, NoCsrfForm):
    """
    Subform for adaptations
    """
    bsl_webcam = BooleanField(_(u'BSL - Webcam'))
    minicom = BooleanField(_(u'Minicom'))
    text_relay = BooleanField(_(u'Text Relay'))
    welsh = BooleanField(_(u'Welsh'))
    is_other_language = BooleanField(_(u'Other language'))
    other_language = SelectField(
        _(u'Language required:'),
        choices=(LANG_CHOICES))
    is_other_adaptation = BooleanField(_(u'Any other communication needs'))
    other_adaptation = TextAreaField(
        _(u'Other communication needs'),
        description=_(u'Please tell us what you need in the box below'))


class CallMeBackForm(Honeypot, BabelTranslationsFormMixin, Form):
    """
    Form to request a callback
    """
    full_name = StringField(
        _(u'Full name'),
        description=_(u'For example: <NAME>'),
        validators=[InputRequired()])
    contact_number = StringField(
        _(u'Contact phone number'),
        validators=[
            Length(max=20, message=_(u'Your telephone number must be 20 '
                                     u'characters or less')),
            InputRequired()])
    safe_to_contact = RadioField(
        _(u'Is it safe for us to leave a message on this number?'),
        choices=CONTACT_SAFETY,
        validators=[
            InputRequired(message=_(u'Please choose Yes or No'))],
    )
    post_code = StringField(_(u'Postcode'))
    address = TextAreaField(_(u'Address'))
    extra_notes = TextAreaField(
        _(u'Help the operator to understand your situation'),
        description=(_(
            u"If you’d like to tell us more about your problem, please do so "
            u"in the box below. The Civil Legal Advice operator will read "
            u"this before they call you.")),
        validators=[NotRequired()])
    adaptations = FormField(
        AdaptationsForm,
        _(u'Do you have any special communication needs?'))

    time = AvailabilityCheckerField(
        _(u'Select a time for us to call you'),
        description=_(u'We will try to call you back around the time you '
                      u'request, but this may not always be possible. We will '
                      u'always call you back by the next working day.'))

    def validate(self):
        """
        Put the callback time into the session on success
        """
        valid = super(CallMeBackForm, self).validate()
        if valid:
            session['time_to_callback'] = self.time.scheduled_time()
        return valid
<commit_msg>validation on call me back fields<commit_after># -*- coding: utf-8 -*-
"CallMeBack forms"

from flask import session
from flask.ext.babel import lazy_gettext as _
from flask_wtf import Form
from wtforms import Form as NoCsrfForm
from wtforms import BooleanField, FormField, RadioField, SelectField, \
    StringField, TextAreaField
from wtforms.validators import InputRequired, Optional, Length

from cla_common.constants import ADAPTATION_LANGUAGES
from cla_public.apps.callmeback.fields import AvailabilityCheckerField
from cla_public.apps.checker.constants import CONTACT_SAFETY
from cla_public.apps.base.forms import BabelTranslationsFormMixin
from cla_public.apps.checker.validators import NotRequired
from cla_public.libs.honeypot import Honeypot


LANG_CHOICES = filter(
    lambda x: x[0] not in ('ENGLISH', 'WELSH'),
    [('', _('-- Choose a language --'))] + ADAPTATION_LANGUAGES)


class AdaptationsForm(BabelTranslationsFormMixin, NoCsrfForm):
    """
    Subform for adaptations
    """
    bsl_webcam = BooleanField(_(u'BSL - Webcam'))
    minicom = BooleanField(_(u'Minicom'))
    text_relay = BooleanField(_(u'Text Relay'))
    welsh = BooleanField(_(u'Welsh'))
    is_other_language = BooleanField(_(u'Other language'))
    other_language = SelectField(
        _(u'Language required:'),
        choices=(LANG_CHOICES))
    is_other_adaptation = BooleanField(_(u'Any other communication needs'))
    other_adaptation = TextAreaField(
        _(u'Other communication needs'),
        description=_(u'Please tell us what you need in the box below'))


class CallMeBackForm(Honeypot, BabelTranslationsFormMixin, Form):
    """
    Form to request a callback
    """
    full_name = StringField(
        _(u'Full name'),
        description=_(u'For example: <NAME>'),
        validators=[
            Length(max=400, message=_(u'Your full name must be 400 '
                                      u'characters or less')),
            InputRequired()])
    contact_number = StringField(
        _(u'Contact phone number'),
        validators=[
            Length(max=20, message=_(u'Your telephone number must be 20 '
                                     u'characters or less')),
            InputRequired()])
    safe_to_contact = RadioField(
        _(u'Is it safe for us to leave a message on this number?'),
        choices=CONTACT_SAFETY,
        validators=[
            InputRequired(message=_(u'Please choose Yes or No'))],
    )
    post_code = StringField(
        _(u'Postcode'),
        validators=[
            Length(max=12, message=_(u'Your postcode must be 12 characters '
                                     u'or less')),
            InputRequired()])
    address = TextAreaField(
        _(u'Address'),
        validators=[
            Length(max=255, message=_(u'Your address must be 255 characters '
                                      u'or less')),
            InputRequired()])
    extra_notes = TextAreaField(
        _(u'Help the operator to understand your situation'),
        description=(_(
            u"If you’d like to tell us more about your problem, please do so "
            u"in the box below. The Civil Legal Advice operator will read "
            u"this before they call you.")),
        validators=[
            Length(max=5000, message=_(u'Your notes must be 5000 characters '
                                       u'or less')),
            NotRequired()])
    adaptations = FormField(
        AdaptationsForm,
        _(u'Do you have any special communication needs?'))

    time = AvailabilityCheckerField(
        _(u'Select a time for us to call you'),
        description=_(u'We will try to call you back around the time you '
                      u'request, but this may not always be possible. We will '
                      u'always call you back by the next working day.'))

    def validate(self):
        """
        Put the callback time into the session on success
        """
        valid = super(CallMeBackForm, self).validate()
        if valid:
            session['time_to_callback'] = self.time.scheduled_time()
        return valid

{'fraction_non_alphanumeric': 0.09449236894492369, 'fraction_numerical': 0.004777704047777041, 'mean_word_length': 2.7104874446085674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5918507', 'n_tokens_mistral': 2171, 'n_tokens_neox': 2086, 'n_words': 628}