<commit_before>##############################################################################
#
#    Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging

from werkzeug.exceptions import Unauthorized

from odoo import http, _
from odoo.http import request, Controller

from odoo.addons.cms_form.controllers.main import FormControllerMixin

_logger = logging.getLogger(__name__)


class ZoomRegistration(Controller, FormControllerMixin):
    @http.route(
        [
            "/zoom/<model('res.partner.zoom.session'):session>/register",
            "/zoom/register"
        ],
        type="http", auth="public", methods=["GET", "POST"], website=True,
        sitemap=False)
    def zoom_registration(self, session=None, **kwargs):
        if session is None:
            session = request.env["res.partner.zoom.session"].get_next_session()
        if not session.website_published:
            raise Unauthorized()
        participant = request.env["res.partner.zoom.attendee"]
        if request.env.user and request.env.user != request.env.ref("base.public_user"):
            partner = request.env.user.partner_id
            kwargs["partner_id"] = partner.id
            participant = session.participant_ids.filtered(
                lambda p: p.partner_id == partner)
        kwargs["zoom_session_id"] = session.id
        form = self.get_form("res.partner.zoom.attendee", participant.id, **kwargs)
        form.form_process(**kwargs)
        return request.render(
            "partner_communication_switzerland.zoom_registration_template",
            {"session": session,
             "form": form,
             "main_object": participant}
        )
<commit_msg>CS-638 Allow to register to zoom session until 15 minutes after start<commit_after>##############################################################################
#
#    Copyright (C) 2021 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging
from datetime import datetime

from dateutil.relativedelta import relativedelta
from werkzeug.exceptions import Unauthorized

from odoo import http
from odoo.http import request, Controller

from odoo.addons.cms_form.controllers.main import FormControllerMixin

_logger = logging.getLogger(__name__)


class ZoomRegistration(Controller, FormControllerMixin):
    @http.route(
        [
            "/zoom/<model('res.partner.zoom.session'):session>/register",
            "/zoom/register"
        ],
        type="http", auth="public", methods=["GET", "POST"], website=True,
        sitemap=False)
    def zoom_registration(self, session=None, **kwargs):
        if session is None:
            # Allow to register in the current zoom session for 15 minutes after start
            start = datetime.now() - relativedelta(minutes=15)
            session = request.env["res.partner.zoom.session"].get_next_session(start)
        if not session.website_published:
            raise Unauthorized()
        participant = request.env["res.partner.zoom.attendee"]
        if request.env.user and request.env.user != request.env.ref("base.public_user"):
            partner = request.env.user.partner_id
            kwargs["partner_id"] = partner.id
            participant = session.participant_ids.filtered(
                lambda p: p.partner_id == partner)
        kwargs["zoom_session_id"] = session.id
        form = self.get_form("res.partner.zoom.attendee", participant.id, **kwargs)
        form.form_process(**kwargs)
        return request.render(
            "partner_communication_switzerland.zoom_registration_template",
            {"session": session,
             "form": form,
             "main_object": participant}
        )

{'fraction_non_alphanumeric': 0.17783191230207065, 'fraction_numerical': 0.0041412911084043845, 'mean_word_length': 3.1558704453441297, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, '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': '7249935', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1084, 'n_words': 245}