# -*- coding:utf8 -*-
# Copyright (C) 2012 FinalsClub Foundation
+ from django.conf import settings
from django.forms import ModelForm
+ from django.forms import CharField
+from ajax_select.fields import AutoCompleteSelectField
+from ajax_select.fields import AutoCompleteSelectWidget
+from ajax_select_cascade.fields import AutoCompleteDependentSelectField
+from ajax_select_cascade.fields import AutoCompleteDependentSelectWidget
+
from karmaworld.apps.courses.models import Course
class CourseForm(ModelForm):
+ school = AutoCompleteSelectField(
+ 'school',
+ widget=AutoCompleteSelectWidget(
+ 'school',
+ attrs={'id': 'dom_autocomplete_school'}
+ )
+ )
+ department = AutoCompleteDependentSelectField(
+ 'dept_given_school',
+ widget=AutoCompleteDependentSelectWidget(
+ 'dept_given_school',
+ attrs={'data-upstream-id': 'dom_autocomplete_school'},
+ )
+ )
+
+ def __init__(self, *args, **kwargs):
+ """ Add a dynamically named field. """
+ super(CourseForm, self).__init__(*args, **kwargs)
+ self.fields[settings.HONEYPOT_FIELD_NAME] = CharField(required=False)
+
class Meta:
model = Course
- fields = ('name', 'school', 'url', 'instructor_name', \
- 'instructor_email')
+ # order the fields
+ fields = ('school', 'department', 'name', 'instructor_name',
+ 'instructor_email', 'url')
+
+ def clean(self, *args, **kwargs):
+ """ Additional form validation. """
+
+ # Call ModelFormMixin or whoever normally cleans house.
+ cleaned_data = super(CourseForm, self).clean(*args, **kwargs)
+
+ # parts of this code borrow from
+ # https://github.com/sunlightlabs/django-honeypot
+ hfn = settings.HONEYPOT_FIELD_NAME
+ formhoneypot = cleaned_data.get(hfn, None)
+ if formhoneypot and (formhoneypot != settings.HONEYPOT_VALUE):
+ # Highlight a failure to follow instructions.
+ # When the template dynamically generates the form, replace
+ # 'honeypot' with hfn
+ self._errors['honeypot'] = [u'You did not follow directions.']
+ del cleaned_data[hfn]
+ return cleaned_data
from django.db import models
from django.utils.text import slugify
+ from django.core.urlresolvers import reverse
from karmaworld.settings.manual_unique_together import auto_add_check_unique_together
+from ajax_select import LookupChannel
+from ajax_select_cascade import DependentLookupChannel
+from ajax_select_cascade import register_channel_name
+
+from karmaworld.utils.ajax_selects import register_channel_name
class SchoolManager(models.Manager):
<form method="POST" action="{% url 'home' %}">
{% csrf_token %}
+ {% for error in course_form.non_field_errors %}
<div class="row">
<div class="small-12 columns">
- {{ course_form.non_field_errors }}
+ {{ error }}
</div>
</div>
+ {% endfor %}
- <div class="row">
- <div class="small-12 columns">
- <legend>
- School
- {% for error in course_form.school.errors %}
- <span style="color:red">
- {{ error }}
- </span>
- {% endfor %}
- </legend>
- <div>
- <input id="str_school" class="" type="text" name="str_school" placeholder="Select a school"/>
- <input id="id_school" name="school" type='hidden'/>
- </div>
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns">
- <legend>Course Name:
- {% if course_form.name.errors %}
- <span style="color:red">
- {{ course_form.name.errors }}
- </span>
- {% endif %}
- </legend>
- <input id="id_name" class="" type="text" name="name" maxlength="255" />
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns">
- <legend>Do not fill in this field:
- {% for error in honeypot_errors %}
- <span style="color:red">
- {{ error }}
- </span>
- {% endfor %}
- </legend>
- <input type="text" name="{{HONEYPOT_FIELD_NAME}}" value="{{HONEYPOT_VALUE}}" />
- </div>
- </div>
-
- <div class="row">
- <div class="small-12 columns large-6">
- <legend class="">
- Instructor Name:
- {% for error in course_form.instructor_name.errors %}
- <span style="color:red">
- {{ error }}
- </span>
- {% endfor %}
- </legend><!-- -->
- <input id="id_instructor_name" class="" type="text" name="instructor_name" maxlength="75" />
- </div>
-
- <div class="small-12 columns large-6">
- <legend class="">
- Instructor Email:
- {% for error in course_form.instructor_email.errors %}
- <span style="color:red">
- {{ error }}
- </span>
- {% endfor %}
- </legend>
- <input id="id_instructor_email" class="" type="text" name="instructor_email" maxlength="75" />
- </div><!-- -->
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns">
- <legend>Course url:
- {% for error in course_form.url.errors %}
- <span style="color:red">
- {{ error }}
- </span>
- {% endfor %}
- </legend>
- <input id="id_url" class="" type="text" name="url" maxlength="255" />
- </div>
- </div> <!-- .row -->
+ {{ course_form }}
<div class="row">
<div class="small-4 large-8 columns small-centered text-center">
from karmaworld.apps.courses.views import AboutView, flag_course, edit_course
from karmaworld.apps.courses.views import CourseDetailView
from karmaworld.apps.courses.views import CourseListView
-from karmaworld.apps.courses.views import school_list
from karmaworld.apps.courses.views import school_course_list
from karmaworld.apps.courses.views import school_course_instructor_list
- from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView, flag_note, downloaded_note
+ from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView, flag_note, downloaded_note, edit_note_tags
from karmaworld.apps.notes.views import RawNoteDetailView
- from karmaworld.apps.notes.views import PDFView
from karmaworld.apps.moderation import moderator
from karmaworld.apps.document_upload.views import save_fp_upload
from karmaworld.apps.users.views import ProfileView