From 3cac799877d8b480ecf696cbf6674108042eaead Mon Sep 17 00:00:00 2001 From: JackDandy Date: Thu, 27 Nov 2014 03:30:00 +0000 Subject: [PATCH] Fix article sorting for Coming Eps, Manage, Show List, and Trending Shows. Increase article sorting strictness with a central helper function. --- CHANGES.md | 3 ++- gui/slick/interfaces/default/comingEpisodes.tmpl | 2 +- gui/slick/interfaces/default/home.tmpl | 4 ++-- .../interfaces/default/home_trendingShows.tmpl | 2 +- gui/slick/interfaces/default/manage.tmpl | 2 +- sickbeard/helpers.py | 3 +++ sickbeard/webapi.py | 13 +++++++------ sickbeard/webserve.py | 13 +++++++------ 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9f6f594e..c167f46c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -### 0.4.0 (2014-11-26 13:30:00 UTC) +### 0.4.0 (2014-11-27 03:30:00 UTC) * Change footer stats to not add newlines when copy/pasting from them * Remove redundant references from Config/Help & Info @@ -50,6 +50,7 @@ * Fix reduces time API endpoint Shows takes to return results * Fix Coming Eps Page to include shows +/- 1 day for time zone corrections * Fix season jumping dropdown menu for shows with over 15 seasons on Display Show +* Fix article sorting for Coming Eps, Manage, Show List, and Trending Shows ### 0.3.1 (2014-11-19 16:40:00 UTC) diff --git a/gui/slick/interfaces/default/comingEpisodes.tmpl b/gui/slick/interfaces/default/comingEpisodes.tmpl index 1a5299bc..9e012219 100644 --- a/gui/slick/interfaces/default/comingEpisodes.tmpl +++ b/gui/slick/interfaces/default/comingEpisodes.tmpl @@ -82,7 +82,7 @@ if (0 == s.indexOf('Loading...')) return s.replace('Loading...', '000') #if not $sickbeard.SORT_ARTICLE: - return (s || '').replace(/^(The|A|An)\s/i, '') + return (s || '').replace(/^(?:(?:A(?!\s+to)n?)|The)\s(\w)/i, '$1') #else: return (s || '') #end if diff --git a/gui/slick/interfaces/default/home.tmpl b/gui/slick/interfaces/default/home.tmpl index e18ec11a..e9b988f0 100644 --- a/gui/slick/interfaces/default/home.tmpl +++ b/gui/slick/interfaces/default/home.tmpl @@ -58,7 +58,7 @@ return s.replace('Loading...','000'); else #if not $sickbeard.SORT_ARTICLE: - return (s || '').replace(/^(The|A|An)\s/i,''); + return (s || '').replace(/^(?:(?:A(?!\s+to)n?)|The)\s(\w)/i, '$1'); #else: return (s || ''); #end if @@ -162,7 +162,7 @@ name: function( itemElem ) { var name = \$( itemElem ).attr('data-name'); #if not $sickbeard.SORT_ARTICLE: - return (name || '').replace(/^(The|A|An)\s/i,''); + return (name || '').replace(/^(?:(?:A(?!\s+to)n?)|The)\s(\w)/i, '$1'); #else: return (name || ''); #end if diff --git a/gui/slick/interfaces/default/home_trendingShows.tmpl b/gui/slick/interfaces/default/home_trendingShows.tmpl index 032ee11f..6bc04d26 100644 --- a/gui/slick/interfaces/default/home_trendingShows.tmpl +++ b/gui/slick/interfaces/default/home_trendingShows.tmpl @@ -36,7 +36,7 @@ name: function( itemElem ) { var name = \$( itemElem ).attr('data-name') || ''; #if not $sickbeard.SORT_ARTICLE: - name = name.replace(/^(The|A|An)\s/i, ''); + name = name.replace(/^(?:(?:A(?!\s+to)n?)|The)\s(\w)/i, '$1'); #end if return name.toLowerCase(); }, diff --git a/gui/slick/interfaces/default/manage.tmpl b/gui/slick/interfaces/default/manage.tmpl index 3a240f21..6202e551 100644 --- a/gui/slick/interfaces/default/manage.tmpl +++ b/gui/slick/interfaces/default/manage.tmpl @@ -18,7 +18,7 @@ }, format: function(s) { #if not $sickbeard.SORT_ARTICLE: - return (s || '').replace(/^(The|A|An)\s/i,''); + return (s || '').replace(/^(?:(?:A(?!\s+to)n?)|The)\s(\w)/i, '$1'); #else: return (s || ''); #end if diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 9439fe85..1be5b37e 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1428,3 +1428,6 @@ def get_size(start_path='.'): total_size += ek.ek(os.path.getsize, fp) return total_size + +def remove_article(text=''): + return re.sub(r'(?i)/^(?:(?:A(?!\s+to)n?)|The)\s(\w)', r'\1', text) \ No newline at end of file diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index df1220c6..46496d0f 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -37,6 +37,7 @@ from sickbeard import processTV from sickbeard import network_timezones, sbdatetime from sickbeard.exceptions import ex from sickbeard.common import SNATCHED, SNATCHED_PROPER, DOWNLOADED, SKIPPED, UNAIRED, IGNORED, ARCHIVED, WANTED, UNKNOWN +from sickbeard.helpers import remove_article from common import Quality, qualityPresetStrings, statusStrings try: @@ -766,22 +767,22 @@ class CMD_ComingEpisodes(ApiCall): sorts = { 'date': (lambda a, b: cmp( (a['parsed_datetime'], - (a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + (a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['season'], a['episode']), (b['parsed_datetime'], - (b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + (b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['season'], b['episode']))), 'show': (lambda a, b: cmp( - ((a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + ((a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['parsed_datetime'], a['season'], a['episode']), - ((b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + ((b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['parsed_datetime'], b['season'], b['episode']))), 'network': (lambda a, b: cmp( (a['network'], a['parsed_datetime'], - (a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + (a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['season'], a['episode']), (b['network'], b['parsed_datetime'], - (b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + (b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['season'], b['episode']))) } diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 308fc18f..dda6dcb2 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -52,6 +52,7 @@ from sickbeard.common import Quality, Overview, statusStrings, qualityPresetStri from sickbeard.common import SNATCHED, UNAIRED, IGNORED, ARCHIVED, WANTED, FAILED from sickbeard.common import SD, HD720p, HD1080p from sickbeard.exceptions import ex +from sickbeard.helpers import remove_article from sickbeard.scene_exceptions import get_scene_exceptions from sickbeard.scene_numbering import get_scene_numbering, set_scene_numbering, get_scene_numbering_for_show, \ get_xem_numbering_for_show, get_scene_absolute_numbering_for_show, get_xem_absolute_numbering_for_show, \ @@ -394,22 +395,22 @@ class MainHandler(RequestHandler): sorts = { 'date': (lambda a, b: cmp( (a['localtime'], - (a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + (a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['season'], a['episode']), (b['localtime'], - (b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + (b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['season'], b['episode']))), 'show': (lambda a, b: cmp( - ((a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + ((a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['localtime'], a['season'], a['episode']), - ((b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + ((b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['localtime'], b['season'], b['episode']))), 'network': (lambda a, b: cmp( (a['network'], a['localtime'], - (a['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', a['show_name']))[not sickbeard.SORT_ARTICLE], + (a['show_name'], remove_article(a['show_name']))[not sickbeard.SORT_ARTICLE], a['season'], a['episode']), (b['network'], b['localtime'], - (b['show_name'], re.sub(r'(?i)^(The|A|An)\s', '', b['show_name']))[not sickbeard.SORT_ARTICLE], + (b['show_name'], remove_article(b['show_name']))[not sickbeard.SORT_ARTICLE], b['season'], b['episode']))) }