Make category destination editable
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
@@ -11,8 +11,6 @@ log = CPLog(__name__)
|
||||
|
||||
class CategoryPlugin(Plugin):
|
||||
|
||||
to_dict = {'destination': {}}
|
||||
|
||||
def __init__(self):
|
||||
addEvent('category.all', self.all)
|
||||
|
||||
@@ -41,7 +39,7 @@ class CategoryPlugin(Plugin):
|
||||
|
||||
temp = []
|
||||
for category in categories:
|
||||
temp.append(category.to_dict(self.to_dict))
|
||||
temp.append(category.to_dict())
|
||||
|
||||
db.expire_all()
|
||||
return temp
|
||||
@@ -61,10 +59,11 @@ class CategoryPlugin(Plugin):
|
||||
c.ignored = toUnicode(kwargs.get('ignored'))
|
||||
c.preferred = toUnicode(kwargs.get('preferred'))
|
||||
c.required = toUnicode(kwargs.get('required'))
|
||||
c.destination = toUnicode(kwargs.get('destination'))
|
||||
|
||||
db.commit()
|
||||
|
||||
category_dict = c.to_dict(self.to_dict)
|
||||
category_dict = c.to_dict()
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
|
||||
@@ -33,6 +33,28 @@ var CategoryListBase = new Class({
|
||||
|
||||
})
|
||||
|
||||
// Add categories in renamer
|
||||
self.settings.addEvent('create', function(){
|
||||
var renamer_group = self.settings.tabs.renamer.groups.renamer;
|
||||
|
||||
p(renamer_group.getElement('.renamer_to'))
|
||||
self.categories.each(function(category){
|
||||
|
||||
var input = new Option.Directory('section_name', 'option.name', category.get('destination'), {
|
||||
'name': category.get('label')
|
||||
});
|
||||
input.inject(renamer_group.getElement('.renamer_to'));
|
||||
input.fireEvent('injected');
|
||||
|
||||
input.save = function(){
|
||||
category.data.destination = input.getValue();
|
||||
category.save();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
createList: function(){
|
||||
@@ -68,7 +90,7 @@ var CategoryListBase = new Class({
|
||||
return category.data.id == id
|
||||
}).pick()
|
||||
},
|
||||
|
||||
|
||||
getAll: function(){
|
||||
return this.categories;
|
||||
},
|
||||
@@ -229,7 +251,7 @@ var Category = new Class({
|
||||
}
|
||||
});
|
||||
|
||||
}).delay(delay, self)
|
||||
}).delay(delay || 0, self)
|
||||
|
||||
},
|
||||
|
||||
@@ -241,7 +263,8 @@ var Category = new Class({
|
||||
'label' : self.el.getElement('.category_label input').get('value'),
|
||||
'required' : self.el.getElement('.category_required input').get('value'),
|
||||
'preferred' : self.el.getElement('.category_preferred input').get('value'),
|
||||
'ignored' : self.el.getElement('.category_ignored input').get('value')
|
||||
'ignored' : self.el.getElement('.category_ignored input').get('value'),
|
||||
'destination': self.data.destination
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
@@ -366,6 +366,7 @@ class MoviePlugin(Plugin):
|
||||
fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True)
|
||||
|
||||
default_profile = fireEvent('profile.default', single = True)
|
||||
cat_id = params.get('category_id', None)
|
||||
|
||||
db = get_session()
|
||||
m = db.query(Movie).filter_by(library_id = library.get('id')).first()
|
||||
@@ -376,6 +377,7 @@ class MoviePlugin(Plugin):
|
||||
library_id = library.get('id'),
|
||||
profile_id = params.get('profile_id', default_profile.get('id')),
|
||||
status_id = status_id if status_id else status_active.get('id'),
|
||||
category_id = tryInt(cat_id) if cat_id is not None and tryInt(cat_id) > 0 else None,
|
||||
)
|
||||
db.add(m)
|
||||
db.commit()
|
||||
@@ -397,6 +399,7 @@ class MoviePlugin(Plugin):
|
||||
fireEvent('release.delete', release.id, single = True)
|
||||
|
||||
m.profile_id = params.get('profile_id', default_profile.get('id'))
|
||||
m.category_id = tryInt(cat_id) if cat_id is not None and tryInt(cat_id) > 0 else None
|
||||
else:
|
||||
log.debug('Movie already exists, not updating: %s', params)
|
||||
added = False
|
||||
|
||||
@@ -159,8 +159,9 @@
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.movie_result .options select[name=title] { width: 180px; }
|
||||
.movie_result .options select[name=title] { width: 170px; }
|
||||
.movie_result .options select[name=profile] { width: 90px; }
|
||||
.movie_result .options select[name=category] { width: 80px; }
|
||||
|
||||
@media all and (max-width: 480px) {
|
||||
|
||||
|
||||
@@ -389,7 +389,6 @@ Block.Search.Item = new Class({
|
||||
|
||||
self.options_el.addClass('set');
|
||||
|
||||
p(self.info.in_wanted, self.info.in_wanted.profile, in_library);
|
||||
if(categories.length == 0 && self.title_select.getElements('option').length == 1 && profiles.length == 1 &&
|
||||
!(self.info.in_wanted && self.info.in_wanted.profile || in_library))
|
||||
self.add();
|
||||
|
||||
@@ -54,7 +54,7 @@ config = [{
|
||||
{
|
||||
'name': 'to',
|
||||
'type': 'directory',
|
||||
'description': 'Folder where the movies should be moved to.',
|
||||
'description': 'Default folder where the movies are moved to.',
|
||||
},
|
||||
{
|
||||
'name': 'folder_name',
|
||||
|
||||
@@ -129,7 +129,6 @@ class Renamer(Plugin):
|
||||
groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'),
|
||||
files = files, download_info = download_info, return_ignored = False, single = True)
|
||||
|
||||
destination = self.conf('to')
|
||||
folder_name = self.conf('folder_name')
|
||||
file_name = self.conf('file_name')
|
||||
trailer_name = self.conf('trailer_name')
|
||||
@@ -148,10 +147,6 @@ class Renamer(Plugin):
|
||||
remove_releases = []
|
||||
|
||||
movie_title = getTitle(group['library'])
|
||||
try:
|
||||
destination = group['category']['path']
|
||||
except:
|
||||
destination = self.conf('to')
|
||||
|
||||
# Add _UNKNOWN_ if no library item is connected
|
||||
if not group['library'] or not movie_title:
|
||||
@@ -165,8 +160,21 @@ class Renamer(Plugin):
|
||||
continue
|
||||
|
||||
library = group['library']
|
||||
library_ent = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
|
||||
movie_title = getTitle(library)
|
||||
|
||||
# Overwrite destination when set in category
|
||||
destination = self.conf('to')
|
||||
for movie in library_ent.movies:
|
||||
if movie.category and movie.category.destination and len(movie.category.destination) > 0:
|
||||
destination = movie.category.destination
|
||||
log.debug('Setting category destination for "%s": %s' % (movie_title, destination))
|
||||
else:
|
||||
log.debug('No category destination found for "%s"' % movie_title)
|
||||
|
||||
break
|
||||
|
||||
# Find subtitle for renaming
|
||||
group['before_rename'] = []
|
||||
fireEvent('renamer.before', group)
|
||||
@@ -319,17 +327,16 @@ class Renamer(Plugin):
|
||||
cd += 1
|
||||
|
||||
# Before renaming, remove the lower quality files
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
remove_leftovers = True
|
||||
|
||||
# Add it to the wanted list before we continue
|
||||
if len(library.movies) == 0:
|
||||
if len(library_ent.movies) == 0:
|
||||
profile = db.query(Profile).filter_by(core = True, label = group['meta_data']['quality']['label']).first()
|
||||
fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False)
|
||||
db.expire_all()
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
|
||||
for movie in library.movies:
|
||||
for movie in library_ent.movies:
|
||||
|
||||
# Mark movie "done" once it's found the quality with the finish check
|
||||
try:
|
||||
@@ -819,6 +826,6 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
||||
|
||||
def statusInfoComplete(self, item):
|
||||
return item['id'] and item['downloader'] and item['folder']
|
||||
|
||||
|
||||
def movieInFromFolder(self, movie_folder):
|
||||
return movie_folder and self.conf('from') in movie_folder or not movie_folder
|
||||
|
||||
@@ -216,17 +216,9 @@ class Category(Entity):
|
||||
required = Field(Unicode(255))
|
||||
preferred = Field(Unicode(255))
|
||||
ignored = Field(Unicode(255))
|
||||
destination = Field(Unicode(255))
|
||||
|
||||
movie = OneToMany('Movie')
|
||||
destination = ManyToOne('Destination')
|
||||
|
||||
|
||||
class Destination(Entity):
|
||||
""""""
|
||||
|
||||
path = Field(Unicode(255))
|
||||
|
||||
category = OneToMany('Category')
|
||||
|
||||
|
||||
class ProfileType(Entity):
|
||||
|
||||
@@ -329,8 +329,8 @@ var OptionBase = new Class({
|
||||
* Create the element
|
||||
*/
|
||||
createBase: function(){
|
||||
var self = this
|
||||
self.el = new Element('div.ctrlHolder')
|
||||
var self = this;
|
||||
self.el = new Element('div.ctrlHolder.'+self.section + '_' + self.name)
|
||||
},
|
||||
|
||||
create: function(){},
|
||||
|
||||
Reference in New Issue
Block a user