Nosql
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import traceback
|
||||
from couchpotato import get_session, get_db
|
||||
from couchpotato import get_session, get_db, tryInt
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import splitString
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from .index import ProfileIndex
|
||||
@@ -78,45 +79,41 @@ class ProfilePlugin(Plugin):
|
||||
def save(self, **kwargs):
|
||||
|
||||
try:
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
|
||||
p = db.query(Profile).filter_by(id = kwargs.get('id')).first()
|
||||
if not p:
|
||||
p = Profile()
|
||||
db.add(p)
|
||||
|
||||
p.label = toUnicode(kwargs.get('label'))
|
||||
p.order = kwargs.get('order', p.order if p.order else 0)
|
||||
p.core = kwargs.get('core', False)
|
||||
|
||||
#delete old types
|
||||
[db.delete(t) for t in p.types]
|
||||
profile = {
|
||||
'label': toUnicode(kwargs.get('label')),
|
||||
'order': tryInt(kwargs.get('order', 999)),
|
||||
'core': kwargs.get('core', False),
|
||||
'qualities': [],
|
||||
'wait_for': [],
|
||||
'finish': []
|
||||
}
|
||||
|
||||
# Update types
|
||||
order = 0
|
||||
for type in kwargs.get('types', []):
|
||||
t = ProfileType(
|
||||
order = order,
|
||||
finish = type.get('finish') if order > 0 else 1,
|
||||
wait_for = kwargs.get('wait_for'),
|
||||
quality_id = type.get('quality_id')
|
||||
)
|
||||
p.types.append(t)
|
||||
|
||||
profile['qualities'].append(type.get('quality'))
|
||||
profile['wait_for'].append(tryInt(type.get('wait_for')))
|
||||
profile['finish'].append((tryInt(type.get('finish')) == 1) if order > 0 else True)
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
id = kwargs.get('id')
|
||||
try:
|
||||
p = db.get('id', id)
|
||||
except:
|
||||
p = db.insert(profile)
|
||||
p.update(profile)
|
||||
|
||||
profile_dict = p.to_dict(self.to_dict)
|
||||
p['order'] = tryInt(kwargs.get('order', p.get('order', 999)))
|
||||
db.update(p)
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'profile': profile_dict
|
||||
'profile': p
|
||||
}
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
db.rollback()
|
||||
finally:
|
||||
pass #db.close()
|
||||
|
||||
return {
|
||||
'success': False
|
||||
@@ -129,26 +126,23 @@ class ProfilePlugin(Plugin):
|
||||
def saveOrder(self, **kwargs):
|
||||
|
||||
try:
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
|
||||
order = 0
|
||||
for profile in kwargs.get('ids', []):
|
||||
p = db.query(Profile).filter_by(id = profile).first()
|
||||
p.hide = kwargs.get('hidden')[order]
|
||||
p.order = order
|
||||
|
||||
for profile_id in kwargs.get('ids', []):
|
||||
p = db.get('id', profile_id)
|
||||
p['hide'] = tryInt(kwargs.get('hidden')[order]) == 1
|
||||
p['order'] = order
|
||||
db.update(p)
|
||||
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
'success': True
|
||||
}
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
db.rollback()
|
||||
finally:
|
||||
pass #db.close()
|
||||
|
||||
return {
|
||||
'success': False
|
||||
@@ -180,9 +174,6 @@ class ProfilePlugin(Plugin):
|
||||
}
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
db.rollback()
|
||||
finally:
|
||||
pass #db.close()
|
||||
|
||||
return {
|
||||
'success': False
|
||||
|
||||
@@ -57,14 +57,16 @@ var Profile = new Class({
|
||||
self.makeSortable();
|
||||
|
||||
// Combine qualities and properties into types
|
||||
data.types = [];
|
||||
data.qualities.each(function(quality, nr){
|
||||
data.types.include({
|
||||
'quality_identifier': quality,
|
||||
'finish': data.finish[nr] || false,
|
||||
'wait_for': data.wait_for[nr] || 0
|
||||
})
|
||||
});
|
||||
if(data.qualities){
|
||||
data.types = [];
|
||||
data.qualities.each(function(quality, nr){
|
||||
data.types.include({
|
||||
'quality': quality,
|
||||
'finish': data.finish[nr] || false,
|
||||
'wait_for': data.wait_for[nr] || 0
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
if(data.types)
|
||||
data.types.each(self.addType.bind(self));
|
||||
@@ -112,16 +114,16 @@ var Profile = new Class({
|
||||
var self = this;
|
||||
|
||||
var data = {
|
||||
'id' : self.data.id,
|
||||
'id' : self.data._id,
|
||||
'label' : self.el.getElement('.quality_label input').get('value'),
|
||||
'wait_for' : self.el.getElement('.wait_for input').get('value'),
|
||||
'types': []
|
||||
}
|
||||
|
||||
Array.each(self.type_container.getElements('.type'), function(type){
|
||||
if(!type.hasClass('deleted') && type.getElement('select').get('value') > 0)
|
||||
if(!type.hasClass('deleted') && type.getElement('select').get('value') != -1)
|
||||
data.types.include({
|
||||
'quality_identifier': type.getElement('select').get('value'),
|
||||
'quality': type.getElement('select').get('value'),
|
||||
'finish': +type.getElement('input[type=checkbox]').checked,
|
||||
'wait_for': 0
|
||||
});
|
||||
@@ -156,7 +158,7 @@ var Profile = new Class({
|
||||
var self = this;
|
||||
|
||||
return self.types.filter(function(type){
|
||||
return type.get('quality_identifier')
|
||||
return type.get('quality')
|
||||
});
|
||||
|
||||
},
|
||||
@@ -173,7 +175,7 @@ var Profile = new Class({
|
||||
(e).preventDefault();
|
||||
Api.request('profile.delete', {
|
||||
'data': {
|
||||
'id': self.data.id
|
||||
'id': self.data._id
|
||||
},
|
||||
'useSpinner': true,
|
||||
'spinnerOptions': {
|
||||
@@ -275,7 +277,7 @@ Profile.Type = new Class({
|
||||
new Element('span.handle')
|
||||
);
|
||||
|
||||
self.el[self.data.quality_identifier ? 'removeClass' : 'addClass']('is_empty');
|
||||
self.el[self.data.quality ? 'removeClass' : 'addClass']('is_empty');
|
||||
|
||||
self.finish_class = new Form.Check(self.finish);
|
||||
|
||||
@@ -302,7 +304,7 @@ Profile.Type = new Class({
|
||||
}).inject(self.qualities)
|
||||
});
|
||||
|
||||
self.qualities.set('value', self.data.quality_identifier);
|
||||
self.qualities.set('value', self.data.quality);
|
||||
|
||||
return self.qualities;
|
||||
|
||||
@@ -312,7 +314,7 @@ Profile.Type = new Class({
|
||||
var self = this;
|
||||
|
||||
return {
|
||||
'quality_identifier': self.qualities.get('value'),
|
||||
'quality': self.qualities.get('value'),
|
||||
'finish': +self.finish.checked,
|
||||
'wait_for': 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user