Skip to content
Snippets Groups Projects
Commit b6fb7e87 authored by Brian Wood's avatar Brian Wood
Browse files

You can now remove movies from a library or all libraries (master collection removal)

parent d0115875
No related branches found
No related tags found
No related merge requests found
...@@ -35,5 +35,4 @@ def model(): ...@@ -35,5 +35,4 @@ def model():
user.addRole('kangaroo').save() user.addRole('kangaroo').save()
testCollection.addUnit(movie).save() testCollection.addUnit(movie).save()
m = testCollection.getUnit(0) m = testCollection.getUnit(0)
print m.title
return render_template('printer/index.html') return render_template('printer/index.html')
...@@ -13,6 +13,16 @@ def libraries(user = None): ...@@ -13,6 +13,16 @@ def libraries(user = None):
libraries = Library.objects(user=user,unit='Movie') libraries = Library.objects(user=user,unit='Movie')
return render_template('library/master.html', libraries=libraries,user=user) return render_template('library/master.html', libraries=libraries,user=user)
@app.route('/libraries/add', methods=['POST'])
@security('user')
def addLibrary(user = None):
name = request.get['name']
library = Library.objects(user=user,unit='Movie',name=name).first()
if library:
return jsonify(response='error',message='Library with name %s already exists' % library.name),404
library = Library(user=user,unit='Movie',name=name).save()
return jsonify(response='success',type='redirect',path=url_for(endpoint='libraries',_external=True))
@app.route('/libraries/<name>') @app.route('/libraries/<name>')
@security('user') @security('user')
def library(name,user=None): def library(name,user=None):
...@@ -34,14 +44,17 @@ def libraryItem(name, index,user=None): ...@@ -34,14 +44,17 @@ def libraryItem(name, index,user=None):
return render_template('404.html',message='Unable to find given Movie',user=user),404 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)
@app.route('/libraries/<name>/remove/<int:index>', methods=['POST']) @app.route('/libraries/<name>/remove', methods=['POST'])
@security('user') @security('user')
def removelibraryItem(name, index,user=None): def removelibraryItem(name,user=None):
from project.model.Movie import Movie from project.model.Movie import Movie
library = Library.objects(user=user,name=name,unit='Movie').first() library = Library.objects(user=user,name=name,unit='Movie').first()
if not library: if not library:
return jsonify(response='error',message='Unable to find the given Library'),404 return jsonify(response='error',message='Unable to find the given Library'),404
movie = library.hydrateUnit(index) index = int(request.form['id'])
if not index:
return jsonify(response='error',message='Invalid parameters'),404
movie = library.hydrateUnit(index-1)
if not movie: if not movie:
return jsonify(response='error',message='Unable to find the given Movie in Library %s' % library.name),404 return jsonify(response='error',message='Unable to find the given Movie in Library %s' % library.name),404
......
...@@ -22,7 +22,6 @@ def searchMovie(user=None): ...@@ -22,7 +22,6 @@ def searchMovie(user=None):
movies = searchMovie(term) movies = searchMovie(term)
if len(movies) == 0: if len(movies) == 0:
return jsonify(response='error',message='No results given'),404 return jsonify(response='error',message='No results given'),404
print movies
results = [] results = []
limit = 10 limit = 10
for index in range(len(movies)): for index in range(len(movies)):
......
...@@ -11,9 +11,9 @@ class Library(db.Document): ...@@ -11,9 +11,9 @@ class Library(db.Document):
def addUnit(self,unit): def addUnit(self,unit):
if self.unit == type(unit).__name__: if self.unit == type(unit).__name__:
value = unit[self.lookup_attribute] value = str(unit[self.lookup_attribute])
if value is not None and value not in self.collection: if value is not None and value not in self.collection:
self.collection.append("%s" % value) self.collection.append(value)
self.save() self.save()
else: else:
return self return self
...@@ -23,9 +23,9 @@ class Library(db.Document): ...@@ -23,9 +23,9 @@ class Library(db.Document):
def removeUnit(self,unit): def removeUnit(self,unit):
if self.unit == type(unit).__name__: if self.unit == type(unit).__name__:
value = unit[self.lookup_attribute] value = str(unit[self.lookup_attribute])
if value is not None and value in self.collection: if value is not None and value in self.collection:
self.collection.remove("%s" % value) self.collection.remove(value)
self.save() self.save()
else: else:
return self return self
...@@ -44,7 +44,6 @@ class Library(db.Document): ...@@ -44,7 +44,6 @@ class Library(db.Document):
def hydrateList(self): def hydrateList(self):
hydratedCollection = [] hydratedCollection = []
print sys.modules.keys()
model = getattr(sys.modules["project.model.%s" % self.unit], self.unit) model = getattr(sys.modules["project.model.%s" % self.unit], self.unit)
for index, hash_value in enumerate(self.collection): for index, hash_value in enumerate(self.collection):
attr = {} attr = {}
......
...@@ -36,7 +36,6 @@ class Movie(db.Document): ...@@ -36,7 +36,6 @@ class Movie(db.Document):
result = Movie() result = Movie()
result.tmdb_id = int(movie.id) result.tmdb_id = int(movie.id)
result.title = str(movie.title) result.title = str(movie.title)
print movie.overview
result.summary = str(movie.overview.encode('utf-8')) result.summary = str(movie.overview.encode('utf-8'))
if movie.poster: if movie.poster:
sizes = movie.poster.sizes() sizes = movie.poster.sizes()
......
{% extends "modal_base.html" %} {% extends "modal_base.html" %}
{% block title %} Login {% endblock %} {% block modal_title %} Login {% endblock %}
{% block modal_content %} {% block modal_content %}
<form class="form-horizontal" id="login" role="form" method="post" action="{{ url_for('login') }}"> <form class="form-horizontal" id="login" role="form" method="post" action="{{ url_for('login') }}">
<div class="form-group"> <div class="form-group">
......
{% extends "modal_base.html" %} {% extends "modal_base.html" %}
{% block title %} Sign Up {% endblock %} {% block modal_title %} Sign Up {% endblock %}
{% block modal_content %} {% block modal_content %}
<form class="form-horizontal" id="signup" role="form" method="post" action="{{ url_for('signup') }}"> <form class="form-horizontal" id="signup" role="form" method="post" action="{{ url_for('signup') }}">
<div class="form-group"> <div class="form-group">
......
{% extends "modal_base.html" %} {% extends "modal_base.html" %}
{% block title %} Add Movie {% endblock %} {% block modal_title %} Add Movie {% endblock %}
{% block modal_content %} {% block modal_content %}
<div class="row"> <div class="row">
<div class="pull-right adjust-left"> <div class="pull-right adjust-left">
......
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
</td> </td>
<td> <td>
<div class="btn-group-vertical"> <div class="btn-group-vertical">
<button type="button" class="btn btn-default btn-small lend-movie" data-id='{{ movie.id }}'>Lend</button> <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='{{ movie.id }}'>Edit</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='{{ movie.id }}'>Remove</button> <button type="button" class="btn btn-default btn-small remove-movie" data-id='{{ loop.index }}'>Remove</button>
</div> </div>
</td> </td>
</tr> </tr>
...@@ -55,9 +55,44 @@ ...@@ -55,9 +55,44 @@
$(function(){ $(function(){
var libraryPath = '{{ url_for("libraryItem", name=library.name, index="999") }}'; var libraryPath = '{{ url_for("libraryItem", name=library.name, index="999") }}';
$('.clickable').on('click',function(){ $('.clickable').on('click',function(){
var libname = $(this).data('id'); var movie_id = $(this).data('id');
window.document.location = libraryPath.replace('999',libname); window.document.location = libraryPath.replace('999',movie_id);
}) });
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> </script>
{% endblock %} {% endblock %}
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 class="blue bigger">{% block title %}{% endblock %}</h3> <h3 class="blue bigger">{% block modal_title %}{% endblock %}</h3>
</div> </div>
<div class="{{ modal_body_class }}"> <div class="{{ modal_body_class }}">
<div class="alert alert-danger hide {{ self.form_id()}}-error"> <div class="alert alert-danger hide {{ self.form_id()}}-error">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment