lists, change loops

This commit is contained in:
j 2014-05-25 22:08:44 +02:00
parent 21072c0941
commit e15ce62ee5
5 changed files with 21 additions and 10 deletions

View File

@ -171,14 +171,16 @@ class Changelog(db.Model):
if not meta[key] and i.meta.get('primaryid', [''])[0] == key:
logger.debug('remove id mapping %s %s', i.id, primary)
i.update_primaryid(*primary)
i.modified = ts2datetime(timestamp)
elif meta[key] and i.meta.get('primaryid') != primary:
logger.debug('edit mapping %s %s', i.id, primary)
i.update_primaryid(*primary)
i.modified = ts2datetime(timestamp)
else:
if 'primaryid' in i.meta:
return True
i.update_meta(meta)
i.modified = ts2datetime(timestamp)
i.modified = ts2datetime(timestamp)
i.save()
return True

View File

@ -251,6 +251,7 @@ class Node(Thread):
with self._app.app_context():
last = Changelog.query.filter_by(user_id=self.user_id).order_by('-revision').first()
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)
if not changes:
return False

View File

@ -126,7 +126,7 @@ class Parser(object):
l = None
if l:
v = l.find_id
if l and l._query:
if l and l.type == 'smart':
data = l._query
q = self.parse_conditions(data.get('conditions', []),
data.get('operator', '&'))

View File

@ -117,13 +117,19 @@ def getLists(data):
actions.register(getLists)
def validate_query(query):
for condition in query['conditions']:
if not list(sorted(condition.keys())) in (
['conditions', 'operator'],
['key', 'operator', 'value']
):
raise Exception('invalid query condition', condition)
validate_conditions(query['conditions'])
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):
'''
@ -161,7 +167,9 @@ def editList(data):
name = l.name
if 'name' in data:
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'])
l._query = data['query']
if l.type == 'static' and name != l.name:

View File

@ -91,7 +91,7 @@ oml.ui.listDialog = function() {
}],
operator: '&'
}
});
}, false);
});
});
}