From 8b1091e7fd331db4be47d144c8f42cdf98240666 Mon Sep 17 00:00:00 2001 From: Brian Wood <legion.the.unforgiven@gmail.com> Date: Mon, 21 Apr 2014 13:45:45 -0600 Subject: [PATCH] Added ratings and worked on some responsive styling --- project/__init__.py | 4 +- project/controllers/library.py | 2 +- project/model/Movie.py | 10 ++- project/static/css/style.css | 50 ++++++++++++ project/templates/library/library.html | 27 +++++-- project/templates/library/libraryItem.html | 94 +++++++++++++++++----- 6 files changed, 154 insertions(+), 33 deletions(-) diff --git a/project/__init__.py b/project/__init__.py index a24a67b..51173a7 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -16,8 +16,8 @@ from tmdb3 import set_key app = Flask('project') app.config['SECRET_KEY'] = 'random' app.config['MONGODB_SETTINGS'] = {'DB': 'my_movie_library'} -app.config['SMTP_USER'] = "" -app.config['SMTP_PASSWORD'] = "" +app.config['SMTP_USER'] = "my.movie.library.reminder@gmail.com" +app.config['SMTP_PASSWORD'] = "1 LikemoVies&p0pCO7n" app.config['SMTP_SERVER'] = "smtp.gmail.com:587" app.config['TMDB_API_KEY'] = "542606a6ccff81a0337dc370a0cbfc37" set_key(app.config['TMDB_API_KEY']) diff --git a/project/controllers/library.py b/project/controllers/library.py index 1961a6d..770f2ae 100644 --- a/project/controllers/library.py +++ b/project/controllers/library.py @@ -54,7 +54,7 @@ def libraryItem(name, index,user=None): movie = library.hydrateUnit(index-1) if not movie: return render_template('404.html',message='Unable to find given Movie',user=user),404 - return render_template('library/libraryItem.html',item=movie,user=user) + return render_template('library/libraryItem.html',item=movie,user=user,library=library,index=index) @app.route('/libraries/<name>/remove', methods=['POST']) @security('user') diff --git a/project/model/Movie.py b/project/model/Movie.py index 905f024..08ab6b4 100644 --- a/project/model/Movie.py +++ b/project/model/Movie.py @@ -7,6 +7,7 @@ class Movie(db.Document): summary = db.StringField(max_length=10000, required=True) tags = db.ListField(db.StringField(max_length=50)) cast = db.ListField(db.StringField()) + director = db.StringField() tmdb_id = db.IntField() runtime = db.IntField() poster = db.StringField() @@ -48,7 +49,7 @@ class Movie(db.Document): if len(sizes) > 0: medium = int(len(sizes)/2) result.poster = str(movie.poster.geturl(sizes[medium])) - result.popularity = float(movie.popularity) + result.popularity = float(movie.userrating) result.runtime = int(movie.runtime) tags = movie.keywords for tag in tags: @@ -58,6 +59,11 @@ class Movie(db.Document): result.addTag(str(genre.name.encode('utf-8'))) cast = movie.cast for actor in cast: - result.cast.append("%s as %s" % (actor.name,actor.character)) + result.cast.append("%s:%s" % (actor.name,actor.character)) + crew = movie.crew + for person in crew: + job = person.job.encode('utf-8') + if 'director' == job.lower(): + result.director = person.name.encode('utf-8') result.save() return result diff --git a/project/static/css/style.css b/project/static/css/style.css index c803093..3fe7d58 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -48,4 +48,54 @@ html,body { #results { max-height: 500px; overflow-y: scroll; +} + +dl { + width:100%; + overflow:hidden; +} +dt { + float:left; + width:50%; /* adjust the width; make sure the total of both is 100% */ +} +dd { + float:left; + width:50%; /* adjust the width; make sure the total of both is 100% */ + +} + +.rating-text { + margin: 0 auto; + width: 20px; + color: gold; +} + +.rating { + unicode-bidi: bidi-override; + direction: rtl; + width: 20px; + margin: 0 auto; +} +.rating > span.rated:before, +.rating > span.rated ~ span:before { + content: "\2605"; + position: absolute; + color: gold; +} + +span.vert{ + font-size: 22px; +} + +@media (max-width: 480px) { + span.vert { + display: inline-block; + } + .rating { + width: 90%; + display: inline-block; + } + .rating-text{ + display: inline-block; + } } \ No newline at end of file diff --git a/project/templates/library/library.html b/project/templates/library/library.html index f8ccba0..8bc3090 100644 --- a/project/templates/library/library.html +++ b/project/templates/library/library.html @@ -11,9 +11,9 @@ <thead> <tr> <td>Movie</td> - <td>Summary</td> <td>Rating</td> - <td>Options</td> + <td class="hidden-xs">Summary</td> + <td class="hidden-xs">Options</td> </tr> </thead> <tbody> @@ -27,14 +27,29 @@ <td> <img src="{{ movie.poster|default('') }}" style="max-width: 200px;" alt="{{ movie.title }}"> <p>{{ movie.title }}</p> + <div class="btn-group hidden-md hidden-lg"> + <button type="button" class="btn btn-default btn-small lend-movie" data-id='{{ loop.index }}'>Lend</button> + <button type="button" class="btn btn-default btn-small borrow-movie" data-id='{{ loop.index }}'>Edit</button> + <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button> + </div> </td> <td> - {{ movie.summary }} + <div class='rating-text'style="">{{ movie.popularity }}</div> + <div class="rating"> + {% set rating = 10 - movie.popularity|int %} + {% for i in range(10) %} + {% if rating == i %} + <span class="vert rated">☆</span> + {% else %} + <span class="vert">☆</span> + {% endif %} + {% endfor %} + </div> </td> - <td> - {{ movie.rating }} + <td class="hidden-xs"> + {{ movie.summary }} </td> - <td> + <td class="hidden-xs"> <div class="btn-group-vertical"> <button type="button" class="btn btn-default btn-small lend-movie" data-id='{{ loop.index }}'>Lend</button> <button type="button" class="btn btn-default btn-small borrow-movie" data-id='{{ loop.index }}'>Edit</button> diff --git a/project/templates/library/libraryItem.html b/project/templates/library/libraryItem.html index 256b956..a2722d0 100644 --- a/project/templates/library/libraryItem.html +++ b/project/templates/library/libraryItem.html @@ -3,36 +3,86 @@ <div class="col-sm-12"> <div class="row"> <div class="col-xs-12 col-sm-3 col-md-2"> - <img data-src="holder.js/100%x200/sky" alt="movie title"> - <button type="button" class="btn btn-default btn-sm"> - <span class="glyphicon glyphicon-pencil"></span> Edit - </button> - <button type="button" class="btn btn-warning btn-sm"> + <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> - - <div class="col-xs-12 col-sm-3 col-md-2"> - <ul class="list-unstyled"> - <li>Movie Title</li> - <li>Director(s)</li> - <li>Actors (truncated)</li> - <li>Producers</li> - <li>Composer</li> - </ul> + <div class="col-md-1 hidden-sm"> + <div class="rating-text">{{ item.popularity }}</div> + <div class="rating"> + {% set rating = 10 - item.popularity|int %} + {% for i in range(10) %} + {% if rating == i %} + <span class="vert rated">☆</span> + {% else %} + <span class="vert">☆</span> + {% endif %} + {% endfor %} + </div> + </div> + <div class="col-xs-12 col-sm-4 col-md-4"> + <dl> + <dt>Director</dt> + <dd>{{ item.director|default('No Director found')}}</dd> + <dt>Actors:</dt> + <dd> </dd> + {% for data in item.cast %} + {% set actor = data.split(':')[0]|default(' ') %} + {% set character = data.split(':')[1]|default(' ') %} + <dt>{{ actor }}</dt> + <dd>{{ character }}</dd> + {% endfor %} + + </dl> </div> - <div class="col-xs-12 col-sm-6 col-md-8"> + <div class="col-xs-12 col-sm-5 col-md-5"> <h2>Summary</h2> - <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget metus vitae mi interdum tristique. Integer malesuada quam tincidunt, gravida nisi vehicula, auctor mi. Morbi fermentum, neque quis adipiscing placerat, odio nunc consequat ligula, vel sagittis nisl orci id risus. Aliquam hendrerit, elit a molestie suscipit, eros tortor scelerisque odio, sit amet cursus ligula lorem et turpis. Pellentesque ante metus, suscipit id blandit eget, vehicula quis tortor. Aliquam a pharetra enim. Morbi in purus sit amet nulla egestas consectetur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla diam nulla, iaculis lobortis varius at, auctor malesuada enim. Donec a nisl eget ligula rhoncus fermentum.</p> + <p>{{ item.summary }}</p> </div> </div> - <div class="row"> - <div class="col-xs-12 col-sm-6 col-md-12"> - <h3>Movie Reviews</h3> - <p>Coming Soon!</p> - </div> - </div> </div> +{% endblock %} +{% block javascript %} + <script> + $(function(){ + var removePath = '{{ url_for("removelibraryItem", name=library.name) }}'; + $('.remove-movie').on('click',function(event){ + var movie_id = $(this).data('id'); + {% if library.name == 'Master' %} + var message = "Removing a movie from your Master list will remove it from all other lists. Are you sure you want remove this movie? "; + {% else %} + var message = "Are you sure you want remove this movie? "; + {% endif %} + if(confirm(message)){ + event.stopPropagation(); + event.preventDefault(); + $.ajax({ + url: removePath, + 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 %} \ No newline at end of file -- GitLab