diff --git a/project/controllers/home.py b/project/controllers/home.py index bc436e84445ba290263d35a1fad002adce263fa9..38299a6a4ea291b24fde9513aea1f2262f224af6 100644 --- a/project/controllers/home.py +++ b/project/controllers/home.py @@ -35,5 +35,4 @@ def model(): user.addRole('kangaroo').save() testCollection.addUnit(movie).save() m = testCollection.getUnit(0) - print m.title return render_template('printer/index.html') diff --git a/project/controllers/library.py b/project/controllers/library.py index 81a74e1d908e2b6ae1ba723f8528325e1bad4605..14b3de0ed1188bf981b35c3454b513d4fa92731a 100644 --- a/project/controllers/library.py +++ b/project/controllers/library.py @@ -13,6 +13,16 @@ def libraries(user = None): libraries = Library.objects(user=user,unit='Movie') 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>') @security('user') def library(name,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('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') -def removelibraryItem(name, index,user=None): +def removelibraryItem(name,user=None): from project.model.Movie import Movie library = Library.objects(user=user,name=name,unit='Movie').first() if not library: 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: return jsonify(response='error',message='Unable to find the given Movie in Library %s' % library.name),404 @@ -51,7 +64,7 @@ def removelibraryItem(name, index,user=None): library.removeUnit(movie) else: library.removeUnit(movie) - + return jsonify(response='success',type='redirect',path=url_for(endpoint='library',name=name,_external=True)) @app.route('/libraries/<name>/add', methods=['POST']) diff --git a/project/controllers/movies.py b/project/controllers/movies.py index 6188a3447382a038464c2e81ec92078bfbe3d28d..07162632c13e4472ae7affb3960d1ac3aa8228e1 100644 --- a/project/controllers/movies.py +++ b/project/controllers/movies.py @@ -22,7 +22,6 @@ def searchMovie(user=None): movies = searchMovie(term) if len(movies) == 0: return jsonify(response='error',message='No results given'),404 - print movies results = [] limit = 10 for index in range(len(movies)): diff --git a/project/model/Library.py b/project/model/Library.py index 4ab0ba64b0dde504a53c99948df61e8c8bcc6019..07ee137a9f896e12b16023e882b9ad589b55bf31 100644 --- a/project/model/Library.py +++ b/project/model/Library.py @@ -11,9 +11,9 @@ class Library(db.Document): def addUnit(self,unit): 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: - self.collection.append("%s" % value) + self.collection.append(value) self.save() else: return self @@ -23,9 +23,9 @@ class Library(db.Document): def removeUnit(self,unit): 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: - self.collection.remove("%s" % value) + self.collection.remove(value) self.save() else: return self @@ -44,7 +44,6 @@ class Library(db.Document): def hydrateList(self): hydratedCollection = [] - print sys.modules.keys() model = getattr(sys.modules["project.model.%s" % self.unit], self.unit) for index, hash_value in enumerate(self.collection): attr = {} diff --git a/project/model/Movie.py b/project/model/Movie.py index 4458faa1761928e2edd163645a09e45f219e65ac..0998b4141e117cccb37062f2b12d60146456f9c8 100644 --- a/project/model/Movie.py +++ b/project/model/Movie.py @@ -36,7 +36,6 @@ class Movie(db.Document): result = Movie() result.tmdb_id = int(movie.id) result.title = str(movie.title) - print movie.overview result.summary = str(movie.overview.encode('utf-8')) if movie.poster: sizes = movie.poster.sizes() diff --git a/project/templates/home/login_modal.html b/project/templates/home/login_modal.html index d159d8dfc1108e00519f4ec923d23f060887ed0f..383645142825318938ff9cab3cfdc4114f3180b2 100644 --- a/project/templates/home/login_modal.html +++ b/project/templates/home/login_modal.html @@ -1,5 +1,5 @@ {% extends "modal_base.html" %} -{% block title %} Login {% endblock %} +{% block modal_title %} Login {% endblock %} {% block modal_content %} <form class="form-horizontal" id="login" role="form" method="post" action="{{ url_for('login') }}"> <div class="form-group"> diff --git a/project/templates/home/signup_modal.html b/project/templates/home/signup_modal.html index db48d3c0a586be6bb74214b4cc5f205086393084..2d354027363608e6209b5363636751873e82684b 100644 --- a/project/templates/home/signup_modal.html +++ b/project/templates/home/signup_modal.html @@ -1,5 +1,5 @@ {% extends "modal_base.html" %} -{% block title %} Sign Up {% endblock %} +{% block modal_title %} Sign Up {% endblock %} {% block modal_content %} <form class="form-horizontal" id="signup" role="form" method="post" action="{{ url_for('signup') }}"> <div class="form-group"> diff --git a/project/templates/library/addmovie_modal.html b/project/templates/library/addmovie_modal.html index 2b943bdaf11e8c03fdb50cd74f3aee3d32d479e9..191c7a380c52f6bf2617ada10e82d3f91f387a73 100644 --- a/project/templates/library/addmovie_modal.html +++ b/project/templates/library/addmovie_modal.html @@ -1,5 +1,5 @@ {% extends "modal_base.html" %} -{% block title %} Add Movie {% endblock %} +{% block modal_title %} Add Movie {% endblock %} {% block modal_content %} <div class="row"> <div class="pull-right adjust-left"> diff --git a/project/templates/library/library.html b/project/templates/library/library.html index cd175c2295cf3cacd5c71643afcc2ff1de93ef31..f8ccba06e3d93b9db262c66a04ca2efc7aa75a5c 100644 --- a/project/templates/library/library.html +++ b/project/templates/library/library.html @@ -36,9 +36,9 @@ </td> <td> <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 borrow-movie" data-id='{{ movie.id }}'>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 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> </tr> @@ -55,9 +55,44 @@ $(function(){ var libraryPath = '{{ url_for("libraryItem", name=library.name, index="999") }}'; $('.clickable').on('click',function(){ - var libname = $(this).data('id'); - window.document.location = libraryPath.replace('999',libname); - }) + var movie_id = $(this).data('id'); + 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> {% endblock %} diff --git a/project/templates/modal_base.html b/project/templates/modal_base.html index af46d888a73dadacfa2fec0d8cb8ecb5eddabc35..a1457809a5d9714c423fd84a2c14837c4a4be86a 100644 --- a/project/templates/modal_base.html +++ b/project/templates/modal_base.html @@ -4,7 +4,7 @@ <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> - <h3 class="blue bigger">{% block title %}{% endblock %}</h3> + <h3 class="blue bigger">{% block modal_title %}{% endblock %}</h3> </div> <div class="{{ modal_body_class }}"> <div class="alert alert-danger hide {{ self.form_id()}}-error">