Browse Source

Make category destination editable

pull/1941/merge
Ruud 12 years ago
parent
commit
623571acbb
  1. 9
      couchpotato/core/plugins/category/main.py
  2. 29
      couchpotato/core/plugins/category/static/category.js
  3. 3
      couchpotato/core/plugins/movie/main.py
  4. 3
      couchpotato/core/plugins/movie/static/search.css
  5. 1
      couchpotato/core/plugins/movie/static/search.js
  6. 2
      couchpotato/core/plugins/renamer/__init__.py
  7. 25
      couchpotato/core/plugins/renamer/main.py
  8. 10
      couchpotato/core/settings/model.py
  9. 4
      couchpotato/static/scripts/page/settings.js

9
couchpotato/core/plugins/category/main.py

@ -1,6 +1,6 @@
from couchpotato import get_session from couchpotato import get_session
from couchpotato.api import addApiView 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.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
@ -11,8 +11,6 @@ log = CPLog(__name__)
class CategoryPlugin(Plugin): class CategoryPlugin(Plugin):
to_dict = {'destination': {}}
def __init__(self): def __init__(self):
addEvent('category.all', self.all) addEvent('category.all', self.all)
@ -41,7 +39,7 @@ class CategoryPlugin(Plugin):
temp = [] temp = []
for category in categories: for category in categories:
temp.append(category.to_dict(self.to_dict)) temp.append(category.to_dict())
db.expire_all() db.expire_all()
return temp return temp
@ -61,10 +59,11 @@ class CategoryPlugin(Plugin):
c.ignored = toUnicode(kwargs.get('ignored')) c.ignored = toUnicode(kwargs.get('ignored'))
c.preferred = toUnicode(kwargs.get('preferred')) c.preferred = toUnicode(kwargs.get('preferred'))
c.required = toUnicode(kwargs.get('required')) c.required = toUnicode(kwargs.get('required'))
c.destination = toUnicode(kwargs.get('destination'))
db.commit() db.commit()
category_dict = c.to_dict(self.to_dict) category_dict = c.to_dict()
return { return {
'success': True, 'success': True,

29
couchpotato/core/plugins/category/static/category.js

@ -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(){ createList: function(){
@ -68,7 +90,7 @@ var CategoryListBase = new Class({
return category.data.id == id return category.data.id == id
}).pick() }).pick()
}, },
getAll: function(){ getAll: function(){
return this.categories; 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'), 'label' : self.el.getElement('.category_label input').get('value'),
'required' : self.el.getElement('.category_required input').get('value'), 'required' : self.el.getElement('.category_required input').get('value'),
'preferred' : self.el.getElement('.category_preferred 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 return data

3
couchpotato/core/plugins/movie/main.py

@ -366,6 +366,7 @@ class MoviePlugin(Plugin):
fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True) fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True)
default_profile = fireEvent('profile.default', single = True) default_profile = fireEvent('profile.default', single = True)
cat_id = params.get('category_id', None)
db = get_session() db = get_session()
m = db.query(Movie).filter_by(library_id = library.get('id')).first() m = db.query(Movie).filter_by(library_id = library.get('id')).first()
@ -376,6 +377,7 @@ class MoviePlugin(Plugin):
library_id = library.get('id'), library_id = library.get('id'),
profile_id = params.get('profile_id', default_profile.get('id')), profile_id = params.get('profile_id', default_profile.get('id')),
status_id = status_id if status_id else status_active.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.add(m)
db.commit() db.commit()
@ -397,6 +399,7 @@ class MoviePlugin(Plugin):
fireEvent('release.delete', release.id, single = True) fireEvent('release.delete', release.id, single = True)
m.profile_id = params.get('profile_id', default_profile.get('id')) 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: else:
log.debug('Movie already exists, not updating: %s', params) log.debug('Movie already exists, not updating: %s', params)
added = False added = False

3
couchpotato/core/plugins/movie/static/search.css

@ -159,8 +159,9 @@
display: inline-block; display: inline-block;
margin-right: 10px; 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=profile] { width: 90px; }
.movie_result .options select[name=category] { width: 80px; }
@media all and (max-width: 480px) { @media all and (max-width: 480px) {

1
couchpotato/core/plugins/movie/static/search.js

@ -389,7 +389,6 @@ Block.Search.Item = new Class({
self.options_el.addClass('set'); 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 && 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.info.in_wanted && self.info.in_wanted.profile || in_library))
self.add(); self.add();

2
couchpotato/core/plugins/renamer/__init__.py

@ -54,7 +54,7 @@ config = [{
{ {
'name': 'to', 'name': 'to',
'type': 'directory', 'type': 'directory',
'description': 'Folder where the movies should be moved to.', 'description': 'Default folder where the movies are moved to.',
}, },
{ {
'name': 'folder_name', 'name': 'folder_name',

25
couchpotato/core/plugins/renamer/main.py

@ -129,7 +129,6 @@ class Renamer(Plugin):
groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'),
files = files, download_info = download_info, return_ignored = False, single = True) files = files, download_info = download_info, return_ignored = False, single = True)
destination = self.conf('to')
folder_name = self.conf('folder_name') folder_name = self.conf('folder_name')
file_name = self.conf('file_name') file_name = self.conf('file_name')
trailer_name = self.conf('trailer_name') trailer_name = self.conf('trailer_name')
@ -148,10 +147,6 @@ class Renamer(Plugin):
remove_releases = [] remove_releases = []
movie_title = getTitle(group['library']) movie_title = getTitle(group['library'])
try:
destination = group['category']['path']
except:
destination = self.conf('to')
# Add _UNKNOWN_ if no library item is connected # Add _UNKNOWN_ if no library item is connected
if not group['library'] or not movie_title: if not group['library'] or not movie_title:
@ -165,8 +160,21 @@ class Renamer(Plugin):
continue continue
library = group['library'] library = group['library']
library_ent = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
movie_title = getTitle(library) 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 # Find subtitle for renaming
group['before_rename'] = [] group['before_rename'] = []
fireEvent('renamer.before', group) fireEvent('renamer.before', group)
@ -319,17 +327,16 @@ class Renamer(Plugin):
cd += 1 cd += 1
# Before renaming, remove the lower quality files # Before renaming, remove the lower quality files
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
remove_leftovers = True remove_leftovers = True
# Add it to the wanted list before we continue # 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() 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) fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False)
db.expire_all() db.expire_all()
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first() 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 # Mark movie "done" once it's found the quality with the finish check
try: 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): def statusInfoComplete(self, item):
return item['id'] and item['downloader'] and item['folder'] return item['id'] and item['downloader'] and item['folder']
def movieInFromFolder(self, movie_folder): def movieInFromFolder(self, movie_folder):
return movie_folder and self.conf('from') in movie_folder or not movie_folder return movie_folder and self.conf('from') in movie_folder or not movie_folder

10
couchpotato/core/settings/model.py

@ -216,17 +216,9 @@ class Category(Entity):
required = Field(Unicode(255)) required = Field(Unicode(255))
preferred = Field(Unicode(255)) preferred = Field(Unicode(255))
ignored = Field(Unicode(255)) ignored = Field(Unicode(255))
destination = Field(Unicode(255))
movie = OneToMany('Movie') movie = OneToMany('Movie')
destination = ManyToOne('Destination')
class Destination(Entity):
""""""
path = Field(Unicode(255))
category = OneToMany('Category')
class ProfileType(Entity): class ProfileType(Entity):

4
couchpotato/static/scripts/page/settings.js

@ -329,8 +329,8 @@ var OptionBase = new Class({
* Create the element * Create the element
*/ */
createBase: function(){ createBase: function(){
var self = this var self = this;
self.el = new Element('div.ctrlHolder') self.el = new Element('div.ctrlHolder.'+self.section + '_' + self.name)
}, },
create: function(){}, create: function(){},

Loading…
Cancel
Save