From: Jacob Hilker Date: Sun, 2 Feb 2014 20:42:29 +0000 (-0500) Subject: add uniqueness validation on name and school so we dont get a 500 error when this... X-Git-Tag: release-20150131~178^2~6 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a5cd4a9adb074cb982075ba62504bc7735531958;p=oweals%2Fkarmaworld.git add uniqueness validation on name and school so we dont get a 500 error when this occurs --- diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 8619553..ef86dc1 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -231,6 +231,7 @@ class Course(models.Model): class Meta: ordering = ['-file_count', 'school', 'name'] unique_together = ('name', 'department') + unique_together = ('name', 'school') verbose_name = 'course' verbose_name_plural = 'courses' diff --git a/karmaworld/assets/js/course-detail.js b/karmaworld/assets/js/course-detail.js index 342338c..0149281 100644 --- a/karmaworld/assets/js/course-detail.js +++ b/karmaworld/assets/js/course-detail.js @@ -34,7 +34,7 @@ $(function() { // on both the client and server side $('#edit-course-form').slideUp(); $('.validation_error').remove() - $('#course_form_errors').text(''); + $('#course_form_errors').empty(); $('#course_name').text(data.fields.name); $('#course_instructor_name').text(data.fields.instructor_name); @@ -65,6 +65,13 @@ $(function() { if (!errors) { $('#course_form_errors').text(json.message); } else { + // Ugly, be works. Could look into backbone or something similar to make it cleaner. + if (errors.__all__) { + $.each(errors.__all__, function(index, value) { + $('#course_form_errors').append($('', { class: 'validation_error', text: value })); + }); + } + if (errors.instructor_email) { $.each(errors.instructor_email, function(index, value) { $('#id_instructor_email').parent().children('legend').append($('', { class: 'validation_error', text: value })); diff --git a/karmaworld/templates/courses/course_detail.html b/karmaworld/templates/courses/course_detail.html index 3a5ab7b..356a81c 100644 --- a/karmaworld/templates/courses/course_detail.html +++ b/karmaworld/templates/courses/course_detail.html @@ -108,7 +108,7 @@ -