from oscar.apps.customer.alerts.views import (
    ProductAlertCreateView as OscarProductAlertCreateView,
)

from ocyan.main.loading import get_baseclass

from ocyan.plugin.google.constants import CAPTCHA_ENABLED

BaseProductAlertCreateView = get_baseclass(
    "customer.alerts.views",
    "ProductAlertCreateView",
    "ocyan.plugin.google.google_customer_extension",
)


class ProductAlertCreateView(BaseProductAlertCreateView):
    def form_valid(self, form):
        if CAPTCHA_ENABLED:
            # use the original form_valid because we have turned the form to invalid
            # in the communication plugin!
            # pylint: disable=bad-super-call
            return OscarProductAlertCreateView.form_valid(self, form)

        return super().form_valid(form)
