<commit_before># This file is part of Indico.
# Copyright (C) 2002 - 2016 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 request, redirect, flash, session, g, render_template
from werkzeug.exceptions import BadRequest, NotFound

from indico.core import signals
from indico.core.db.sqlalchemy.principals import PrincipalType
from indico.core.logger import Logger
from indico.core.roles import check_roles, ManagementRole, get_available_roles
from indico.modules.events.cloning import get_event_cloners
from indico.modules.events.logs import EventLogRealm, EventLogKind
from indico.modules.events.models.events import Event
from indico.modules.events.models.legacy_mapping import LegacyEventMapping
from indico.modules.events.util import notify_pending
from indico.util.i18n import _, ngettext, orig_string
from indico.util.string import is_legacy_id
from indico.web.flask.templating import template_hook, get_template_module
from indico.web.flask.util import url_for
from indico.web.forms.base import FormDefaults
from indico.web.menu import SideMenuItem


__all__ = ('Event', 'logger', 'event_management_object_url_prefixes', 'event_object_url_prefixes')
logger = Logger.get('events')

#: URL prefixes for the various event objects (public area)
#: All prefixes are expected to be used inside the '/event/<confId>'
#: url space.
event_object_url_prefixes = {
    'event': [''],
    'session': ['/session/<int:session_id>'],
    'contribution': ['/contribution/<int:contrib_id>'],
    'subcontribution': ['/contribution/<int:contrib_id>/<int:subcontrib_id>']
}

#: URL prefixes for the various event objects (management area)
#: All prefixes are expected to be used inside the '/event/<confId>'
#: url space.
event_management_object_url_prefixes = {
    'event': ['/manage'],
    'session': ['/manage/sessions/<int:session_id>'],
    'contribution': ['/manage/contributions/<int:contrib_id>'],
    'subcontribution': ['/manage/contributions/<int:contrib_id>/subcontribution/<int:subcontrib_id>']
}


@signals.event.deleted.connect
def _event_deleted(event, **kwargs):
    event.as_event.is_deleted = True
    logger.info('Event %s deleted. ZODB OID: %r', event.as_event, event._p_oid)


@signals.users.merged.connect
def _merge_users(target, source, **kwargs):
    from indico.modules.events.models.principals import EventPrincipal
    EventPrincipal.merge_users(target, source, 'event_new')


@signals.users.registered.connect
@signals.users.email_added.connect
def _convert_email_principals(user, **kwargs):
    from indico.modules.events.models.principals import EventPrincipal
    events = EventPrincipal.replace_email_with_user(user, 'event_new')
    if events:
        num = len(events)
        flash(ngettext("You have been granted manager/submission privileges for an event.",
                       "You have been granted manager/submission privileges for {} events.", num).format(num), 'info')


@signals.users.registered.connect
@signals.users.email_added.connect
def _convert_email_person_links(user, **kwargs):
    from indico.modules.events.models.persons import EventPerson
    EventPerson.link_user_by_email(user)
<commit_msg>Log event ID instead of repr when deleting event<commit_after># This file is part of Indico.
# Copyright (C) 2002 - 2016 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 request, redirect, flash, session, g, render_template
from werkzeug.exceptions import BadRequest, NotFound

from indico.core import signals
from indico.core.db.sqlalchemy.principals import PrincipalType
from indico.core.logger import Logger
from indico.core.roles import check_roles, ManagementRole, get_available_roles
from indico.modules.events.cloning import get_event_cloners
from indico.modules.events.logs import EventLogRealm, EventLogKind
from indico.modules.events.models.events import Event
from indico.modules.events.models.legacy_mapping import LegacyEventMapping
from indico.modules.events.util import notify_pending
from indico.util.i18n import _, ngettext, orig_string
from indico.util.string import is_legacy_id
from indico.web.flask.templating import template_hook, get_template_module
from indico.web.flask.util import url_for
from indico.web.forms.base import FormDefaults
from indico.web.menu import SideMenuItem


__all__ = ('Event', 'logger', 'event_management_object_url_prefixes', 'event_object_url_prefixes')
logger = Logger.get('events')

#: URL prefixes for the various event objects (public area)
#: All prefixes are expected to be used inside the '/event/<confId>'
#: url space.
event_object_url_prefixes = {
    'event': [''],
    'session': ['/session/<int:session_id>'],
    'contribution': ['/contribution/<int:contrib_id>'],
    'subcontribution': ['/contribution/<int:contrib_id>/<int:subcontrib_id>']
}

#: URL prefixes for the various event objects (management area)
#: All prefixes are expected to be used inside the '/event/<confId>'
#: url space.
event_management_object_url_prefixes = {
    'event': ['/manage'],
    'session': ['/manage/sessions/<int:session_id>'],
    'contribution': ['/manage/contributions/<int:contrib_id>'],
    'subcontribution': ['/manage/contributions/<int:contrib_id>/subcontribution/<int:subcontrib_id>']
}


@signals.event.deleted.connect
def _event_deleted(event, **kwargs):
    event.as_event.is_deleted = True
    logger.info('Event %s deleted. ZODB OID: %r', event.id, event._p_oid)


@signals.users.merged.connect
def _merge_users(target, source, **kwargs):
    from indico.modules.events.models.principals import EventPrincipal
    EventPrincipal.merge_users(target, source, 'event_new')


@signals.users.registered.connect
@signals.users.email_added.connect
def _convert_email_principals(user, **kwargs):
    from indico.modules.events.models.principals import EventPrincipal
    events = EventPrincipal.replace_email_with_user(user, 'event_new')
    if events:
        num = len(events)
        flash(ngettext("You have been granted manager/submission privileges for an event.",
                       "You have been granted manager/submission privileges for {} events.", num).format(num), 'info')


@signals.users.registered.connect
@signals.users.email_added.connect
def _convert_email_person_links(user, **kwargs):
    from indico.modules.events.models.persons import EventPerson
    EventPerson.link_user_by_email(user)

{'fraction_non_alphanumeric': 0.09983057474260394, 'fraction_numerical': 0.0028671966636257006, 'mean_word_length': 5.173773129525342, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7200194', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2244, 'n_words': 674}