# Path: search/web/forms.py
# class CourseModelForm(forms.ModelForm):
# 
#     def __init__(self, *args, **kwargs):
#         if kwargs.get('instance'):
#             self.instance = kwargs.get('instance')
#         else:
#             source = kwargs.pop('source')
#             self.base_fields['source'].initial = source.id
#             self.base_fields['language'].initial = 'English'
#             self.instance = None
# 
#         self.base_fields['source'].widget = forms.HiddenInput()
# 
#         self.base_fields['merlot_categories'].widget = django_select2.widgets.Select2MultipleWidget()
#         self.base_fields['merlot_categories'].help_text = "Press Esc key to close the selection box after you've selected all relevant categories."
# 
#         self.base_fields['language'].widget = django_select2.widgets.Select2Widget(choices=LANGUAGE_CHOICES)
#         self.base_fields['tags'].help_text = "Separate tags with commas"
# 
#         self.base_fields['audience'].widget = forms.RadioSelect(choices=PRIMARY_AUDIENCE_CHOICES)
#         self.base_fields['creative_commons'].widget = forms.RadioSelect(choices=YES_NO_UNSURE_CHOICES)
#         self.base_fields['creative_commons_commercial'].widget = forms.RadioSelect(choices=YES_NO_UNSURE_CHOICES)
#         self.base_fields['creative_commons_derivatives'].widget = forms.RadioSelect(choices=CC_DERIV_CHOICES)
# 
#         self.helper = FormHelper()
#         self.helper.form_action = '.'
# 
#         self.helper.layout = Layout(
#             Row(
#                 Field('merlot_ignore'),
#                 Field('title'),
#             )
#         )
# 
#         if self.instance and self.instance.linkurl:
#             self.helper.layout.append(Layout(
#                 Row(
#                     HTML("<a href='%s' target='_blank'>View link</a>" % self.instance.linkurl),
#                     Field('linkurl'),
#                     )
#             ))
#         else:
#             self.helper.layout.append(Layout(
#                 Row(
#                     Field('linkurl')
#                 )
#             ))
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 Field('description'),
#                 Field('language'),
#                 Field('content_medium'),
#                 Field('author'),
#                 Field('tags'),
#             )
#         ))
# 
#         if self.instance and self.instance.categories.count():
#             self.helper.layout.append(Layout(
#                 Row(
#                     HTML("<h4>Legacy categories:</h4>"),
#                     HTML(
#                     """ {%load mptt_tags %}
#                         <p>
#                         {% for node in course.categories.all %}
#                         {{ node.get_ancestors|tree_path:" > " }} > {{ node }}<br />
#                         {% endfor %}
#                         </p>
#                     """)
#                 ))
#             )
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 HTML("<a href='http://www.merlot.org/merlot/categories.htm' target='_blank'>Full Merlot Categories list</a>"),
#                 Field('merlot_categories'),
#             )
#         ))
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 Field('image_url'),
#                 Div(Field('audience'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons_commercial'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons_derivatives'),
#                     css_class="small-8 columns left"),
#             )
#         ))
# 
#         self.helper.layout.append(
#             Row(
#                 Submit('Save', 'save'),
#             css_class="buttons")
#         )
# 
#         super(CourseModelForm, self).__init__(*args, **kwargs)
# 
#     class Meta:
#         model = Course
#         fields = ('title', 'linkurl', 'source', 'description', 'language', 'author', 'merlot_categories',
#                   'tags', 'content_medium', 'merlot_ignore',
#                   'image_url', 'audience',
#                   'creative_commons', 'creative_commons_commercial', 'creative_commons_derivatives',)


import HTMLParser
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from vanilla import ListView, DetailView, FormView
from data.models import Course, Source
from ..forms import CourseModelForm




class SourceCourseListView(ListView):
    model = Course
    template_name = 'web/source_course_list.html'

    def get_queryset(self):
        pk = self.kwargs.get('pk')
        return self.model.objects.filter(source=pk, merlot_present=False, is_404=False).order_by('-merlot_categories')

    def get_context_data(self, **kwargs):
        context = super(SourceCourseListView, self).get_context_data(**kwargs)
        context['source'] = Source.objects.get(pk=self.kwargs.get('pk'))
        
        return context


class CourseActionMixin(object):
    pass


class CourseDetailView(DetailView):
    model = Course
    template_name = 'web/course_detail.html'


class CourseFormAddView(CourseActionMixin, FormView):
    model = Course

# Path: search/web/forms.py
# class CourseModelForm(forms.ModelForm):
# 
#     def __init__(self, *args, **kwargs):
#         if kwargs.get('instance'):
#             self.instance = kwargs.get('instance')
#         else:
#             source = kwargs.pop('source')
#             self.base_fields['source'].initial = source.id
#             self.base_fields['language'].initial = 'English'
#             self.instance = None
# 
#         self.base_fields['source'].widget = forms.HiddenInput()
# 
#         self.base_fields['merlot_categories'].widget = django_select2.widgets.Select2MultipleWidget()
#         self.base_fields['merlot_categories'].help_text = "Press Esc key to close the selection box after you've selected all relevant categories."
# 
#         self.base_fields['language'].widget = django_select2.widgets.Select2Widget(choices=LANGUAGE_CHOICES)
#         self.base_fields['tags'].help_text = "Separate tags with commas"
# 
#         self.base_fields['audience'].widget = forms.RadioSelect(choices=PRIMARY_AUDIENCE_CHOICES)
#         self.base_fields['creative_commons'].widget = forms.RadioSelect(choices=YES_NO_UNSURE_CHOICES)
#         self.base_fields['creative_commons_commercial'].widget = forms.RadioSelect(choices=YES_NO_UNSURE_CHOICES)
#         self.base_fields['creative_commons_derivatives'].widget = forms.RadioSelect(choices=CC_DERIV_CHOICES)
# 
#         self.helper = FormHelper()
#         self.helper.form_action = '.'
# 
#         self.helper.layout = Layout(
#             Row(
#                 Field('merlot_ignore'),
#                 Field('title'),
#             )
#         )
# 
#         if self.instance and self.instance.linkurl:
#             self.helper.layout.append(Layout(
#                 Row(
#                     HTML("<a href='%s' target='_blank'>View link</a>" % self.instance.linkurl),
#                     Field('linkurl'),
#                     )
#             ))
#         else:
#             self.helper.layout.append(Layout(
#                 Row(
#                     Field('linkurl')
#                 )
#             ))
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 Field('description'),
#                 Field('language'),
#                 Field('content_medium'),
#                 Field('author'),
#                 Field('tags'),
#             )
#         ))
# 
#         if self.instance and self.instance.categories.count():
#             self.helper.layout.append(Layout(
#                 Row(
#                     HTML("<h4>Legacy categories:</h4>"),
#                     HTML(
#                     """ {%load mptt_tags %}
#                         <p>
#                         {% for node in course.categories.all %}
#                         {{ node.get_ancestors|tree_path:" > " }} > {{ node }}<br />
#                         {% endfor %}
#                         </p>
#                     """)
#                 ))
#             )
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 HTML("<a href='http://www.merlot.org/merlot/categories.htm' target='_blank'>Full Merlot Categories list</a>"),
#                 Field('merlot_categories'),
#             )
#         ))
# 
#         self.helper.layout.append(Layout(
#             Row(
#                 Field('image_url'),
#                 Div(Field('audience'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons_commercial'),
#                     css_class="small-4 columns"),
#                 Div(Field('creative_commons_derivatives'),
#                     css_class="small-8 columns left"),
#             )
#         ))
# 
#         self.helper.layout.append(
#             Row(
#                 Submit('Save', 'save'),
#             css_class="buttons")
#         )
# 
#         super(CourseModelForm, self).__init__(*args, **kwargs)
# 
#     class Meta:
#         model = Course
#         fields = ('title', 'linkurl', 'source', 'description', 'language', 'author', 'merlot_categories',
#                   'tags', 'content_medium', 'merlot_ignore',
#                   'image_url', 'audience',
#                   'creative_commons', 'creative_commons_commercial', 'creative_commons_derivatives',)


# Path: search/web/views/dashboard.py
import HTMLParser
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from vanilla import ListView, DetailView, FormView
from data.models import Course, Source
from ..forms import CourseModelForm





class SourceCourseListView(ListView):
    model = Course
    template_name = 'web/source_course_list.html'

    def get_queryset(self):
        pk = self.kwargs.get('pk')
        return self.model.objects.filter(source=pk, merlot_present=False, is_404=False).order_by('-merlot_categories')

    def get_context_data(self, **kwargs):
        context = super(SourceCourseListView, self).get_context_data(**kwargs)
        context['source'] = Source.objects.get(pk=self.kwargs.get('pk'))
        
        return context


class CourseActionMixin(object):
    pass


class CourseDetailView(DetailView):
    model = Course
    template_name = 'web/course_detail.html'


class CourseFormAddView(CourseActionMixin, FormView):
    model = Course

    form_class = CourseModelForm