From 0209852af5c4af2bacfd5759f1bea6325b03e62d Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 12 Dec 2014 17:52:32 -0800 Subject: [PATCH] Fixed issues with network timezone downloads crashing on a empty return. Changed version checker url and moved code to Home class. Fixed WebUI issues caused by calling redirect method. Fixed update checking issues, added no cache header. Fixed WebAPI builder issues with show.delete cmd. Fixed article sorting for both WebAPI and WebUI. --- gui/slick/interfaces/default/apiBuilder.tmpl | 149 +++++++++--------- gui/slick/interfaces/default/displayShow.tmpl | 2 +- gui/slick/js/apibuilder.js | 18 +-- sickbeard/helpers.py | 138 ++-------------- sickbeard/providers/newznab.py | 4 +- sickbeard/webapi.py | 16 +- sickbeard/webserve.py | 64 +++----- 7 files changed, 124 insertions(+), 267 deletions(-) diff --git a/gui/slick/interfaces/default/apiBuilder.tmpl b/gui/slick/interfaces/default/apiBuilder.tmpl index d8df2f64..ecae82b5 100644 --- a/gui/slick/interfaces/default/apiBuilder.tmpl +++ b/gui/slick/interfaces/default/apiBuilder.tmpl @@ -1,48 +1,49 @@ - - - -API Builder - - - + + + + + SickRage - API Builder + + + - + + + + + @@ -390,8 +383,8 @@ addOption("show.pause-opt", "Pause", "&pause=1");
- - + +
@@ -402,4 +395,4 @@ addOption("show.pause-opt", "Pause", "&pause=1"); - + \ No newline at end of file diff --git a/gui/slick/interfaces/default/displayShow.tmpl b/gui/slick/interfaces/default/displayShow.tmpl index e2715fa0..f2bfb9a7 100644 --- a/gui/slick/interfaces/default/displayShow.tmpl +++ b/gui/slick/interfaces/default/displayShow.tmpl @@ -244,7 +244,7 @@ #end if - Size:$sickbeard.helpers.human(sickbeard.helpers.get_size($showLoc[0])) + Size:$sickbeard.helpers.pretty_filesize(sickbeard.helpers.get_size($showLoc[0])) diff --git a/gui/slick/js/apibuilder.js b/gui/slick/js/apibuilder.js index 755986f1..48dafdca 100644 --- a/gui/slick/js/apibuilder.js +++ b/gui/slick/js/apibuilder.js @@ -11,16 +11,16 @@ var _disable_empty_list=false; var _hide_empty_list=false; function goListGroup(apikey, L7, L6, L5, L4, L3, L2, L1){ - var GlobalOptions = ""; + var html, GlobalOptions = ""; $('.global').each(function(){ var checked = $(this).prop('checked'); if(checked) { var globalID = $(this).attr('id'); // handle jsonp/callback global option differently if(globalID == "jsonp") { - GlobalOptions = GlobalOptions + "&" + globalID + "=foo"; + GlobalOptions = GlobalOptions + "&" + globalID + "=foo"; } else { - GlobalOptions = GlobalOptions + "&" + globalID + "=1"; + GlobalOptions = GlobalOptions + "&" + globalID + "=1"; } } }); @@ -28,7 +28,7 @@ function goListGroup(apikey, L7, L6, L5, L4, L3, L2, L1){ // handle the show.getposter / show.getbanner differently as they return an image and not json if (L1 == "?cmd=show.getposter" || L1 == "?cmd=show.getbanner") { var imgcache = sbRoot + "/api/" + apikey + "/" + L1 + L2 + GlobalOptions; - var html = imgcache + '

'; + html = imgcache + '

'; $('#apiResponse').html(html); $.ajax({ url: sbRoot + "/api/" + apikey + "/" + L1 + L2 + GlobalOptions, @@ -38,10 +38,10 @@ function goListGroup(apikey, L7, L6, L5, L4, L3, L2, L1){ success: function (img) { $('#imgcache').attr('src', imgcache); } - }) + }); } else { - var html = sbRoot + "/api/" + apikey + "/" + L1 + L2 + L3 + L4 + L5 + L6 + L7 + GlobalOptions + "
";
+        html = sbRoot + "/api/" + apikey + "/" + L1 + L2 + L3 + L4 + L5 + L6 + L7 + GlobalOptions + "
";
         html += $.ajax({
           url: sbRoot + "/api/" + apikey + "/" + L1 + L2 + L3 + L4 + L5 + L6 + L7 + GlobalOptions,
           async: false,
@@ -189,13 +189,13 @@ function cs_getCookie(name) {
 
 function cs_optionOBJ(type,text,value,label,css) { this.type=type; this.text=text; this.value=value; this.label=label; this.css=css; }
 function cs_getOptions(menu,list) {
-  var opt=new Array();
+  var opt=[];
   for (var i=0; i.
 
 from __future__ import with_statement
-import inspect
 
 import traceback
 import os
@@ -27,7 +26,6 @@ import re
 import datetime
 
 import sickbeard
-
 from sickbeard import config, sab
 from sickbeard import clients
 from sickbeard import history, notifiers, processTV
@@ -41,7 +39,6 @@ from sickbeard import scene_exceptions
 from sickbeard import subtitles
 from sickbeard import network_timezones
 from sickbeard import sbdatetime
-
 from sickbeard.providers import newznab, rsstorrent
 from sickbeard.common import Quality, Overview, statusStrings, qualityPresetStrings, cpu_presets
 from sickbeard.common import SNATCHED, UNAIRED, IGNORED, ARCHIVED, WANTED, FAILED
@@ -56,9 +53,7 @@ from sickbeard.scene_numbering import get_scene_numbering, set_scene_numbering,
 
 from lib.dateutil import tz
 from lib.unrar2 import RarFile
-
 from lib import adba, subliminal
-
 from lib.trakt import TraktAPI
 from lib.trakt.exceptions import traktException, traktAuthException, traktServerBusy
 
@@ -75,14 +70,12 @@ except ImportError:
 from Cheetah.Template import Template
 
 from tornado.routes import route
-from tornado.web import RequestHandler, HTTPError, authenticated, asynchronous, addslash
+from tornado.web import RequestHandler, HTTPError, authenticated, asynchronous
 from tornado.gen import coroutine
 from tornado.ioloop import IOLoop
 from tornado.concurrent import run_on_executor
 from concurrent.futures import ThreadPoolExecutor
 
-from bug_tracker import BugTracker
-
 route_locks = {}
 
 class PageTemplate(Template):
@@ -135,6 +128,9 @@ class PageTemplate(Template):
 
 
 class BaseHandler(RequestHandler):
+    def __init__(self, *args, **kwargs):
+        super(BaseHandler, self).__init__(*args, **kwargs)
+
     def write_error(self, status_code, **kwargs):
         # handle 404 http errors
         if status_code == 404:
@@ -186,33 +182,24 @@ class WebHandler(BaseHandler):
     @authenticated
     def get(self, route, *args, **kwargs):
         try:
+            # route -> method obj
             route = route.strip('/').replace('.', '_') or 'index'
-
-            # get route
-            #try:
             method = getattr(self, route)
-            #except:
-                #try:
-                #    subclasses = self.__class__.__subclasses__()
-                #    method = [getattr(cls, route) for cls in subclasses if getattr(cls, route, None)][0]
-                #except:
-                #    raise
-
-            # query params
-            params = self.request.arguments
-            for arg, value in params.items():
-                if len(value) == 1:
-                    params[arg] = value[0]
 
             # process request async
-            self.async_call(method, callback=self.async_done, **params)
+            self.async_call(method, callback=self.async_done)
         except:
             logger.log('Failed doing webui request "%s": %s' % (route, traceback.format_exc()), logger.ERROR)
             raise HTTPError(404)
 
     @run_on_executor
-    def async_call(self, function, callback=None, **kwargs):
+    def async_call(self, function, callback=None):
         try:
+            kwargs = self.request.arguments
+            for arg, value in kwargs.items():
+                if len(value) == 1:
+                    kwargs[arg] = value[0]
+
             result = function(**kwargs)
             if callback:
                 callback(result)
@@ -236,7 +223,7 @@ class WebHandler(BaseHandler):
 
     def _genericMessage(self, subject, message):
         t = PageTemplate(rh=self, file="genericMessage.tmpl")
-        t.submenu = self.HomeMenu()
+        t.submenu = Home().HomeMenu()
         t.subject = subject
         t.message = message
         return t
@@ -347,22 +334,15 @@ class WebRoot(WebHandler):
         t = PageTemplate(rh=self, file="apiBuilder.tmpl")
 
         def titler(x):
-            if not x or sickbeard.SORT_ARTICLE:
-                return x
-            if x.lower().startswith('a '):
-                x = x[2:]
-            elif x.lower().startswith('an '):
-                x = x[3:]
-            elif x.lower().startswith('the '):
-                x = x[4:]
-            return x
+            return (helpers.remove_article(x), x)[not x or sickbeard.SORT_ARTICLE]
 
         t.sortedShowList = sorted(sickbeard.showList, lambda x, y: cmp(titler(x.name), titler(y.name)))
 
+        myDB = db.DBConnection(row_type="dict")
+
         seasonSQLResults = {}
         episodeSQLResults = {}
 
-        myDB = db.DBConnection(row_type="dict")
         for curShow in t.sortedShowList:
             seasonSQLResults[curShow.indexerid] = myDB.select(
                 "SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
@@ -1117,15 +1097,7 @@ class Home(WebRoot):
                 epCounts[curEpCat] += 1
 
         def titler(x):
-            if not x or sickbeard.SORT_ARTICLE:
-                return x
-            if x.lower().startswith('a '):
-                x = x[2:]
-            if x.lower().startswith('an '):
-                x = x[3:]
-            elif x.lower().startswith('the '):
-                x = x[4:]
-            return x
+            return (helpers.remove_article(x), x)[not x or sickbeard.SORT_ARTICLE]
 
         if sickbeard.ANIME_SPLIT_HOME:
             shows = []
@@ -3155,7 +3127,7 @@ class Manage(WebRoot):
 
         if re.search('localhost', sickbeard.TORRENT_HOST):
 
-            if not sickbeard.LOCALHOST_IP:
+            if sickbeard.LOCALHOST_IP == '':
                 t.webui_url = re.sub('localhost', helpers.get_lan_ip(), sickbeard.TORRENT_HOST)
             else:
                 t.webui_url = re.sub('localhost', sickbeard.LOCALHOST_IP, sickbeard.TORRENT_HOST)