Commits

Luke Plant committed 9b151f9

Added client side validation of sermon file name and help text for admin.

  • Participants
  • Parent commits 88f9b64

Comments (0)

Files changed (2)

File sermons/models.py

 
 
 class Sermon(models.Model):
-    sermon = models.FileField(upload_to=SERMONS_PATH, max_length=255)
+    sermon = models.FileField(upload_to=SERMONS_PATH, max_length=255,
+                              help_text="""The file name must be in the form:<br/>
+&nbsp;&nbsp;<code>YYYY-MM-DD HHmm Speaker Name - Title - Passage.mp3</code><br/>
+For example:<br/>
+&nbsp;&nbsp;<code>2011-06-26 1700 Joe Bloggs - In the beginning - Genesis 1v1-2.mp3</code><br/>
+<br/>
+Title and Passage are optional.
+""")
     speaker = models.ForeignKey(Speaker)
     title = models.CharField(max_length=255, blank=True)
     bible_book = models.CharField(max_length=20, choices=BIBLE_BOOKS_CHOICES, blank=True)

File sermons/templates/admin/sermons/sermon/change_form.html

            $('input[name="_save"]').hide();
        }
 
+       $('input[name="_continue"]').click(function(ev) {
+           var fname = $('#id_sermon').val();
+           // Get filename component, assuming '/' or '\' might be
+           // path separators.
+           fname = fname.split('\\').pop().split('/').pop();
+           var parts = fname.match(/^\d{4}-\d{2}-\d{2} \d{2}\d{2} .+ .+/);
+           if (parts == null) {
+               ev.preventDefault();
+               alert("The file name is not in the required format, please rename it. Thanks!");
+               return;
+           }
+
+           // Javascript's Date object is full of fail, so this is the best we
+           // can reasonably do, short of an AJAX call.
+
+       });
+
     });
 })(django.jQuery);
 </script>