# Path: core/utils.py
# class PathAndRename(object):
# 
#     def __init__(self, sub_path):
#         self.path = sub_path
# 
#     def __call__(self, instance, filename):
#         ext = filename.split('.')[-1]
#         # set filename
#         if hasattr(instance, 'name') and instance.name:
#             filename = '{}.{}'.format(slugify(instance.name[:255]), ext)
#         elif hasattr(instance, 'title') and instance.title:
#             filename = '{}.{}'.format(slugify(instance.title[:255]), ext)
#         else:
#             # set filename as random string
#             filename = '{}.{}'.format(slugify(str(uuid.uuid4())), ext)
#         # return the whole path to the file
#         return os.path.join(self.path, "{}".format(datetime.now().year), "{}".format(datetime.now().month), filename)
# 
# Path: saas/models.py
# class Customer(models.Model):
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     name = models.CharField(_('Customer name'), max_length=255, blank=False)
#     email = models.EmailField(_('Email address'), blank=True)
#     phone = PhoneNumberField(_('Phone Number'), max_length=255, blank=True)
#     is_active = models.BooleanField(_('Active'), default=True,
#                                     help_text=_('Designates whether this customer should be treated as '
#                                                 'active.'))
# 
#     class Meta:
#         verbose_name = _("Customer")
#         verbose_name_plural = _("Customers")
# 
#     def __str__(self):
#         return self.name
# 
# Path: questions/managers.py
# class QuizManager(models.Manager):
# 
#     def active(self):
#         return self.get_queryset().filter(draft=False)


from decimal import Decimal
from django.core.validators import MaxValueValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.utils.encoding import python_2_unicode_compatible
from autoslug import AutoSlugField
from mptt.fields import TreeForeignKey
from mptt.models import MPTTModel
from polymorphic.models import PolymorphicModel
from sorl.thumbnail import ImageField
from core.utils import PathAndRename
from saas.models import Customer
from .managers import QuizManager
        from answers.models import TextAnswer
        from answers.models import EssayAnswer
        from answers.models import MultipleChoiceAnswer
        from answers.models import RatingAnswer
        from answers.models import BooleanAnswer
@python_2_unicode_compatible
class MultipleChoiceQuestion(Question):

    """
        A type of question where the user is presented with a list of options to pick from
        The choices themselves are MultipleChoiceAnswer objects
    """

    class Meta:
        verbose_name = _("Multiple Choice Question")
        verbose_name_plural = _("Multiple Choice Questions")

    def get_answer_class(self):
        return MultipleChoiceAnswer

    def __str__(self):
        return self.title


@python_2_unicode_compatible
class MultipleChoiceOption(models.Model):

    """The answer choices to a multiple choice question"""

    created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
    updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
    question = models.ForeignKey(
        MultipleChoiceQuestion, verbose_name=_("Question"), on_delete=models.CASCADE)
    title = models.CharField(_("Answer"), max_length=300, blank=False, help_text=_(
        "Input the answer as you want it displayed"))

# Path: core/utils.py
# class PathAndRename(object):
# 
#     def __init__(self, sub_path):
#         self.path = sub_path
# 
#     def __call__(self, instance, filename):
#         ext = filename.split('.')[-1]
#         # set filename
#         if hasattr(instance, 'name') and instance.name:
#             filename = '{}.{}'.format(slugify(instance.name[:255]), ext)
#         elif hasattr(instance, 'title') and instance.title:
#             filename = '{}.{}'.format(slugify(instance.title[:255]), ext)
#         else:
#             # set filename as random string
#             filename = '{}.{}'.format(slugify(str(uuid.uuid4())), ext)
#         # return the whole path to the file
#         return os.path.join(self.path, "{}".format(datetime.now().year), "{}".format(datetime.now().month), filename)
# 
# Path: saas/models.py
# class Customer(models.Model):
#     created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
#     updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
#     name = models.CharField(_('Customer name'), max_length=255, blank=False)
#     email = models.EmailField(_('Email address'), blank=True)
#     phone = PhoneNumberField(_('Phone Number'), max_length=255, blank=True)
#     is_active = models.BooleanField(_('Active'), default=True,
#                                     help_text=_('Designates whether this customer should be treated as '
#                                                 'active.'))
# 
#     class Meta:
#         verbose_name = _("Customer")
#         verbose_name_plural = _("Customers")
# 
#     def __str__(self):
#         return self.name
# 
# Path: questions/managers.py
# class QuizManager(models.Manager):
# 
#     def active(self):
#         return self.get_queryset().filter(draft=False)


# Path: questions/models.py
from decimal import Decimal
from django.core.validators import MaxValueValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.utils.encoding import python_2_unicode_compatible
from autoslug import AutoSlugField
from mptt.fields import TreeForeignKey
from mptt.models import MPTTModel
from polymorphic.models import PolymorphicModel
from sorl.thumbnail import ImageField
from core.utils import PathAndRename
from saas.models import Customer
from .managers import QuizManager
        from answers.models import TextAnswer
        from answers.models import EssayAnswer
        from answers.models import MultipleChoiceAnswer
        from answers.models import RatingAnswer
        from answers.models import BooleanAnswer

@python_2_unicode_compatible
class MultipleChoiceQuestion(Question):

    """
        A type of question where the user is presented with a list of options to pick from
        The choices themselves are MultipleChoiceAnswer objects
    """

    class Meta:
        verbose_name = _("Multiple Choice Question")
        verbose_name_plural = _("Multiple Choice Questions")

    def get_answer_class(self):
        return MultipleChoiceAnswer

    def __str__(self):
        return self.title


@python_2_unicode_compatible
class MultipleChoiceOption(models.Model):

    """The answer choices to a multiple choice question"""

    created_on = models.DateTimeField(_("Created on"), auto_now_add=True)
    updated_on = models.DateTimeField(_("Updated on"), auto_now=True)
    question = models.ForeignKey(
        MultipleChoiceQuestion, verbose_name=_("Question"), on_delete=models.CASCADE)
    title = models.CharField(_("Answer"), max_length=300, blank=False, help_text=_(
        "Input the answer as you want it displayed"))

    image = ImageField(_("Image"), upload_to=PathAndRename(