From 0115bf254e84062db9eea257cec19710bce7019d Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 19 Mar 2013 22:55:10 +0100 Subject: [PATCH] Force default profile on movies without profile. fix #1523 --- couchpotato/core/plugins/profile/main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/plugins/profile/main.py b/couchpotato/core/plugins/profile/main.py index 4caa54f..3dd89d9 100644 --- a/couchpotato/core/plugins/profile/main.py +++ b/couchpotato/core/plugins/profile/main.py @@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.helpers.request import jsonified, getParams, getParam from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin -from couchpotato.core.settings.model import Profile, ProfileType +from couchpotato.core.settings.model import Profile, ProfileType, Movie log = CPLog(__name__) @@ -30,6 +30,21 @@ class ProfilePlugin(Plugin): }) addEvent('app.initialize', self.fill, priority = 90) + addEvent('app.load', self.forceDefaults) + + def forceDefaults(self): + + # Get all active movies without profile + active_status = fireEvent('status.get', 'active', single = True) + + db = get_session() + movies = db.query(Movie).filter(Movie.status_id == active_status.get('id'), Movie.profile == None).all() + + if len(movies) > 0: + default_profile = self.default() + for movie in movies: + movie.profile_id = default_profile.get('id') + db.commit() def allView(self): @@ -129,6 +144,9 @@ class ProfilePlugin(Plugin): db.delete(p) db.commit() + # Force defaults on all empty profile movies + self.forceDefaults() + success = True except Exception, e: message = log.error('Failed deleting Profile: %s', e)