Beispiel #1
0
def form(cfp_type="talk"):
    form = get_cfp_type_form(cfp_type)
    if not form:
        abort(404)

    ignore_closed = "closed" in request.args

    if feature_enabled("CFP_CLOSED") and not ignore_closed:
        return render_template("cfp/closed.html", cfp_type=cfp_type)

    if feature_enabled("CFP_{}S_CLOSED".format(
            cfp_type.upper())) and not ignore_closed:
        msg = Markup(
            render_template_string(
                """Sorry, we're not accepting new {{ type }} proposals, if you have been told to submit something please <a href="{{ url }}">click here</a>""",
                type=HUMAN_CFP_TYPES[cfp_type],
                url=url_for(".form", cfp_type=cfp_type, closed=True),
            ))
        flash(msg)
        return redirect(url_for(".main"))

    if (cfp_type == "lightning" and not feature_enabled("LIGHTNING_TALKS")
            and not current_user.has_permission("cfp_admin")):
        flash("We're not currently accepting Lightning Talks.")
        return redirect(url_for(".main"))

    remaining_lightning_slots = LightningTalkProposal.get_days_with_slots()
    # Require logged in users as you have to have a ticket to lightning talk
    if cfp_type == "lightning" and current_user.is_anonymous:
        return redirect(
            url_for("users.login", next=url_for(".form",
                                                cfp_type="lightning")))
    elif cfp_type == "lightning":
        if all([i <= 0 for i in remaining_lightning_slots.values()]):
            flash("All lightning talk sessions are now full, sorry")
            return redirect(url_for(".main"))
        form.set_session_choices(remaining_lightning_slots)

    # If the user is already logged in set their name & email for the form
    if current_user.is_authenticated:
        form.email.data = current_user.email
        if current_user.name != current_user.email:
            form.name.data = current_user.name

    if request.method == "POST":
        app.logger.info(
            "Checking %s proposal for %s (%s)",
            cfp_type,
            form.name.data,
            form.email.data,
        )

    if form.validate_on_submit():
        new_user = False
        if current_user.is_anonymous:
            try:
                create_current_user(form.email.data, form.name.data)
                new_user = True
            except IntegrityError as e:
                app.logger.warn("Adding user raised %r, possible double-click",
                                e)
                flash(
                    "An error occurred while creating an account for you. Please try again."
                )
                return redirect(url_for(".main"))

        elif current_user.name == current_user.email:
            current_user.name = form.name.data

        if cfp_type == "talk":
            proposal = TalkProposal()
            proposal.length = form.length.data

        elif cfp_type == "performance":
            proposal = PerformanceProposal()
            proposal.length = form.length.data

        elif cfp_type == "workshop":
            proposal = WorkshopProposal()
            proposal.length = form.length.data
            proposal.attendees = form.attendees.data
            proposal.cost = form.cost.data
            proposal.participant_equipment = form.participant_equipment.data
            proposal.age_range = form.age_range.data

        elif cfp_type == "youthworkshop":
            proposal = YouthWorkshopProposal()
            proposal.length = form.length.data
            proposal.attendees = form.attendees.data
            proposal.cost = form.cost.data
            proposal.participant_equipment = form.participant_equipment.data
            proposal.age_range = form.age_range.data
            proposal.valid_dbs = form.valid_dbs.data

        elif cfp_type == "installation":
            proposal = InstallationProposal()
            proposal.size = form.size.data
            proposal.funds = form.funds.data

        elif cfp_type == "lightning":
            if remaining_lightning_slots[form.session.data] <= 0:
                # Manually set this because otherwise we need to pass the
                # remaining_lightning_slots object to validate
                form.errors[
                    "sessions"] = "That session is now full, sorry. Please select a different day"
                return render_template(
                    "cfp/new.html",
                    cfp_type=cfp_type,
                    form=form,
                    has_errors=bool(form.errors),
                    ignore_closed=ignore_closed,
                )

            proposal = LightningTalkProposal()
            proposal.slide_link = form.slide_link.data
            proposal.session = form.session.data

        proposal.user_id = current_user.id

        proposal.title = form.title.data
        proposal.requirements = form.requirements.data
        proposal.description = form.description.data
        proposal.notice_required = form.notice_required.data
        proposal.needs_help = form.needs_help.data

        db.session.add(proposal)
        db.session.commit()

        # Send confirmation message
        msg = EmailMessage(
            "Electromagnetic Field CFP Submission",
            from_email=from_email("CONTENT_EMAIL"),
            to=[current_user.email],
        )

        msg.body = render_template("emails/cfp-submission.txt",
                                   proposal=proposal,
                                   new_user=new_user)
        msg.send()

        if channel := app.config.get("CONTENT_IRC_CHANNEL"):
            # WARNING: don't send personal information via this (the channel is public)
            irc_send(
                f"{channel} New CfP {proposal.human_type} submission: {external_url('cfp_review.update_proposal', proposal_id=proposal.id)}"
            )
        return redirect(url_for(".complete"))