from django.contrib import admin
from .models import AnswerMarks, Long, LongSeries, LongSeriesImage, LongCreationDefault, Exam, UserAnswer

from django.forms import ModelForm

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

from tinymce.widgets import TinyMCE

# from generic.models import Examination, Sign, Site, Condition
#from generic.models import Examination, Sign, Condition

# Register your models here.
# admin.site.register(Examination)
# admin.site.register(Site)
admin.site.register(LongCreationDefault)
admin.site.register(LongSeriesImage)
admin.site.register(UserAnswer)
admin.site.register(AnswerMarks)


#class LongImageInline(admin.TabularInline):
#    model = LongSeries.long.through
#    extra = 1


#    readonly_fields = [
#        "image_tag",
#    ]


class ExamInline(admin.TabularInline):
    model = Long.exams.through
    extra = 1


class LongAdminForm(ModelForm):
    class Meta:
        model = Long

        fields = [
            "description",
            "history",
            #"sign",
            "feedback",
            "mark_scheme",
            "model_observations",
            "model_interpretation",
            "model_principle_diagnosis",
            "model_differential_diagnosis",
            "model_management",
            "author",
            "series",
        ]

        widgets = {
            # "normal": RadioSelect(
            # choices=[(True, 'Yes'),
            #     (False, 'No')])
            "feedback" : TinyMCE(attrs={'cols': 80, 'rows': 30}),
            "mark_scheme" : TinyMCE(attrs={'cols': 80, 'rows': 30}),
        }

class LongAdmin(VersionAdmin):
    form = LongAdminForm

    save_on_top = True
    save_as = True
    view_on_site = True

    inlines = [
        #LongImageInline,
        ExamInline,
    ]


admin.site.register(Long, LongAdmin)

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

class LongSeriesAdmin(VersionAdmin):
    pass

admin.site.register(LongSeries, LongSeriesAdmin)

admin.site.register(Exam, ExamAdmin)

#@admin.register(AnswerMarks)
#class AnswerMarksAdmin(admin.ModelAdmin):
#    """Foo admin."""
#
#    fields = ["score", "mark_reason", "candidate_feedback", "marker"]
#    list_display = ('name', 'get_bars')
#    search_fields = ('name',)
#
#    def get_user_answer(self, obj):
#        return obj.user_answer.first()