"""This module holds the views related to the ``QuestionWall`` model"""

from django.utils.translation import ugettext_lazy as _
from django.views import generic

from mtp.apps.common.views_utils import AjaxResponseMixin
from mtp.apps.trainings.views.activities import (
    TrainingActivityCreateBase,
    TrainingActivityDetailBase,
    TrainingActivityEditBase,
)

from ..forms import QuestionWallForm
from ..models import QuestionWall


class QuestionWallBase(TrainingActivityDetailBase):
    """Base view to use on all views related to the ``QuestionWall`` model.

    Define the queryset to use for the current user.

    """

    def get_queryset(self):
        """Get all ``QuestionWall`` instances the current user is allowed to see.

        The user can only see questionwall instance he own.
        Also excludes deleted questionwall from the result.

        Returns
        -------
        Queryset of ``mtp.apps.ideas.models.QuestionWall``
            A lazy queryset with the wanted questionwalls.

        """

        return super().get_queryset().instance_of(QuestionWall)

    def get_success_url(self):
        """Get the url where to go back when an action is done on a ``QuestionWall``"""

        return self.object.get_detail_url()


class QuestionWallEditBase(AjaxResponseMixin, QuestionWallBase):
    """Base view to create or edit a given instance of ``QuestionWall``"""

    model = QuestionWall
    form_class = QuestionWallForm
    pk_url_kwarg = 'questionwall_uuid'


class QuestionWallDetailView(QuestionWallEditBase, generic.DetailView):
    """Detail View for a ``Brainstorming`` instance"""

    template_name = 'ideas/idea_activity_detail.html'


class QuestionWallCreateView(QuestionWallEditBase, TrainingActivityCreateBase):
    """View to create a new ``QuestionWall`` instance"""

    success_message = _('Your Questionwall was successfully created.')


class QuestionWallUpdateView(QuestionWallEditBase, TrainingActivityEditBase):
    """View to update an existing ``QuestionWall`` instance"""

    success_message = _('Your Questionwall was successfully updated.')
