Compare commits
6 Commits
b7d140e36a
...
111ea307a9
Author | SHA1 | Date |
---|---|---|
j | 111ea307a9 | |
j | 349383ff39 | |
j | 7ee959cd11 | |
j | b3246f05db | |
j | 08a3477e88 | |
j | 739cfd8c9d |
|
@ -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
|
||||
]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import codecs
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
@ -53,7 +52,7 @@ class Peer(object):
|
|||
def apply_log(self):
|
||||
changes = []
|
||||
if os.path.exists(self._logpath):
|
||||
with codecs.open(self._logpath, 'r', encoding='utf-8') as fd:
|
||||
with open(self._logpath, 'r', encoding='utf-8', newline='\n') as fd:
|
||||
for line in fd:
|
||||
if line:
|
||||
try:
|
||||
|
@ -447,6 +446,9 @@ 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 not 'local' in u.info and not u.pending:
|
||||
if state.nodes and u.id in state.nodes.local:
|
||||
continue
|
||||
if not u.pending:
|
||||
state.db.session.delete(u)
|
||||
|
||||
state.db.session.commit()
|
||||
|
|
|
@ -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 = 18
|
||||
DB_VERSION = 20
|
||||
|
|
|
@ -379,6 +379,10 @@ 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):
|
||||
|
@ -617,10 +621,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, 'w') as fd:
|
||||
with open(path, 'wb') as fd:
|
||||
for c in qs.order_by('timestamp'):
|
||||
data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False)
|
||||
fd.write(data + '\n')
|
||||
data = json.dumps([c.revision, c.timestamp, json.loads(c.data)], ensure_ascii=False).encode('utf-8')
|
||||
fd.write(data + b'\n')
|
||||
revision = c.revision
|
||||
if revision > -1:
|
||||
settings.server['revision'] = revision
|
||||
|
@ -698,3 +702,37 @@ 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
|
||||
|
|
|
@ -64,17 +64,6 @@ 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') {
|
||||
|
@ -98,8 +87,14 @@ oml.ui.annotationPanel = function(options, self) {
|
|||
},
|
||||
change: function(data) {
|
||||
var id = data.id;
|
||||
console.log('change', data)
|
||||
if (id == 'show') {
|
||||
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('show', data)
|
||||
oml.UI.set({annotationsShow: data.checked[0].id});
|
||||
} else if (id == 'sort') {
|
||||
|
|
|
@ -206,9 +206,6 @@ oml.ui.viewer = function() {
|
|||
if (sortKey == 'date') {
|
||||
sortKey = 'created'
|
||||
}
|
||||
if (sortKey == 'date') {
|
||||
sortKey = 'created'
|
||||
}
|
||||
if (sortKey == 'quote') {
|
||||
sortKey = 'text'
|
||||
}
|
||||
|
@ -216,6 +213,7 @@ oml.ui.viewer = function() {
|
|||
loadAnnotations(function() {
|
||||
that.renderAnnotations()
|
||||
})
|
||||
return
|
||||
}
|
||||
annotations = Ox.sortBy(annotations, sortKey)
|
||||
oml.$ui.annotationFolder.empty();
|
||||
|
|
Loading…
Reference in New Issue