<commit_before># coding: utf8

from flask_wtf import FlaskForm
from wtforms import StringField, ValidationError
from wtforms.validators import DataRequired

from labonneboite.common import mapping as mapping_util
from labonneboite.common.models import Office
from labonneboite.web.admin.forms import siret_validator


class NafForm(FlaskForm):
    """
    Enter a NAF code to find associated ROME codes.
    """
    naf = StringField(u"NAF", validators=[DataRequired()],
        description=u"Saisissez un code NAF pour trouver les codes ROME associés.")

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.
        # The token can be removed safely here because this form is always submitted in GET.
        # See http://goo.gl/QxWXBH for CSRF token with the GET method: server-side actions
        # that have state changing affect should only respond to POST requests.
        csrf = False

    def validate_naf(self, field):
        if field.data and not mapping_util.Rome2NafMapper.naf_is_valid(field.data):
            raise ValidationError(u"Ce code NAF n'est pas valide.")


class RomeForm(FlaskForm):
    """
    Enter a ROME code to find associated NAF codes.
    """
    rome = StringField(u"ROME", validators=[DataRequired()],
        description=u"Saisissez un code ROME pour trouver les codes NAF associés.")

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.
        # The token can be removed safely here because this form is always submitted in GET.
        # See http://goo.gl/QxWXBH for CSRF token with the GET method: server-side actions
        # that have state changing affect should only respond to POST requests.
        csrf = False

    def validate_rome(self, field):
        if field.data and not mapping_util.Rome2NafMapper.romes_is_valid(field.data):
            raise ValidationError(u"Ce code ROME n'est pas valide.")


class SiretForm(FlaskForm):
    """
    Enter a SIRET to find associated ROME codes.
    """
    siret = StringField(u"Siret", validators=[DataRequired(), siret_validator],
        description=u"Saisissez un SIRET pour trouver les codes ROME associés.")

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.<commit_msg>Uppercase user input in data forms<commit_after># coding: utf8

from flask_wtf import FlaskForm
from wtforms import StringField, ValidationError
from wtforms.validators import DataRequired

from labonneboite.common import mapping as mapping_util
from labonneboite.common.models import Office
from labonneboite.web.admin.forms import siret_validator


def upper_filter(value):
    """
    Uppercase user input.
    """
    if value is not None and hasattr(value, 'upper'):
        return value.upper()
    return value


class NafForm(FlaskForm):
    """
    Enter a NAF code to find associated ROME codes.
    """
    naf = StringField(u"NAF", validators=[DataRequired()],
        description=u"Saisissez un code NAF pour trouver les codes ROME associés.", filters=[upper_filter])

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.
        # The token can be removed safely here because this form is always submitted in GET.
        # See http://goo.gl/QxWXBH for CSRF token with the GET method: server-side actions
        # that have state changing affect should only respond to POST requests.
        csrf = False

    def validate_naf(self, field):
        if field.data and not mapping_util.Rome2NafMapper.naf_is_valid(field.data):
            raise ValidationError(u"Ce code NAF n'est pas valide.")


class RomeForm(FlaskForm):
    """
    Enter a ROME code to find associated NAF codes.
    """
    rome = StringField(u"ROME", validators=[DataRequired()],
        description=u"Saisissez un code ROME pour trouver les codes NAF associés.", filters=[upper_filter])

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.
        # The token can be removed safely here because this form is always submitted in GET.
        # See http://goo.gl/QxWXBH for CSRF token with the GET method: server-side actions
        # that have state changing affect should only respond to POST requests.
        csrf = False

    def validate_rome(self, field):
        if field.data and not mapping_util.Rome2NafMapper.romes_is_valid(field.data):
            raise ValidationError(u"Ce code ROME n'est pas valide.")


class SiretForm(FlaskForm):
    """
    Enter a SIRET to find associated ROME codes.
    """
    siret = StringField(u"Siret", validators=[DataRequired(), siret_validator],
        description=u"Saisissez un SIRET pour trouver les codes ROME associés.")

    class Meta:
        # CSRF validation is enabled globally but we don't want the CSRF token
        # to be included in this form.
{'fraction_non_alphanumeric': 0.0711189913317573, 'fraction_numerical': 0.001182033096926714, 'mean_word_length': 3.110931174089069, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7634661', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1428, 'n_words': 561}