<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 io import BytesIO

from flask import session, request, jsonify
from pytz import timezone
from sqlalchemy.orm import load_only, noload, joinedload
from werkzeug.exceptions import Forbidden

from indico.core.db import db
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.persons import ContributionPersonLink, AuthorType
from indico.modules.events.contributions.models.subcontributions import SubContribution
from indico.modules.events.contributions.util import (get_contributions_with_user_as_submitter,
                                                      serialize_contribution_for_ical, ContributionDisplayReporter)
from indico.modules.events.contributions.views import WPMyContributions, WPContributions, WPAuthorList, WPSpeakerList
from indico.modules.events.layout.util import is_menu_entry_enabled
from indico.modules.events.models.persons import EventPerson
from indico.modules.events.paper_reviewing.forms import PaperUploadForm
from indico.modules.events.paper_reviewing.legacy import get_reviewing_status
from indico.modules.events.util import get_base_ical_parameters
from indico.modules.events.views import WPEventDisplay
from indico.web.flask.util import send_file, jsonify_data
from indico.web.http_api.metadata.serializer import Serializer

from MaKaC.common.timezoneUtils import DisplayTZ
from MaKaC.PDFinterface.conference import ContribToPDF, ContribsToPDF
from MaKaC.webinterface.rh.base import RH
from MaKaC.webinterface.rh.conferenceDisplay import RHConferenceBaseDisplay


def _get_persons(event, condition):
    """Queries event persons linked to contributions in the event, filtered using the condition provided."""
    return (event.persons.filter(EventPerson.contribution_links.any(
            db.and_(condition,
                    ContributionPersonLink.contribution.has(~Contribution.is_deleted))))
            .options(joinedload('contribution_links').joinedload('contribution'))
            .order_by(db.func.lower(EventPerson.last_name)))


class RHContributionDisplayBase(RHConferenceBaseDisplay):
    CSRF_ENABLED = True

    normalize_url_spec = {
        'locators': {
            lambda self: self.contrib
        }
    }

    def _checkProtection(self):
        RHConferenceBaseDisplay._checkProtection(self)
        if not self.contrib.can_access(session.user):
            raise Forbidden

    def _checkParams(self, params):
        RHConferenceBaseDisplay._checkParams(self, params)
        self.contrib = Contribution.get_one(request.view_args['contrib_id'], is_deleted=False)


class RHDisplayProtectionBase(RHConferenceBaseDisplay):
    def _checkProtection(self):
        RHConferenceBaseDisplay._checkProtection(self)
        if not is_menu_entry_enabled(self.MENU_ENTRY_NAME, self.event_new):
            self._forbidden_if_not_admin()


class RHMyContributions(RHDisplayProtectionBase):
    """Display list of current user contributions"""

    MENU_ENTRY_NAME = 'my_contributions'

    def _process(self):
        contributions = get_contributions_with_user_as_submitter(self.event_new, session.user)
        return WPMyContributions.render_template('display/user_contribution_list.html', self._conf,
                                                 event=self.event_new, contributions=contributions)


class RHContributionList(RHDisplayProtectionBase):
    """Display list of event contributions"""

    MENU_ENTRY_NAME = 'contributions'

    def _checkParams(self, params):
        RHConferenceBaseDisplay._checkParams(self, params)
        self.contribs = self.event_new.contributions
        self.reporter = ContributionDisplayReporter(event=self.event_new)

    def _process(self):
        tz = timezone(DisplayTZ(session.user, self._conf).getDisplayTZ())
        return WPContributions.render_template('display/contribution_list.html', self._conf, event=self.event_new,
                                               timezone=tz, **self.reporter.get_contrib_report_kwargs())


class RHContributionDisplay(RHContributionDisplayBase):
    """Display page with contribution details """

    def _process(self):
        reviewing_status = get_reviewing_status(self.contrib, self._conf)
        show_paper = ((self._conf.getConfPaperReview().hasReviewing() and
                       self.contrib.can_manage(session.user, 'submit')) or reviewing_status == 'Accept')
        paper_upload_form = PaperUploadForm()
        paper_file_data = self.contrib.paper_files.filter_by(revision_id=None) if show_paper else None

        ical_params = get_base_ical_parameters(session.user, self.event_new, 'contributions')
        return WPContributions.render_template('display/contribution_display.html', self._conf,
                                               contribution=self.contrib, event=self.event_new,
                                               reviewing_status=get_reviewing_status(self.contrib, self._conf),
                                               show_paper=show_paper,
                                               can_submit_paper=self.contrib.can_manage(session.user, 'submit'),<commit_msg>Only get reviewing status in conferences<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 io import BytesIO

from flask import session, request, jsonify
from pytz import timezone
from sqlalchemy.orm import load_only, noload, joinedload
from werkzeug.exceptions import Forbidden

from indico.core.db import db
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.persons import ContributionPersonLink, AuthorType
from indico.modules.events.contributions.models.subcontributions import SubContribution
from indico.modules.events.contributions.util import (get_contributions_with_user_as_submitter,
                                                      serialize_contribution_for_ical, ContributionDisplayReporter)
from indico.modules.events.contributions.views import WPMyContributions, WPContributions, WPAuthorList, WPSpeakerList
from indico.modules.events.layout.util import is_menu_entry_enabled
from indico.modules.events.models.persons import EventPerson
from indico.modules.events.paper_reviewing.forms import PaperUploadForm
from indico.modules.events.paper_reviewing.legacy import get_reviewing_status
from indico.modules.events.util import get_base_ical_parameters
from indico.modules.events.views import WPEventDisplay
from indico.web.flask.util import send_file, jsonify_data
from indico.web.http_api.metadata.serializer import Serializer

from MaKaC.common.timezoneUtils import DisplayTZ
from MaKaC.PDFinterface.conference import ContribToPDF, ContribsToPDF
from MaKaC.webinterface.rh.base import RH
from MaKaC.webinterface.rh.conferenceDisplay import RHConferenceBaseDisplay


def _get_persons(event, condition):
    """Queries event persons linked to contributions in the event, filtered using the condition provided."""
    return (event.persons.filter(EventPerson.contribution_links.any(
            db.and_(condition,
                    ContributionPersonLink.contribution.has(~Contribution.is_deleted))))
            .options(joinedload('contribution_links').joinedload('contribution'))
            .order_by(db.func.lower(EventPerson.last_name)))


class RHContributionDisplayBase(RHConferenceBaseDisplay):
    CSRF_ENABLED = True

    normalize_url_spec = {
        'locators': {
            lambda self: self.contrib
        }
    }

    def _checkProtection(self):
        RHConferenceBaseDisplay._checkProtection(self)
        if not self.contrib.can_access(session.user):
            raise Forbidden

    def _checkParams(self, params):
        RHConferenceBaseDisplay._checkParams(self, params)
        self.contrib = Contribution.get_one(request.view_args['contrib_id'], is_deleted=False)


class RHDisplayProtectionBase(RHConferenceBaseDisplay):
    def _checkProtection(self):
        RHConferenceBaseDisplay._checkProtection(self)
        if not is_menu_entry_enabled(self.MENU_ENTRY_NAME, self.event_new):
            self._forbidden_if_not_admin()


class RHMyContributions(RHDisplayProtectionBase):
    """Display list of current user contributions"""

    MENU_ENTRY_NAME = 'my_contributions'

    def _process(self):
        contributions = get_contributions_with_user_as_submitter(self.event_new, session.user)
        return WPMyContributions.render_template('display/user_contribution_list.html', self._conf,
                                                 event=self.event_new, contributions=contributions)


class RHContributionList(RHDisplayProtectionBase):
    """Display list of event contributions"""

    MENU_ENTRY_NAME = 'contributions'

    def _checkParams(self, params):
        RHConferenceBaseDisplay._checkParams(self, params)
        self.contribs = self.event_new.contributions
        self.reporter = ContributionDisplayReporter(event=self.event_new)

    def _process(self):
        tz = timezone(DisplayTZ(session.user, self._conf).getDisplayTZ())
        return WPContributions.render_template('display/contribution_list.html', self._conf, event=self.event_new,
                                               timezone=tz, **self.reporter.get_contrib_report_kwargs())


class RHContributionDisplay(RHContributionDisplayBase):
    """Display page with contribution details """

    def _process(self):
        if self.event_new.type == 'conference':
            reviewing_status = get_reviewing_status(self.contrib, self._conf)
            show_paper = ((self._conf.getConfPaperReview().hasReviewing() and
                           self.contrib.can_manage(session.user, 'submit')) or reviewing_status == 'Accept')
            paper_upload_form = PaperUploadForm()
            paper_file_data = self.contrib.paper_files.filter_by(revision_id=None) if show_paper else None
        else:
            reviewing_status = paper_upload_form = paper_file_data = None
            show_paper = False

        ical_params = get_base_ical_parameters(session.user, self.event_new, 'contributions')
        return WPContributions.render_template('display/contribution_display.html', self._conf,
                                               contribution=self.contrib, event=self.event_new,
                                               reviewing_status=reviewing_status,
                                               show_paper=show_paper,
                                               can_submit_paper=self.contrib.can_manage(session.user, 'submit'),
{'fraction_non_alphanumeric': 0.07348057123879109, 'fraction_numerical': 0.0014945200929923613, 'mean_word_length': 3.576367781155015, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3312625', 'n_tokens_mistral': 3322, 'n_tokens_neox': 3142, 'n_words': 753}