<commit_before># This file is part of Indico.
# Copyright (C) 2002 - 2019 CERN
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.

from __future__ import unicode_literals

from indico.core.db import db
from indico.core.db.sqlalchemy.principals import clone_principals
from indico.core.db.sqlalchemy.util.models import get_simple_column_attrs
from indico.core.db.sqlalchemy.util.session import no_autoflush
from indico.modules.events.cloning import EventCloner
from indico.modules.events.models.events import EventType
from indico.modules.events.tracks.models.principals import TrackPrincipal
from indico.modules.events.tracks.models.tracks import Track
from indico.util.i18n import _


class TrackCloner(EventCloner):
    name = 'tracks'
    friendly_name = _('Tracks')
    always_available_dep = True

    @property
    def is_visible(self):
        return self.old_event.type_ == EventType.conference

    @property
    def is_available(self):
        return bool(self.old_event.tracks)

    @no_autoflush
    def run(self, new_event, cloners, shared_data):
        self._track_map = {}
        self._clone_tracks(new_event)
        db.session.flush()
        return {'track_map': self._track_map}

    def _clone_tracks(self, new_event):
        attrs = get_simple_column_attrs(Track)
        for old_track in self.old_event.tracks:
            track = Track()
            track.populate_from_attrs(old_track, attrs)
            track.acl_entries = clone_principals(TrackPrincipal, old_track.acl_entries)
            new_event.tracks.append(track)
            self._track_map[old_track] = track<commit_msg>Clone track groups together with tracks<commit_after># This file is part of Indico.
# Copyright (C) 2002 - 2019 CERN
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see the
# LICENSE file for more details.

from __future__ import unicode_literals

from indico.core.db import db
from indico.core.db.sqlalchemy.principals import clone_principals
from indico.core.db.sqlalchemy.util.models import get_simple_column_attrs
from indico.core.db.sqlalchemy.util.session import no_autoflush
from indico.modules.events.cloning import EventCloner
from indico.modules.events.models.events import EventType
from indico.modules.events.tracks.models.groups import TrackGroup
from indico.modules.events.tracks.models.principals import TrackPrincipal
from indico.modules.events.tracks.models.tracks import Track
from indico.util.i18n import _


class TrackCloner(EventCloner):
    name = 'tracks'
    friendly_name = _('Tracks')
    always_available_dep = True

    @property
    def is_visible(self):
        return self.old_event.type_ == EventType.conference

    @property
    def is_available(self):
        return bool(self.old_event.tracks)

    @no_autoflush
    def run(self, new_event, cloners, shared_data):
        self._track_map = {}
        self._track_group_map = {}
        self._clone_track_groups(new_event)
        self._clone_tracks(new_event)
        db.session.flush()
        return {'track_map': self._track_map}

    def _clone_tracks(self, new_event):
        attrs = get_simple_column_attrs(Track)
        for old_track in self.old_event.tracks:
            track = Track()
            track.populate_from_attrs(old_track, attrs)
            track.acl_entries = clone_principals(TrackPrincipal, old_track.acl_entries)
            track.track_group = self._track_group_map.get(old_track.track_group, None)
            new_event.tracks.append(track)
            self._track_map[old_track] = track

    def _clone_track_groups(self, new_event):
        attrs = get_simple_column_attrs(TrackGroup)
        for old_group in self.old_event.track_groups:
            group = TrackGroup()
            group.populate_from_attrs(old_group, attrs)
            new_event.track_groups.append(group)
            self._track_group_map[old_group] = group
{'fraction_non_alphanumeric': 0.07893426294820717, 'fraction_numerical': 0.0049800796812749, 'mean_word_length': 3.498320268756999, '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': '2540579', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1209, 'n_words': 281}