Skip to content
Snippets Groups Projects
Commit e1614111 authored by Nathan Bills's avatar Nathan Bills
Browse files

Merge branch 'develop' of https://github.com/ndbills/MyMovieLibrary into develop

parents e933e60c c8c9ccd9
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ def loaned(user=None): ...@@ -13,7 +13,6 @@ def loaned(user=None):
def reminderEmail(user=None): def reminderEmail(user=None):
import smtplib import smtplib
from_addr = user.email from_addr = user.email
to_addr = request.form['email']
subject = request.form['subject'] or "Movie Return Reminder" subject = request.form['subject'] or "Movie Return Reminder"
movie_id = request.form['movie'] movie_id = request.form['movie']
if not movie_id: if not movie_id:
...@@ -25,7 +24,9 @@ def reminderEmail(user=None): ...@@ -25,7 +24,9 @@ def reminderEmail(user=None):
loan = movie.getLoan(user) loan = movie.getLoan(user)
if not loan: if not loan:
return jsonify(response='error',message='Invalid Movie given'),404 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'] login = app.config['SMTP_USER']
password = app.config['SMTP_PASSWORD'] password = app.config['SMTP_PASSWORD']
smtpserver= app.config['SMTP_SERVER'] smtpserver= app.config['SMTP_SERVER']
......
...@@ -5,8 +5,14 @@ from flask.ext.wtf import Form, TextField, validators ...@@ -5,8 +5,14 @@ from flask.ext.wtf import Form, TextField, validators
@app.route('/movies') @app.route('/movies')
def movies(): @security('user')
return render_template('movies/master.html') 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>') @app.route('/movies/<movieId>')
def movie_item(movieId): def movie_item(movieId):
......
...@@ -32,8 +32,10 @@ ...@@ -32,8 +32,10 @@
{% if loan == None %} {% 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> <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 %} {% 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 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 %} {% endif %}
{% if library.name != "Master" or loan == None %} {% if library.name != "Master" or loan == None %}
<button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button> <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button>
...@@ -43,7 +45,7 @@ ...@@ -43,7 +45,7 @@
<td> <td>
<div class='rating-text'style="">{{ movie.popularity }}</div> <div class='rating-text'style="">{{ movie.popularity }}</div>
<div class="rating"> <div class="rating">
{% set rating = 10 - movie.popularity|int %} {% set rating = 10 - movie.popularity|round %}
{% for i in range(10) %} {% for i in range(10) %}
{% if rating == i %} {% if rating == i %}
<span class="vert rated"></span> <span class="vert rated"></span>
...@@ -61,8 +63,10 @@ ...@@ -61,8 +63,10 @@
{% if loan == None %} {% 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> <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 %} {% 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 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 %} {% endif %}
{% if library.name != "Master" or loan == None %} {% if library.name != "Master" or loan == None %}
<button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button> <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button>
...@@ -160,4 +164,5 @@ ...@@ -160,4 +164,5 @@
{% block modals %} {% block modals %}
{% include 'library/addmovie_modal.html' %} {% include 'library/addmovie_modal.html' %}
{% include 'library/loanMovie_modal.html' %} {% include 'library/loanMovie_modal.html' %}
{% include 'library/reminder_modal.html' %}
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends "usernav.html" %} {% extends "usernav.html" %}
{% block content %} {% block content %}
{% set loan = item.getLoan(user) %}
<div class="col-sm-12"> <div class="col-sm-12">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-3 col-md-2"> <div class="col-xs-12 col-sm-3 col-md-2">
<img src="{{ item.poster }}" style="max-width: 180px;" alt="{{ item.title }}"> <img src="{{ item.poster }}" style="max-width: 180px;" alt="{{ item.title }}">
<h3>{{ item.title }}</h3> <h3>{{ item.title }}</h3>
<button type="button" class="btn btn-warning btn-sm remove-movie" data-id='{{ index }}'> <div class="btn-group">
<span class="glyphicon glyphicon-remove"></span> Remove {% if loan == None %}
</button> <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>
<div class="col-md-1 hidden-sm"> <div class="col-md-1 hidden-sm">
<div class="rating-text">{{ item.popularity }}</div> <div class="rating-text">{{ item.popularity }}</div>
<div class="rating"> <div class="rating">
{% set rating = 10 - item.popularity|int %} {% set rating = 10 - item.popularity|round %}
{% for i in range(10) %} {% for i in range(10) %}
{% if rating == i %} {% if rating == i %}
<span class="vert rated"></span> <span class="vert rated"></span>
...@@ -22,7 +34,7 @@ ...@@ -22,7 +34,7 @@
{% endfor %} {% endfor %}
</div> </div>
</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> <dl>
<dt>Director</dt> <dt>Director</dt>
<dd>{{ item.director|default('No Director found')}}</dd> <dd>{{ item.director|default('No Director found')}}</dd>
...@@ -83,6 +95,42 @@ ...@@ -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> </script>
{% endblock %} {% endblock %}
{% block modals %}
{% include 'library/loanMovie_modal.html' %}
{% include 'library/reminder_modal.html' %}
{% endblock %}
\ No newline at end of file
{% 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment