<commit_before># This file is part of Indico.
# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from flask import current_app
from wtforms import ValidationError

from indico.modules.events.registration.models.form_fields import (RegistrationFormPersonalDataField,
                                                                   RegistrationFormFieldData)
from indico.modules.events.registration.models.forms import RegistrationForm
from indico.modules.events.registration.models.items import (RegistrationFormPersonalDataSection,
                                                             RegistrationFormItemType, PersonalDataType)
from indico.modules.events.registration.models.registrations import Registration
from indico.web.forms.base import IndicoForm


def user_registered_in_event(user, event):
    """Check whether there is a ``Registration`` entry
       for a user in any form tied to a particular event

       :param user: the ``User`` object
       :param event: the ``Event`` in question
    """
    return bool(Registration.find(Registration.user == user,
                                  RegistrationForm.event_id == event.id,
                                  ~Registration.is_cancelled)
                            .join(RegistrationForm, Registration.registration_form_id == RegistrationForm.id).count())


def get_event_section_data(regform, management=False):
    return [s.view_data for s in regform.sections if not s.is_deleted and (management or not s.is_manager_only)]


def make_registration_form(regform, management=False):
    """Creates a WTForm based on registration form fields"""

    class RegistrationFormWTF(IndicoForm):<commit_msg>Fix join and docstring of user_registered_in_event<commit_after># This file is part of Indico.
# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from flask import current_app
from wtforms import ValidationError

from indico.modules.events.registration.models.form_fields import (RegistrationFormPersonalDataField,
                                                                   RegistrationFormFieldData)
from indico.modules.events.registration.models.forms import RegistrationForm
from indico.modules.events.registration.models.items import (RegistrationFormPersonalDataSection,
                                                             RegistrationFormItemType, PersonalDataType)
from indico.modules.events.registration.models.registrations import Registration
from indico.web.forms.base import IndicoForm


def user_registered_in_event(user, event):
    """
    Check whether there is a `Registration` entry for a user in any
    form tied to a particular event.

    :param user: the `User` object
    :param event: the event in question
    """
    return bool(Registration
                .find(Registration.user == user,
                      RegistrationForm.event_id == int(event.id),
                      ~Registration.is_cancelled)
                .join(Registration.registration_form)
                .count())


def get_event_section_data(regform, management=False):
    return [s.view_data for s in regform.sections if not s.is_deleted and (management or not s.is_manager_only)]


def make_registration_form(regform, management=False):
    """Creates a WTForm based on registration form fields"""

    class RegistrationFormWTF(IndicoForm):
{'fraction_non_alphanumeric': 0.06513897729683853, 'fraction_numerical': 0.0038192234245703373, 'mean_word_length': 3.1606354810238306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4658005', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1109, 'n_words': 442}