add uniqueness validation on name and school so we dont get a 500 error when this...
authorJacob Hilker <hilker.j@gmail.com>
Sun, 2 Feb 2014 20:42:29 +0000 (15:42 -0500)
committerJacob Hilker <hilker.j@gmail.com>
Sun, 2 Feb 2014 20:42:29 +0000 (15:42 -0500)
karmaworld/apps/courses/models.py
karmaworld/assets/js/course-detail.js
karmaworld/templates/courses/course_detail.html

index 86195539589c1b93b37b0f3976caa5f38dfd0636..ef86dc1c96a2707f98e3fcf00e2891fcd0286702 100644 (file)
@@ -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'
 
index 342338c4332d852c92024555b216a078340b2f89..0149281774748c301329d6c7976b6e013c46d71e 100644 (file)
@@ -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($('<span>', { class: 'validation_error', text: value }));
+            });
+          }
+
           if (errors.instructor_email) {
             $.each(errors.instructor_email, function(index, value) {
               $('#id_instructor_email').parent().children('legend').append($('<span>', { class: 'validation_error', text: value }));
index 3a5ab7b763fcb66299887ce05b96efc0daceb49c..356a81c7eed2176de41fa675fb58b31d9fc8cc74 100644 (file)
           </div>
         </div>
 
-        <div class="row hidden">
+        <div class="row hide">
           <div class="small-12 columns">
             <legend>School</legend>
             <div>