<commit_before># This file is part of Indico.
# Copyright (C) 2002 - 2017 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

import itertools
from collections import OrderedDict, defaultdict

from flask import flash, redirect, request, session
from sqlalchemy.orm import contains_eager, joinedload

from indico.core.db import db
from indico.core.db.sqlalchemy.principals import PrincipalType
from indico.core.notifications import make_email, send_email
from indico.modules.events import EventLogKind, EventLogRealm
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.principals import ContributionPrincipal
from indico.modules.events.management.controllers import RHManageEventBase
from indico.modules.events.models.persons import EventPerson
from indico.modules.events.models.principals import EventPrincipal
from indico.modules.events.persons.forms import EmailEventPersonsForm, EventPersonForm
from indico.modules.events.persons.operations import update_person
from indico.modules.events.persons.views import WPManagePersons
from indico.modules.events.registration.models.registrations import Registration
from indico.modules.events.sessions.models.principals import SessionPrincipal
from indico.modules.events.sessions.models.sessions import Session
from indico.modules.users import User
from indico.util.date_time import now_utc
from indico.util.i18n import _, ngettext
from indico.util.placeholders import replace_placeholders
from indico.web.flask.templating import get_template_module
from indico.web.flask.util import jsonify_data, url_for
from indico.web.forms.base import FormDefaults
from indico.web.util import jsonify_form, jsonify_template


BUILTIN_ROLES = {'chairperson': {'name': 'Chairperson', 'code': 'CHR', 'color': 'f7b076',
                                 'css': 'background-color: #f7b076 !important; border-color: #f7b076 !important'},
                 'author': {'name': 'Author', 'code': 'AUT', 'color': '6582e8',
                            'css': 'background-color: #6582e8 !important; border-color: #6582e8 !important'},
                 'convener': {'name': 'Convener', 'code': 'CON', 'color': 'ce69e0',
                              'css': 'background-color: #ce69e0 !important; border-color: #ce69e0 !important'},
                 'speaker': {'name': 'Speaker', 'code': 'SPK', 'color': '53c7ad',
                             'css': 'background-color: #53c7ad !important; border-color: #53c7ad !important'}}


class RHPersonsBase(RHManageEventBase):
    def generate_abstracts_data(self, person_link):
        return {'title': person_link.abstract.verbose_title,
                'url': url_for('abstracts.display_abstract', person_link.abstract, management=True)}

    def generate_sessions_data(self, person_link):
        return {'title': person_link.session_block.full_title}

    def generate_contributions_data(self, person_link):
        return {'title': person_link.contribution.title,
                'url': url_for('contributions.manage_contributions', self.event,
                               selected=person_link.contribution.friendly_id)}

    def generate_subcontributions_data(self, person_link):
        return {'title': '{} ({})'.format(person_link.subcontribution.contribution.title,
                                          person_link.subcontribution.title),
                'url': url_for('contributions.manage_contributions', self.event,
                               selected=person_link.subcontribution.friendly_id)}

    def get_persons(self):
        abstract_strategy = joinedload('abstract_links')
        abstract_strategy.joinedload('abstract')
        abstract_strategy.joinedload('person').joinedload('user')
        contribution_strategy = joinedload('contribution_links')
        contribution_strategy.joinedload('contribution')
        contribution_strategy.joinedload('person').joinedload('user')
        subcontribution_strategy = joinedload('subcontribution_links')
        subcontribution_strategy.joinedload('subcontribution')
        subcontribution_strategy.joinedload('person').joinedload('user')
        session_block_strategy = joinedload('session_block_links')
        session_block_strategy.joinedload('session_block')
        session_block_strategy.joinedload('person').joinedload('user')
        event_strategy = joinedload('event_links')
        event_strategy.joinedload('person').joinedload('user')

        chairpersons = {link.person for link in self.event.person_links}
        persons = defaultdict(lambda: {'roles': OrderedDict(), 'registrations': [], 'has_event_person': True})

        event_persons_query = (db.session.query(EventPerson, Registration)
                               .filter(EventPerson.event_id == self.event.id)
                               .outerjoin(Registration, (EventPerson.user_id == Registration.user_id) &
                                                        (Registration.event_id == self.event.id))
                               .options(abstract_strategy,
                                        event_strategy,
                                        contribution_strategy,
                                        subcontribution_strategy,
                                        session_block_strategy)
                               .all())

        event_user_roles = defaultdict(set)
        for event_role in self.event.roles:
            for user in event_role.members:
                event_user_roles[user].add(event_role)
<commit_msg>Associate persons/registrations by email if no uid<commit_after># This file is part of Indico.
# Copyright (C) 2002 - 2017 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

import itertools
from collections import OrderedDict, defaultdict

from flask import flash, redirect, request, session
from sqlalchemy.orm import contains_eager, joinedload

from indico.core.db import db
from indico.core.db.sqlalchemy.principals import PrincipalType
from indico.core.notifications import make_email, send_email
from indico.modules.events import EventLogKind, EventLogRealm
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.principals import ContributionPrincipal
from indico.modules.events.management.controllers import RHManageEventBase
from indico.modules.events.models.persons import EventPerson
from indico.modules.events.models.principals import EventPrincipal
from indico.modules.events.persons.forms import EmailEventPersonsForm, EventPersonForm
from indico.modules.events.persons.operations import update_person
from indico.modules.events.persons.views import WPManagePersons
from indico.modules.events.registration.models.registrations import Registration
from indico.modules.events.sessions.models.principals import SessionPrincipal
from indico.modules.events.sessions.models.sessions import Session
from indico.modules.users import User
from indico.util.date_time import now_utc
from indico.util.i18n import _, ngettext
from indico.util.placeholders import replace_placeholders
from indico.web.flask.templating import get_template_module
from indico.web.flask.util import jsonify_data, url_for
from indico.web.forms.base import FormDefaults
from indico.web.util import jsonify_form, jsonify_template


BUILTIN_ROLES = {'chairperson': {'name': 'Chairperson', 'code': 'CHR', 'color': 'f7b076',
                                 'css': 'background-color: #f7b076 !important; border-color: #f7b076 !important'},
                 'author': {'name': 'Author', 'code': 'AUT', 'color': '6582e8',
                            'css': 'background-color: #6582e8 !important; border-color: #6582e8 !important'},
                 'convener': {'name': 'Convener', 'code': 'CON', 'color': 'ce69e0',
                              'css': 'background-color: #ce69e0 !important; border-color: #ce69e0 !important'},
                 'speaker': {'name': 'Speaker', 'code': 'SPK', 'color': '53c7ad',
                             'css': 'background-color: #53c7ad !important; border-color: #53c7ad !important'}}


class RHPersonsBase(RHManageEventBase):
    def generate_abstracts_data(self, person_link):
        return {'title': person_link.abstract.verbose_title,
                'url': url_for('abstracts.display_abstract', person_link.abstract, management=True)}

    def generate_sessions_data(self, person_link):
        return {'title': person_link.session_block.full_title}

    def generate_contributions_data(self, person_link):
        return {'title': person_link.contribution.title,
                'url': url_for('contributions.manage_contributions', self.event,
                               selected=person_link.contribution.friendly_id)}

    def generate_subcontributions_data(self, person_link):
        return {'title': '{} ({})'.format(person_link.subcontribution.contribution.title,
                                          person_link.subcontribution.title),
                'url': url_for('contributions.manage_contributions', self.event,
                               selected=person_link.subcontribution.friendly_id)}

    def get_persons(self):
        abstract_strategy = joinedload('abstract_links')
        abstract_strategy.joinedload('abstract')
        abstract_strategy.joinedload('person').joinedload('user')
        contribution_strategy = joinedload('contribution_links')
        contribution_strategy.joinedload('contribution')
        contribution_strategy.joinedload('person').joinedload('user')
        subcontribution_strategy = joinedload('subcontribution_links')
        subcontribution_strategy.joinedload('subcontribution')
        subcontribution_strategy.joinedload('person').joinedload('user')
        session_block_strategy = joinedload('session_block_links')
        session_block_strategy.joinedload('session_block')
        session_block_strategy.joinedload('person').joinedload('user')
        event_strategy = joinedload('event_links')
        event_strategy.joinedload('person').joinedload('user')

        chairpersons = {link.person for link in self.event.person_links}
        persons = defaultdict(lambda: {'roles': OrderedDict(), 'registrations': [], 'has_event_person': True})

        _reg_person_join = db.or_((EventPerson.user_id == Registration.user_id),
                                  db.and_(EventPerson.user_id.is_(None),
                                          Registration.user_id.is_(None),
                                          EventPerson.email == Registration.email))
        event_persons_query = (db.session.query(EventPerson, Registration)
                               .filter(EventPerson.event_id == self.event.id)
                               .outerjoin(Registration, (Registration.event_id == self.event.id) & _reg_person_join)
                               .options(abstract_strategy,
                                        event_strategy,
                                        contribution_strategy,
                                        subcontribution_strategy,
                                        session_block_strategy)
                               .all())

        event_user_roles = defaultdict(set)
        for event_role in self.event.roles:
            for user in event_role.members:
                event_user_roles[user].add(event_role)

{'fraction_non_alphanumeric': 0.09308007566204288, 'fraction_numerical': 0.008827238335435058, 'mean_word_length': 3.1251625487646293, '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': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2263645', 'n_tokens_mistral': 3497, 'n_tokens_neox': 3339, 'n_words': 792}