from django.utils.translation import gettext_lazy as _

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


class ProductAlertCreateView(BaseProductAlertCreateView):
    def form_valid(self, form):
        error_field = "__all__" if form.user else "email"
        form.add_error(
            error_field,
            _(
                "Because of spammers abusing this form, unfortunately at this point we cannot accept product alert requests"
            ),
        )
        return self.form_invalid(form)
