# Path: core/mixins.py
# class AdminMixin(object):
# 
#     """
#     Restricts views to only admin users
#     """
# 
#     def dispatch(self, *args, **kwargs):
#         if not self.request.user.is_authenticated():
#             messages.add_message(
#                 self.request, messages.WARNING, _('Please log in'))
#             return redirect('dashboard')
#         if not self.request.user.userprofile.is_admin:
#             messages.add_message(
#                 self.request, messages.WARNING, _('Sorry, you do not have access to that section'))
#             return redirect('dashboard')
#         return super(AdminMixin, self).dispatch(*args, **kwargs)
# 
# Path: answers/models.py
# class Answer(PolymorphicModel):
#     class Meta:
# class TextAnswer(Answer):
#     class Meta:
# class EssayAnswer(Answer):
#     class Meta:
# class MultipleChoiceAnswer(Answer):
#     class Meta:
# class MultipleChoiceOtherAnswer(models.Model):
#     class Meta:
# class RatingAnswer(Answer):
#     class Meta:
# class BooleanAnswer(Answer):
#     class Meta:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     VERY_POOR = 1
#     POOR = 2
#     AVERAGE = 3
#     GOOD = 4
#     VERY_GOOD = 5
#     RATING_CHOICES = (
#         (VERY_POOR, _('Strongly Disagree')),
#         (POOR, _('Disagree')),
#         (AVERAGE, _('Neither Agree Nor Disagree')),
#         (GOOD, _("Agree")),
#         (VERY_GOOD, _("Strongly Agree")),
#     )


from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from django.core.urlresolvers import reverse_lazy, reverse
from django.utils.translation import ugettext as _
from django.utils.html import format_html
from datatableview.views import DatatableView
from core.mixins import AdminMixin
from answers.models import Sitting
from answers.forms import SittingForm




class SittingDatatableView(AdminMixin, DatatableView):
    """
    Allows you to manage sittings
    """

    model = Sitting
    template_name = "answers/sitting_list.html"
    datatable_options = {
        'structure_template': "datatableview/bootstrap_structure.html",
        'columns': [
            'title',
            (_("Actions"), 'id', 'get_actions'),
        ],
        'search_fields': ['title'],
        'unsortable_columns': ['id'],
    }

    def get_actions(self, instance, *args, **kwargs):
        return format_html(
            '<a href="{}">Edit</a>', reverse(
                'answers:sitting_edit', args=[instance.pk])
        )


class SittingUpdate(AdminMixin, UpdateView):

# Path: core/mixins.py
# class AdminMixin(object):
# 
#     """
#     Restricts views to only admin users
#     """
# 
#     def dispatch(self, *args, **kwargs):
#         if not self.request.user.is_authenticated():
#             messages.add_message(
#                 self.request, messages.WARNING, _('Please log in'))
#             return redirect('dashboard')
#         if not self.request.user.userprofile.is_admin:
#             messages.add_message(
#                 self.request, messages.WARNING, _('Sorry, you do not have access to that section'))
#             return redirect('dashboard')
#         return super(AdminMixin, self).dispatch(*args, **kwargs)
# 
# Path: answers/models.py
# class Answer(PolymorphicModel):
#     class Meta:
# class TextAnswer(Answer):
#     class Meta:
# class EssayAnswer(Answer):
#     class Meta:
# class MultipleChoiceAnswer(Answer):
#     class Meta:
# class MultipleChoiceOtherAnswer(models.Model):
#     class Meta:
# class RatingAnswer(Answer):
#     class Meta:
# class BooleanAnswer(Answer):
#     class Meta:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     VERY_POOR = 1
#     POOR = 2
#     AVERAGE = 3
#     GOOD = 4
#     VERY_GOOD = 5
#     RATING_CHOICES = (
#         (VERY_POOR, _('Strongly Disagree')),
#         (POOR, _('Disagree')),
#         (AVERAGE, _('Neither Agree Nor Disagree')),
#         (GOOD, _("Agree")),
#         (VERY_GOOD, _("Strongly Agree")),
#     )


# Path: answers/views.py
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from django.core.urlresolvers import reverse_lazy, reverse
from django.utils.translation import ugettext as _
from django.utils.html import format_html
from datatableview.views import DatatableView
from core.mixins import AdminMixin
from answers.models import Sitting
from answers.forms import SittingForm





class SittingDatatableView(AdminMixin, DatatableView):
    """
    Allows you to manage sittings
    """

    model = Sitting
    template_name = "answers/sitting_list.html"
    datatable_options = {
        'structure_template': "datatableview/bootstrap_structure.html",
        'columns': [
            'title',
            (_("Actions"), 'id', 'get_actions'),
        ],
        'search_fields': ['title'],
        'unsortable_columns': ['id'],
    }

    def get_actions(self, instance, *args, **kwargs):
        return format_html(
            '<a href="{}">Edit</a>', reverse(
                'answers:sitting_edit', args=[instance.pk])
        )


class SittingUpdate(AdminMixin, UpdateView):

    model = Sitting