diff --git a/project/controllers/loan.py b/project/controllers/loan.py index 1cc2648dc30b359571689dd21f1456feaf69a745..5d22a5001229e7155fbe9b8134df0a7414d49c14 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 e1d9a98330067e28f117dd2fd202810d694e3770..f7def10190e087967c48b06951b45939939dc512 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 6375046fe438bb3185c053531d9e9d76b2589ed9..29173731e3e397ccadb907bb56e37f0e42f09bef 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();