WesternFriend/WF-website

View on GitHub
accounts/views.py

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
from typing import Any
from django.conf import settings
from django.utils.decorators import method_decorator

from django_registration.backends.activation.views import RegistrationView  # type: ignore
from honeypot.decorators import check_honeypot  # type: ignore

from accounts.forms import CustomUserForm


@method_decorator(check_honeypot, name="post")
class CustomRegistrationView(RegistrationView):
    form_class = CustomUserForm
    success_url = "/"
    template_name = "django_registration/registration_form.html"

    def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
        """Add honeypot field to context."""
        context = super().get_context_data(**kwargs)

        context["honeypot_field_name"] = settings.HONEYPOT_FIELD_NAME

        return context