From e657f446c1b406e03dd6954c6c25804a9683c34c Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 29 Jan 2012 23:15:48 +0100 Subject: [PATCH] Notify when adding movie already in wanted or library --- couchpotato/core/plugins/movie/static/search.css | 5 ++++ couchpotato/core/plugins/movie/static/search.js | 6 +++++ couchpotato/core/providers/movie/_modifier/main.py | 31 ++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/plugins/movie/static/search.css b/couchpotato/core/plugins/movie/static/search.css index ad2f5b0..6bd388e 100644 --- a/couchpotato/core/plugins/movie/static/search.css +++ b/couchpotato/core/plugins/movie/static/search.css @@ -126,6 +126,11 @@ } .movie_result:last-child .data { border-bottom: 0; } + + .movie_result .in_wanted, .movie_result .in_library { + position: absolute; + margin-top: 105px; + } .movie_result .thumbnail { width: 17%; diff --git a/couchpotato/core/plugins/movie/static/search.js b/couchpotato/core/plugins/movie/static/search.js index 82ba6d8..fc26d19 100644 --- a/couchpotato/core/plugins/movie/static/search.js +++ b/couchpotato/core/plugins/movie/static/search.js @@ -291,6 +291,12 @@ Block.Search.Item = new Class({ self.info.images.poster.length > 0 ? new Element('img.thumbnail', { 'src': self.info.images.poster[0] }) : null, + self.info.in_wanted ? new Element('span.in_wanted', { + 'text': 'Already in wanted list: ' + self.info.in_wanted.label + }) : null, + self.info.in_library ? new Element('span.in_library', { + 'text': 'Already in library: ' + self.info.in_library.label + }) : null, self.title_select = new Element('select', { 'name': 'title' }), diff --git a/couchpotato/core/providers/movie/_modifier/main.py b/couchpotato/core/providers/movie/_modifier/main.py index 4d19d5d..4f58f40 100644 --- a/couchpotato/core/providers/movie/_modifier/main.py +++ b/couchpotato/core/providers/movie/_modifier/main.py @@ -1,6 +1,12 @@ -from couchpotato.core.event import addEvent +from couchpotato import get_session +from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.helpers.variable import mergeDicts +from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin +from couchpotato.core.settings.model import Library +import traceback + +log = CPLog(__name__) class MovieResultModifier(Plugin): @@ -8,12 +14,15 @@ class MovieResultModifier(Plugin): def __init__(self): addEvent('result.modify.movie.search', self.combineOnIMDB) - def combineOnIMDB(self, results): temp = {} unique = 1 + # Statuses + active_status = fireEvent('status.get', 'active', single = True) + done_status = fireEvent('status.get', 'done', single = True) + # Combine on imdb id for item in results: imdb = item.get('imdb') @@ -21,6 +30,24 @@ class MovieResultModifier(Plugin): if not temp.get(imdb): temp[imdb] = {} + temp[imdb]['in_wanted'] = False + temp[imdb]['in_library'] = False + + # Add release info from current library + try: + db = get_session() + l = db.query(Library).filter_by(identifier = imdb).first() + if l: + for movie in l.movies: + if movie.status_id == active_status['id']: + temp[imdb]['in_wanted'] = movie.profile.to_dict() + + for release in movie.releases: + if release.status_id == done_status['id']: + temp[imdb]['in_library'] = release.quality.to_dict() + except: + log.error('Tried getting more info on searched movies: %s' % traceback.format_exc()) + # Merge dicts temp[imdb] = mergeDicts(temp[imdb], item) else: