diff --git a/oml/changelog.py b/oml/changelog.py index f641fd4..05296e0 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -446,7 +446,7 @@ class Changelog(db.Model): listitems = data[2] #remove from additemlists removed = [] - if list_id in changes.get('addlistitems', {}): + if list_id in changes.get('addlistitems',{}): removed = [ i for i in changes['addlistitems'][list_id] if i in listitems ] diff --git a/oml/library.py b/oml/library.py index eee921e..09cc474 100644 --- a/oml/library.py +++ b/oml/library.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import codecs import json import os import time @@ -52,7 +53,7 @@ class Peer(object): def apply_log(self): changes = [] if os.path.exists(self._logpath): - with open(self._logpath, 'r', encoding='utf-8', newline='\n') as fd: + with codecs.open(self._logpath, 'r', encoding='utf-8') as fd: for line in fd: if line: try: @@ -446,9 +447,6 @@ def cleanup_peers(): other_peers[id] = peer.info['peers'][id] known_peers.add(id) for u in user.models.User.query.filter(user.models.User.id.notin_(list(known_peers))): - if state.nodes and u.id in state.nodes.local: - continue - if not u.pending: + if not 'local' in u.info and not u.pending: state.db.session.delete(u) - state.db.session.commit() diff --git a/oml/settings.py b/oml/settings.py index 5c06f74..39df3a2 100644 --- a/oml/settings.py +++ b/oml/settings.py @@ -95,4 +95,4 @@ FULLTEXT_SUPPORT = fulltext.platform_supported() if not FULLTEXT_SUPPORT: config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext'] -DB_VERSION = 20 +DB_VERSION = 18 diff --git a/oml/update.py b/oml/update.py index 10d24e2..3ae467a 100644 --- a/oml/update.py +++ b/oml/update.py @@ -379,10 +379,6 @@ class Update(Thread): db_version = migrate_17() if db_version < 18: db_version = migrate_18() - if db_version < 19: - db_version = migrate_19() - if db_version < 20: - db_version = migrate_20() settings.server['db_version'] = db_version def run(self): @@ -621,10 +617,10 @@ def migrate_13(): with db.session() as session: revision = -1 qs = changelog.Changelog.query.filter_by(user_id=settings.USER_ID) - with open(path, 'wb') as fd: + with open(path, 'w') as fd: for c in qs.order_by('timestamp'): - data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False).encode('utf-8') - fd.write(data + b'\n') + data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False) + fd.write(data + '\n') revision = c.revision if revision > -1: settings.server['revision'] = revision @@ -702,37 +698,3 @@ def migrate_18(): 'CREATE INDEX ix_annotation_findnotes ON annotation (findnotes)' ]) return 18 - -def migrate_19(): - from user.models import User - with db.session(): - peers = [u for u in User.query.filter_by(peered=True)] - peers.sort(key=lambda u: utils.user_sort_key(u.json())) - for u in peers: - peer = utils.get_peer(u.id) - if not peer.info.get('revision') and os.path.exists(peer._logpath) and os.path.getsize(peer._logpath): - logger.debug('try to apply pending logs for %s', u.id) - try: - peer.apply_log() - except: - logger.error('failed to apply log for %s', u.id) - return 19 - -def migrate_20(): - from glob import glob - changed = False - for log in glob(os.path.join(settings.data_path, 'peers', '*.log')): - with open(log, 'rb') as fd: - data = fd.read() - try: - data.decode('utf-8') - except UnicodeDecodeError: - data = data.decode('Windows-1252') - logger.error('convert %s to utf-8', log) - with open(log, 'wb') as fd: - fd.write(data.encode('utf-8')) - changed = True - - if changed: - migrate_19() - return 20 diff --git a/static/js/annotationPanel.js b/static/js/annotationPanel.js index e9fee31..f0cf0e5 100644 --- a/static/js/annotationPanel.js +++ b/static/js/annotationPanel.js @@ -64,6 +64,17 @@ oml.ui.annotationPanel = function(options, self) { // borderColor: 'transparent', float: 'right' }).bindEvent({ + change: function(data) { + if (data.id == 'showAnnotationUsers') { + var value = data.checked[0].id; + oml.UI.set('showAnnotationUsers', value); + oml.$ui.viewer.renderAnnotations(); + } else if (data.id == 'sortAnnotations') { + var value = data.checked[0].id; + oml.UI.set('sortAnnotations', value); + oml.$ui.viewer.renderAnnotations(); + } + }, click: function(data) { var id = data.id; if (id == 'exportAnnotations') { @@ -87,14 +98,8 @@ oml.ui.annotationPanel = function(options, self) { }, change: function(data) { var id = data.id; - if (data.id == 'showAnnotationUsers') { - var value = data.checked[0].id; - oml.UI.set('showAnnotationUsers', value); - oml.$ui.viewer.renderAnnotations(); - } else if (data.id == 'sortAnnotations') { - var value = data.checked[0].id; - oml.UI.set('sortAnnotations', value); - } else if (id == 'show') { + console.log('change', data) + if (id == 'show') { console.log('show', data) oml.UI.set({annotationsShow: data.checked[0].id}); } else if (id == 'sort') { diff --git a/static/js/viewer.js b/static/js/viewer.js index 616aacf..24c48a2 100644 --- a/static/js/viewer.js +++ b/static/js/viewer.js @@ -206,6 +206,9 @@ oml.ui.viewer = function() { if (sortKey == 'date') { sortKey = 'created' } + if (sortKey == 'date') { + sortKey = 'created' + } if (sortKey == 'quote') { sortKey = 'text' } @@ -213,7 +216,6 @@ oml.ui.viewer = function() { loadAnnotations(function() { that.renderAnnotations() }) - return } annotations = Ox.sortBy(annotations, sortKey) oml.$ui.annotationFolder.empty();