from django.contrib import admin

# Register your models here.
from .models import Question, Exam, UserAnswer, Category

from django.forms import ModelForm

from reversion.admin import VersionAdmin
from django.forms.widgets import RadioSelect

from tinymce.widgets import TinyMCE
class ExamInline(admin.TabularInline):
    model = Question.exams.through
    extra = 1

class QuestionAdminForm(ModelForm):
    class Meta:
        model = Question

        exclude = []

        widgets = {
            # "normal": RadioSelect(
            # choices=[(True, 'Yes'),
            #     (False, 'No')])
            "stem" : TinyMCE(attrs={'cols': 80, 'rows': 30}),
            "feedback" : TinyMCE(attrs={'cols': 80, 'rows': 30}),
            "a_answer" : TinyMCE(attrs={'cols': 80, 'rows': 5}, mce_attrs={'height': 140}),
            "a_feedback" : TinyMCE(attrs={'cols': 80, 'rows': 5}, mce_attrs={'height': 140}),
            "b_answer" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "c_answer" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "d_answer" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "e_answer" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "b_feedback" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "c_feedback" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "d_feedback" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
            "e_feedback" : TinyMCE(attrs={'cols': 80, 'rows': 4}, mce_attrs={'height': 140}),
        }


class QuestionAdmin(VersionAdmin):
    form = QuestionAdminForm

    save_on_top = True
    save_as = True
    view_on_site = True

    inlines = [
        ExamInline,
    ]

class ExamAdmin(VersionAdmin, admin.ModelAdmin):
    save_as = True

admin.site.register(Category)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Exam, ExamAdmin)
class UserAnswerAdmin(admin.ModelAdmin):
    exclude = []
    readonly_fields = ["created", "updated"]

admin.site.register(UserAnswer, UserAnswerAdmin)