From: Bryan Date: Wed, 26 Feb 2014 06:12:05 +0000 (-0500) Subject: merging old commit with current master X-Git-Tag: release-20150131~163 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bc9f96fafc828a096d8b3d78b4e0c0a233524cf6;p=oweals%2Fkarmaworld.git merging old commit with current master --- bc9f96fafc828a096d8b3d78b4e0c0a233524cf6 diff --cc karmaworld/apps/courses/forms.py index db186bb,35f3a6c..e2642d3 --- a/karmaworld/apps/courses/forms.py +++ b/karmaworld/apps/courses/forms.py @@@ -2,32 -2,38 +2,58 @@@ # -*- 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 diff --cc karmaworld/apps/courses/models.py index 10f7770,573bfe4..6ef836c --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@@ -13,12 -13,8 +13,13 @@@ import reversio 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): diff --cc karmaworld/templates/partial/add_course.html index 2d43e5e,47af638..7b52b58 --- a/karmaworld/templates/partial/add_course.html +++ b/karmaworld/templates/partial/add_course.html @@@ -13,13 -13,95 +13,15 @@@
{% csrf_token %} + {% for error in course_form.non_field_errors %}
- {{ course_form.non_field_errors }} + {{ error }}
+ {% endfor %} -
-
- - School - {% for error in course_form.school.errors %} - - {{ error }} - - {% endfor %} - -
- - -
-
-
- -
-
- Course Name: - {% if course_form.name.errors %} - - {{ course_form.name.errors }} - - {% endif %} - - -
-
- -
-
- Do not fill in this field: - {% for error in honeypot_errors %} - - {{ error }} - - {% endfor %} - - -
-
- -
-
- - Instructor Name: - {% for error in course_form.instructor_name.errors %} - - {{ error }} - - {% endfor %} - - -
- -
- - Instructor Email: - {% for error in course_form.instructor_email.errors %} - - {{ error }} - - {% endfor %} - - -
-
- -
-
- Course url: - {% for error in course_form.url.errors %} - - {{ error }} - - {% endfor %} - - -
-
+ {{ course_form }}
diff --cc karmaworld/urls.py index 493e1e3,6777de8..7cf32d1 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@@ -12,11 -12,11 +12,10 @@@ from karmaworld.apps.courses.models imp 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