# Copyright 2012, Cercle Informatique. All rights reserved.

from djangbone.views import BackboneAPIView
from course.models import Course, CourseInfo
from course.forms import EditWikiForm
from profile.models import Profile


class CourseBone(BackboneAPIView):
    base_queryset = Course.objects.all()
    serialize_fields = ('id', 'slug', 'name', 'description', 'infos')


class WikiBone(BackboneAPIView):
    base_queryset = CourseInfo.objects.all()
    serialize_fields = ('id', 'user', 'infos', 'date', 'prev')
    edit_form_class = EditWikiForm

    def serialize_qs(self, queryset, single_object=False):
        # for simplicy, I assume that this we will always return only one thread
        output = self.base_queryset.values()[0]
        output["user"] = Profile.objects.filter(id=self.base_queryset[0].user.id).values()[0]
        json_output = self.json_encoder.encode(output)
        return json_output
