# Path: sectesting/streetart/views/pages/base.py
# class BaseFormView(FormView):
#     """
#     This is a base class for all FormView pages used within the Street Art project.
#     """
# 
#     _created_object = None
# 
#     def _create_object(self, **create_kwargs):
#         """
#         Create an instance of the referenced model class and return it.
#         :param create_kwargs: Keyword arguments to pass to the object create method.
#         :return: The newly-created object.
#         """
#         self._created_object = self.form_class.Meta.model.objects.create(**create_kwargs)
#         return self._created_object
# 
#     @property
#     def created_object(self):
#         """
#         Get the model instance that was created by valid submission of the referenced form.
#         :return: the model instance that was created by valid submission of the referenced form.
#         """
#         return self._created_object
# 
# class BaseTemplateView(TemplateView):
#     """
#     This is a base class for all TemplateView pages used within the Street Art project.
#     """
# 
# Path: sectesting/streetart/forms/user.py
# class NewUserForm(forms.ModelForm):
#     """
#     This is a form for handling the registration of a new user.
#     """
# 
#     class Meta:
#         model = StreetArtUser
#         fields = [
#             "email",
#             "first_name",
#             "last_name",
#             "password",
#         ]
# 
# Path: sectesting/streetart/tests/registry.py
# def requested_by(requestor_path):
#     """
#     This is a decorator for views that maps a requestor class to the view that it is configured to
#     submit requests to.
#     :param requestor_path: A string depicting the local file path to the requestor class for the given
#     view.
#     :return: A function that maps the view class to the requestor path and returns the called function
#     or class.
#     """
# 
#     def decorator(to_wrap):
# 
#         registry = TestRequestorRegistry.instance()
#         registry.add_mapping(requestor_path=requestor_path, requested_view=to_wrap)
#         return to_wrap
# 
#     return decorator


from .base import BaseFormView, BaseTemplateView
from ...forms import NewUserForm
from ...tests import requested_by

@requested_by("streetart.tests.requestors.pages.CreateUserViewRequestor")
class CreateUserView(BaseFormView):
    """
    This is a view for creating a new user.
    """

    template_name = "pages/register.html"
    form_class = NewUserForm
    success_url = "/register-success/"

    def form_valid(self, form):
        """
        Handle the processing of the form to create a new Street Art user.
        :param form: The form to process.
        :return: The HTTP redirect response from super.form_valid.
        """
        user = self._create_object(
            email=form.cleaned_data["email"],
            first_name=form.cleaned_data["first_name"],
            last_name=form.cleaned_data["last_name"],
            is_active=True,
            is_staff=False,
            is_superuser=False,
        )
        user.set_password(form.cleaned_data["password"])
        user.save()
        return super(CreateUserView, self).form_valid(form)



# Path: sectesting/streetart/views/pages/base.py
# class BaseFormView(FormView):
#     """
#     This is a base class for all FormView pages used within the Street Art project.
#     """
# 
#     _created_object = None
# 
#     def _create_object(self, **create_kwargs):
#         """
#         Create an instance of the referenced model class and return it.
#         :param create_kwargs: Keyword arguments to pass to the object create method.
#         :return: The newly-created object.
#         """
#         self._created_object = self.form_class.Meta.model.objects.create(**create_kwargs)
#         return self._created_object
# 
#     @property
#     def created_object(self):
#         """
#         Get the model instance that was created by valid submission of the referenced form.
#         :return: the model instance that was created by valid submission of the referenced form.
#         """
#         return self._created_object
# 
# class BaseTemplateView(TemplateView):
#     """
#     This is a base class for all TemplateView pages used within the Street Art project.
#     """
# 
# Path: sectesting/streetart/forms/user.py
# class NewUserForm(forms.ModelForm):
#     """
#     This is a form for handling the registration of a new user.
#     """
# 
#     class Meta:
#         model = StreetArtUser
#         fields = [
#             "email",
#             "first_name",
#             "last_name",
#             "password",
#         ]
# 
# Path: sectesting/streetart/tests/registry.py
# def requested_by(requestor_path):
#     """
#     This is a decorator for views that maps a requestor class to the view that it is configured to
#     submit requests to.
#     :param requestor_path: A string depicting the local file path to the requestor class for the given
#     view.
#     :return: A function that maps the view class to the requestor path and returns the called function
#     or class.
#     """
# 
#     def decorator(to_wrap):
# 
#         registry = TestRequestorRegistry.instance()
#         registry.add_mapping(requestor_path=requestor_path, requested_view=to_wrap)
#         return to_wrap
# 
#     return decorator


# Path: sectesting/streetart/views/pages/auth.py
from .base import BaseFormView, BaseTemplateView
from ...forms import NewUserForm
from ...tests import requested_by


@requested_by("streetart.tests.requestors.pages.CreateUserViewRequestor")
class CreateUserView(BaseFormView):
    """
    This is a view for creating a new user.
    """

    template_name = "pages/register.html"
    form_class = NewUserForm
    success_url = "/register-success/"

    def form_valid(self, form):
        """
        Handle the processing of the form to create a new Street Art user.
        :param form: The form to process.
        :return: The HTTP redirect response from super.form_valid.
        """
        user = self._create_object(
            email=form.cleaned_data["email"],
            first_name=form.cleaned_data["first_name"],
            last_name=form.cleaned_data["last_name"],
            is_active=True,
            is_staff=False,
            is_superuser=False,
        )
        user.set_password(form.cleaned_data["password"])
        user.save()
        return super(CreateUserView, self).form_valid(form)



@requested_by("streetart.tests.requestors.pages.CreateUserSuccessRequestor")