commit 4e7972c5c1b9517b949dcbcd19550669b29b89e1
parent 7c9448a485547238514d3b883158619ca9945992
Author: Brian C. Lane <bcl@f12.imp.home>
Date: Wed, 14 Apr 2010 03:19:42 -0700
Add delete of media items
Simplified delete AJAX call. XSRF support is moot at this point since
they are turned off to allow the Roku to POST. Need to sort out a better
way to update last played position.
Diffstat:
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/server/hms/hms.py b/server/hms/hms.py
@@ -830,10 +830,26 @@ class SourceHandler(BaseHandler):
class MediaDeleteHandler(BaseHandler):
@tornado.web.authenticated
def post(self, media_id):
+ """
+ Delete the media entry
+ """
if self.current_user != 'admin':
self.redirect("/media/")
return
+ print self.request
+
+ conn = sqlite3.connect(options.database)
+ conn.row_factory = sqlite3.Row
+ cur = conn.cursor()
+
+ cur.execute("delete from last_position where media_id=?", (media_id,))
+ cur.execute("delete from list_media where media_id=?", (media_id,))
+ cur.execute("delete from media where id=?", (media_id,))
+ conn.commit()
+
+ cur.close()
+ conn.close()
return
@@ -993,6 +1009,9 @@ class MediaHandler(BaseHandler):
class UserDeleteHandler(BaseHandler):
@tornado.web.authenticated
def post(self, media_id):
+ """
+ Delete the user from the database
+ """
if self.current_user != 'admin':
self.redirect("/media/")
return
diff --git a/server/hms/templates/base.html b/server/hms/templates/base.html
@@ -40,19 +40,11 @@ function getCookie(name) {
return r ? r[1] : undefined;
}
-jQuery.postJSON = function(url, args, callback) {
- args._xsrf = getCookie("_xsrf");
- $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
- success: function(response) {
- callback(eval("(" + response + ")"));
- }});
-};
-
$(document).ready(function() {
$('.delete').click(function() {
+ var args = {_xsrf : getCookie("_xsrf")};
if (confirm("Delete this item?"))
- $.postJSON($(this).attr('href'), function(data) {
- // Reload the current page...
+ $.post($(this).attr('href'), args, function(data) {
location.reload();
return false;
});