<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

from flask import session, flash
from werkzeug.exceptions import Forbidden

from indico.core.errors import NoReportError
from indico.modules.events.abstracts.controllers.base import RHAbstractsBase
from indico.modules.events.abstracts.operations import create_abstract
from indico.modules.events.abstracts.util import get_user_abstracts, make_abstract_form
from indico.modules.events.abstracts.views import WPDisplayCallForAbstracts
from indico.modules.events.util import get_field_values
from indico.util.i18n import _
from indico.web.flask.util import send_file, url_for
from indico.web.util import jsonify_data, jsonify_template
from indico.legacy.PDFinterface.conference import AbstractsToPDF


class RHCallForAbstracts(RHAbstractsBase):
    """Show the main CFA page"""

    def _process(self):
        abstracts = get_user_abstracts(self.event_new, session.user) if session.user else []
        return WPDisplayCallForAbstracts.render_template('display/call_for_abstracts.html', self._conf,
                                                         event=self.event_new, abstracts=abstracts)


class RHMyAbstractsExportPDF(RHAbstractsBase):
    """Export the list of the user's abstracts as PDF"""

    def _checkProtection(self):
        if not session.user:
            raise Forbidden
        RHAbstractsBase._checkProtection(self)

    def _process(self):
        pdf = AbstractsToPDF(self.event_new, get_user_abstracts(self.event_new, session.user))
        return send_file('my-abstracts.pdf', pdf.generate(), 'application/pdf')


class RHSubmitAbstract(RHAbstractsBase):
    """Submit a new abstract."""

    def _checkProtection(self):
        cfa = self.event_new.cfa
        if session.user and not cfa.is_open and not cfa.can_submit_abstracts(session.user):
            raise NoReportError(_('The Call for Abstracts is closed. Please contact the event organiser for further '
                                  'assistance.'), http_status_code=403)
        elif not session.user or not cfa.can_submit_abstracts(session.user):
            raise Forbidden
        RHAbstractsBase._checkProtection(self)

    def _process(self):
        abstract_form_class = make_abstract_form(self.event_new, management=self.management)
        form = abstract_form_class(event=self.event_new)
        if form.validate_on_submit():
            abstract = create_abstract(self.event_new, *get_field_values(form.data), send_notifications=True)
            flash(_("Your abstract '{}' has been successfully submitted. It is registered with the number "
                    "#{}. You will be notified by email with the submission details.")
                  .format(abstract.title, abstract.friendly_id), 'success')
            return jsonify_data(flash=False, redirect=url_for('.call_for_abstracts', self.event_new))
        return jsonify_template('events/abstracts/display/submission.html', event=self.event_new, form=form)
<commit_msg>organiser -> organizer<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

from flask import session, flash
from werkzeug.exceptions import Forbidden

from indico.core.errors import NoReportError
from indico.modules.events.abstracts.controllers.base import RHAbstractsBase
from indico.modules.events.abstracts.operations import create_abstract
from indico.modules.events.abstracts.util import get_user_abstracts, make_abstract_form
from indico.modules.events.abstracts.views import WPDisplayCallForAbstracts
from indico.modules.events.util import get_field_values
from indico.util.i18n import _
from indico.web.flask.util import send_file, url_for
from indico.web.util import jsonify_data, jsonify_template
from indico.legacy.PDFinterface.conference import AbstractsToPDF


class RHCallForAbstracts(RHAbstractsBase):
    """Show the main CFA page"""

    def _process(self):
        abstracts = get_user_abstracts(self.event_new, session.user) if session.user else []
        return WPDisplayCallForAbstracts.render_template('display/call_for_abstracts.html', self._conf,
                                                         event=self.event_new, abstracts=abstracts)


class RHMyAbstractsExportPDF(RHAbstractsBase):
    """Export the list of the user's abstracts as PDF"""

    def _checkProtection(self):
        if not session.user:
            raise Forbidden
        RHAbstractsBase._checkProtection(self)

    def _process(self):
        pdf = AbstractsToPDF(self.event_new, get_user_abstracts(self.event_new, session.user))
        return send_file('my-abstracts.pdf', pdf.generate(), 'application/pdf')


class RHSubmitAbstract(RHAbstractsBase):
    """Submit a new abstract."""

    def _checkProtection(self):
        cfa = self.event_new.cfa
        if session.user and not cfa.is_open and not cfa.can_submit_abstracts(session.user):
            raise NoReportError(_('The Call for Abstracts is closed. Please contact the event organizer for further '
                                  'assistance.'), http_status_code=403)
        elif not session.user or not cfa.can_submit_abstracts(session.user):
            raise Forbidden
        RHAbstractsBase._checkProtection(self)

    def _process(self):
        abstract_form_class = make_abstract_form(self.event_new, management=self.management)
        form = abstract_form_class(event=self.event_new)
        if form.validate_on_submit():
            abstract = create_abstract(self.event_new, *get_field_values(form.data), send_notifications=True)
            flash(_("Your abstract '{}' has been successfully submitted. It is registered with the number "
                    "#{}. You will be notified by email with the submission details.")
                  .format(abstract.title, abstract.friendly_id), 'success')
            return jsonify_data(flash=False, redirect=url_for('.call_for_abstracts', self.event_new))
        return jsonify_template('events/abstracts/display/submission.html', event=self.event_new, form=form)

{'fraction_non_alphanumeric': 0.07846298535536746, 'fraction_numerical': 0.0037619239553943304, 'mean_word_length': 3.7054361567635903, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '132384', 'n_tokens_mistral': 2079, 'n_tokens_neox': 2016, 'n_words': 613}