From bc3b28ac13bc0c4c2462814b35dd39876e42717f Mon Sep 17 00:00:00 2001 From: Brian Wood <legion.the.unforgiven@gmail.com> Date: Wed, 23 Apr 2014 21:16:30 -0600 Subject: [PATCH] Added validtaion that return date must be in the futurel --- project/controllers/loan.py | 2 ++ project/templates/library/loanMovie_modal.html | 5 ++++- project/templates/modal_base.html | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/project/controllers/loan.py b/project/controllers/loan.py index 1cc2648..5d22a50 100644 --- a/project/controllers/loan.py +++ b/project/controllers/loan.py @@ -57,6 +57,8 @@ def createLoan(user=None): movie_id = request.form['movie'] if return_date: return_date = datetime.strptime(return_date, '%m/%d/%Y') + if return_date <= datetime.now(): + return jsonify(response='error',message='Return date must be in the future'),404 if not movie_id: return jsonify(response='error',message='Invalid Movie given'),404 diff --git a/project/templates/library/loanMovie_modal.html b/project/templates/library/loanMovie_modal.html index e1d9a98..f7def10 100644 --- a/project/templates/library/loanMovie_modal.html +++ b/project/templates/library/loanMovie_modal.html @@ -30,7 +30,10 @@ rules: { required: true, email: true }, - date: "required", + date: { + required: true, + greaterThanToday: true + }, movie: "required" } {% endblock %} diff --git a/project/templates/modal_base.html b/project/templates/modal_base.html index 6375046..2917373 100644 --- a/project/templates/modal_base.html +++ b/project/templates/modal_base.html @@ -35,6 +35,11 @@ $(function(){ var $form = $(document.getElementById("{{ self.form_id() }}")); var $acceptButton = $(document.getElementById("{{ self.form_id() }}-accept")); + jQuery.validator.addMethod("greaterThanToday", function(value, element, params) { + if (!/Invalid|NaN/.test(new Date(value))) { + return new Date(value) > new Date(); + } + },'Must be a future date'); $acceptButton.on('click',function(event){ event.stopPropagation(); event.preventDefault(); -- GitLab