"""This module provides ``WorkshopStepImage`` for the ``workshops`` app"""

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _

from . import WorkshopStep


class WorkshopStepImage(WorkshopStep):
    """Django model representing a workshop image step.

    Attributes
    ----------
    image : django ``ImageField``
        The image of the step.

    """
    image = models.ImageField(upload_to="workshops", verbose_name=_('Image'))

    step_name = 'image'
    verbose_step_name = _('Image')

    @property
    def serializer_class(self):
        """Get the serializer class to use for this model

        This is a property to avoid recursive import problem.

        """

        from ..apiv2.serializers import WorkshopStepImageSerializer

        return WorkshopStepImageSerializer

    def get_absolute_url(self):
        """ Get the url of the current image step.

        Returns
        -------
        string
            The wanted url.

        """
        return self.get_edit_url()

    def get_edit_url(self):
        """ Get the url to edit the current step.

        Returns
        -------
        string
            The wanted url.

        """
        return reverse('workshops:step-image-update', kwargs={
            'workshop_uuid': self.workshop.pk, 'step_uuid': self.pk})

    @classmethod
    def get_create_url(cls, workshop):
        """ Get the url to create a new image step.

        Parameters
        ----------
        workshop: Workshop
            The workshop for which we want to create a new image step.

        Returns
        -------
        string
            The wanted url.

        """
        return reverse('workshops:step-image-create', kwargs={'workshop_uuid': workshop.pk})
