lists, change loops
This commit is contained in:
parent
21072c0941
commit
e15ce62ee5
5 changed files with 21 additions and 10 deletions
|
@ -171,14 +171,16 @@ class Changelog(db.Model):
|
||||||
if not meta[key] and i.meta.get('primaryid', [''])[0] == key:
|
if not meta[key] and i.meta.get('primaryid', [''])[0] == key:
|
||||||
logger.debug('remove id mapping %s %s', i.id, primary)
|
logger.debug('remove id mapping %s %s', i.id, primary)
|
||||||
i.update_primaryid(*primary)
|
i.update_primaryid(*primary)
|
||||||
|
i.modified = ts2datetime(timestamp)
|
||||||
elif meta[key] and i.meta.get('primaryid') != primary:
|
elif meta[key] and i.meta.get('primaryid') != primary:
|
||||||
logger.debug('edit mapping %s %s', i.id, primary)
|
logger.debug('edit mapping %s %s', i.id, primary)
|
||||||
i.update_primaryid(*primary)
|
i.update_primaryid(*primary)
|
||||||
|
i.modified = ts2datetime(timestamp)
|
||||||
else:
|
else:
|
||||||
if 'primaryid' in i.meta:
|
if 'primaryid' in i.meta:
|
||||||
return True
|
return True
|
||||||
i.update_meta(meta)
|
i.update_meta(meta)
|
||||||
i.modified = ts2datetime(timestamp)
|
i.modified = ts2datetime(timestamp)
|
||||||
i.save()
|
i.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -251,6 +251,7 @@ class Node(Thread):
|
||||||
with self._app.app_context():
|
with self._app.app_context():
|
||||||
last = Changelog.query.filter_by(user_id=self.user_id).order_by('-revision').first()
|
last = Changelog.query.filter_by(user_id=self.user_id).order_by('-revision').first()
|
||||||
from_revision = last.revision + 1 if last else 0
|
from_revision = last.revision + 1 if last else 0
|
||||||
|
logger.debug('pullChanges %s from %s', self.user.name, from_revision)
|
||||||
changes = self.request('pullChanges', from_revision)
|
changes = self.request('pullChanges', from_revision)
|
||||||
if not changes:
|
if not changes:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -126,7 +126,7 @@ class Parser(object):
|
||||||
l = None
|
l = None
|
||||||
if l:
|
if l:
|
||||||
v = l.find_id
|
v = l.find_id
|
||||||
if l and l._query:
|
if l and l.type == 'smart':
|
||||||
data = l._query
|
data = l._query
|
||||||
q = self.parse_conditions(data.get('conditions', []),
|
q = self.parse_conditions(data.get('conditions', []),
|
||||||
data.get('operator', '&'))
|
data.get('operator', '&'))
|
||||||
|
|
|
@ -117,13 +117,19 @@ def getLists(data):
|
||||||
actions.register(getLists)
|
actions.register(getLists)
|
||||||
|
|
||||||
def validate_query(query):
|
def validate_query(query):
|
||||||
for condition in query['conditions']:
|
validate_conditions(query['conditions'])
|
||||||
if not list(sorted(condition.keys())) in (
|
|
||||||
['conditions', 'operator'],
|
|
||||||
['key', 'operator', 'value']
|
|
||||||
):
|
|
||||||
raise Exception('invalid query condition', condition)
|
|
||||||
|
|
||||||
|
def validate_conditions(conditions):
|
||||||
|
for c in conditions:
|
||||||
|
if 'conditions' in c:
|
||||||
|
if list(sorted(c.keys())) != ['conditions', 'operator']:
|
||||||
|
raise Exception('invalid query condition', c)
|
||||||
|
validate_conditions(c)
|
||||||
|
else:
|
||||||
|
if list(sorted(c.keys())) != ['key', 'operator', 'value']:
|
||||||
|
raise Exception('invalid query condition', c)
|
||||||
|
if c['key'] == 'list' and ':' not in c['value']:
|
||||||
|
raise Exception('invalid query condition', c)
|
||||||
|
|
||||||
def addList(data):
|
def addList(data):
|
||||||
'''
|
'''
|
||||||
|
@ -161,7 +167,9 @@ def editList(data):
|
||||||
name = l.name
|
name = l.name
|
||||||
if 'name' in data:
|
if 'name' in data:
|
||||||
l.name = data['name']
|
l.name = data['name']
|
||||||
if 'query' in data:
|
if 'query' in data and l.type != 'smart':
|
||||||
|
raise Exception('query only for smart lists')
|
||||||
|
if 'query' in data and l.type == 'smart':
|
||||||
validate_query(data['query'])
|
validate_query(data['query'])
|
||||||
l._query = data['query']
|
l._query = data['query']
|
||||||
if l.type == 'static' and name != l.name:
|
if l.type == 'static' and name != l.name:
|
||||||
|
|
|
@ -91,7 +91,7 @@ oml.ui.listDialog = function() {
|
||||||
}],
|
}],
|
||||||
operator: '&'
|
operator: '&'
|
||||||
}
|
}
|
||||||
});
|
}, false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue