diff --git a/project/controllers/loan.py b/project/controllers/loan.py index 1644c61516797c1c06e0ca2799f6e973f2596964..6015d7a678b48b80dd26cc2d2f2fe6d7f336ebdc 100644 --- a/project/controllers/loan.py +++ b/project/controllers/loan.py @@ -13,7 +13,6 @@ def loaned(user=None): def reminderEmail(user=None): import smtplib from_addr = user.email - to_addr = request.form['email'] subject = request.form['subject'] or "Movie Return Reminder" movie_id = request.form['movie'] if not movie_id: @@ -25,7 +24,9 @@ def reminderEmail(user=None): loan = movie.getLoan(user) if not loan: return jsonify(response='error',message='Invalid Movie given'),404 - message = request.form['message'] or "The movie %s, borrowed form %s is due on %s" % (movie.title, user.email, loan.expected_return_date) + to_addr = loan.borrower_email + + message = request.form['message'] or "The movie %s, that you borrowed from %s has asked that you return the movie by %s" % (movie.title, user.email, loan.expected_return_date.strftime('%m-%d-%Y')) login = app.config['SMTP_USER'] password = app.config['SMTP_PASSWORD'] smtpserver= app.config['SMTP_SERVER'] diff --git a/project/controllers/movies.py b/project/controllers/movies.py index 07162632c13e4472ae7affb3960d1ac3aa8228e1..a945f30f0496bb0e8d73538974e138c61d742c4e 100644 --- a/project/controllers/movies.py +++ b/project/controllers/movies.py @@ -5,8 +5,14 @@ from flask.ext.wtf import Form, TextField, validators @app.route('/movies') -def movies(): - return render_template('movies/master.html') +@security('user') +def movies(user=None): + from project.model.Movie import Movie + from project.model.Library import Library + library = Library.objects(user=user,name="Master",unit='Movie').first() + if not library: + return render_template('404.html',message='Unable to find given Library',user=user),404 + return render_template('library/library.html',library=library,user=user) @app.route('/movies/<movieId>') def movie_item(movieId): diff --git a/project/templates/library/library.html b/project/templates/library/library.html index fd6595843946671f91cc7fe1688647c51ca5ae7d..25c00e95a2a9f6748a83f4864e1fd0358db09a87 100644 --- a/project/templates/library/library.html +++ b/project/templates/library/library.html @@ -32,8 +32,10 @@ {% if loan == None %} <button type="button" class="btn btn-default btn-small lend-movie" data-toggle="modal" data-target="#loan-form" data-id='{{ movie.id }}'>Lend</button> {% else %} - This movie is loaned to {{ loan.email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }} + Loaned to: {{ loan.borrower_email }}<br/> + Due back: {{ loan.expected_return_date.strftime('%m-%d-%Y') }} <button type="button" class="btn btn-default btn-small return-movie" data-toggle="modal" data-target="#return-form" data-id='{{ movie.id }}'>Return</button> + <button type="button" class="btn btn-default btn-small reminder" data-toggle="modal" data-target="#reminder-form" data-id='{{ movie.id }}'>Reminder</button> {% endif %} {% if library.name != "Master" or loan == None %} <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button> @@ -43,7 +45,7 @@ <td> <div class='rating-text'style="">{{ movie.popularity }}</div> <div class="rating"> - {% set rating = 10 - movie.popularity|int %} + {% set rating = 10 - movie.popularity|round %} {% for i in range(10) %} {% if rating == i %} <span class="vert rated">☆</span> @@ -61,8 +63,10 @@ {% if loan == None %} <button type="button" class="btn btn-default btn-small lend-movie" data-toggle="modal" data-target="#loan-form" data-id='{{ movie.id }}'>Lend</button> {% else %} - This movie is loaned to {{ loan.borrower_email }} and is due back on {{ loan.expected_return_date.strftime('%m-%d-%Y') }} + Loaned to: {{ loan.borrower_email }}<br/> + Due back: {{ loan.expected_return_date.strftime('%m-%d-%Y') }} <button type="button" class="btn btn-default btn-small return-movie" data-toggle="modal" data-target="#return-form" data-id='{{ movie.id }}'>Return</button> + <button type="button" class="btn btn-default btn-small reminder" data-toggle="modal" data-target="#reminder-form" data-id='{{ movie.id }}'>Reminder</button> {% endif %} {% if library.name != "Master" or loan == None %} <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button> @@ -160,4 +164,5 @@ {% block modals %} {% include 'library/addmovie_modal.html' %} {% include 'library/loanMovie_modal.html' %} + {% include 'library/reminder_modal.html' %} {% endblock %} \ No newline at end of file diff --git a/project/templates/library/libraryItem.html b/project/templates/library/libraryItem.html index a2722d017f7ea0b59c351acd3ba00bb9166c8277..0e583855a0646b3c7e8f7c513ac783193c744b9e 100644 --- a/project/templates/library/libraryItem.html +++ b/project/templates/library/libraryItem.html @@ -1,18 +1,30 @@ {% extends "usernav.html" %} {% block content %} +{% set loan = item.getLoan(user) %} <div class="col-sm-12"> <div class="row"> <div class="col-xs-12 col-sm-3 col-md-2"> <img src="{{ item.poster }}" style="max-width: 180px;" alt="{{ item.title }}"> <h3>{{ item.title }}</h3> - <button type="button" class="btn btn-warning btn-sm remove-movie" data-id='{{ index }}'> - <span class="glyphicon glyphicon-remove"></span> Remove - </button> + <div class="btn-group"> + {% if loan == None %} + <button type="button" class="btn btn-default btn-small lend-movie" data-toggle="modal" data-target="#loan-form" data-id='{{ item.id }}'>Lend</button> + {% else %} + Loaned to: {{ loan.borrower_email }}<br/> + Due back: {{ loan.expected_return_date.strftime('%m-%d-%Y') }} + <button type="button" class="btn btn-default btn-small return-movie" data-toggle="modal" data-target="#return-form" data-id='{{ item.id }}'>Return</button> + <button type="button" class="btn btn-default btn-small reminder" data-toggle="modal" data-target="#reminder-form" data-id='{{ item.id }}'>Reminder</button> + {% endif %} + {% if library.name != "Master" or loan == None %} + <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ index }}'>Remove</button> + {% endif %} + + </div> </div> <div class="col-md-1 hidden-sm"> <div class="rating-text">{{ item.popularity }}</div> <div class="rating"> - {% set rating = 10 - item.popularity|int %} + {% set rating = 10 - item.popularity|round %} {% for i in range(10) %} {% if rating == i %} <span class="vert rated">☆</span> @@ -22,7 +34,7 @@ {% endfor %} </div> </div> - <div class="col-xs-12 col-sm-4 col-md-4"> + <div class="col-xs-12 col-sm-4 col-md-4 well"> <dl> <dt>Director</dt> <dd>{{ item.director|default('No Director found')}}</dd> @@ -83,6 +95,42 @@ } }); + + var returnPath = '{{ url_for("returnMovie") }}'; + $('.return-movie').on('click',function(event){ + var movie_id = $(this).data('id'); + var message = "Are you sure you want return this movie? "; + if(confirm(message)){ + event.stopPropagation(); + event.preventDefault(); + $.ajax({ + url: returnPath, + data: {id:movie_id}, + method: 'POST', + success: function(data,status,jqXHR){ + if(data['response'] == 'success'){ + if(data['type'] == 'redirect'){ + window.document.location = data['path']; + } else if (data['type'] == 'reload') { + window.document.location.reload(); + } + } + }, + error: function(jqXHR, textStatus, errorThrown){ + response = jqXHR.responseJSON; + if('message' in response){ + alert(response['message']); + } + } + }); + + } + }); }); </script> +{% endblock %} + +{% block modals %} + {% include 'library/loanMovie_modal.html' %} + {% include 'library/reminder_modal.html' %} {% endblock %} \ No newline at end of file diff --git a/project/templates/library/reminder_modal.html b/project/templates/library/reminder_modal.html new file mode 100644 index 0000000000000000000000000000000000000000..1f359bcc1e291e2baafe45a69f917c2a4f59ea1d --- /dev/null +++ b/project/templates/library/reminder_modal.html @@ -0,0 +1,66 @@ +{% extends "modal_base.html" %} +{% block modal_title %} Reminder Email {% endblock %} +{% block modal_content %} +<form class="form-horizontal" id="reminder" role="form" method="post" action="{{ url_for('reminderEmail') }}"> + <div style="margin-left:12%" class="form-group"> + <div class="col-xs-9 col-md-6 checkbox"> + <label> + <input id="custom" type="checkbox"> Custom Message? + </label> + </div> + </div> + <div class="form-group message-area"> + <label for="subject" class="col-sm-3 control-label">Subject</label> + <div class="col-xs-9 col-md-6"> + <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject"> + </div> + </div> + <div class="form-group message-area"> + <label for="message" class="col-sm-3 control-label">Message</label> + <div class="col-xs-9 col-md-6"> + <textarea class="form-control" id="message" name="message" placeholder="Password"></textarea> + </div> + </div> + <div class="form-group"> + <div class="col-xs-9 col-md-6"> + <input type="hidden" class="hidden" name="movie" /> + </div> + </div> + </form> +{% endblock %} +{% block accept_button_text %}Send{% endblock %} +{% block ajax_url %}'{{ url_for('reminderEmail') }}'{% endblock %} +{% block form_id %}reminder{% endblock %} +{% block validation_rules %} +rules: { + subject: { + required: { depends: 'input#custom:checked' } + }, + message: { + required: { depends: 'input#custom:checked' } + } +} +{% endblock %} +{% block additional_javascripts %} + <script> + $(function(){ + var $custom = $(document.getElementById("custom")); + var $messageArea = $(".message-area"); + $custom.on('change',function(){ + if($custom.is(':checked')){ + $messageArea.show(); + } else { + $messageArea.hide(); + } + }); + }); + $(".reminder").on('click', function (event) { + event.stopPropagation(); + event.preventDefault(); + $(document.getElementById("custom")).change(); + modal = $(this).data('target'); + $(modal).modal('toggle'); + $(".modal-body input[name='movie']").val( $(this).data('id')); + }); + </script> +{% endblock %} \ No newline at end of file