extract textsize, take timestamp for changelog entries update peers on peering events

This commit is contained in:
j 2014-05-19 11:38:41 +02:00
parent b6866cb2be
commit 9aef3616ba
6 changed files with 24 additions and 9 deletions

View file

@ -82,7 +82,7 @@ class Changelog(db.Model):
sig = settings.sk.sign(_data, encoding='base64') sig = settings.sk.sign(_data, encoding='base64')
if valid(user.id, _data, sig): if valid(user.id, _data, sig):
c = cls() c = cls()
c.created = datetime.now() c.created = datetime.fromtimestamp(float(timestamp))
c.user_id = user.id c.user_id = user.id
c.revision = revision c.revision = revision
c.data = data c.data = data
@ -144,9 +144,13 @@ class Changelog(db.Model):
from item.models import Item from item.models import Item
i = Item.get(itemid) i = Item.get(itemid)
if i and i.timestamp > timestamp: if i and i.timestamp > timestamp:
if user not in i.users:
i.users.append(user)
i.update()
return True return True
if not i: if not i:
i = Item.get_or_create(itemid, info) i = Item.get_or_create(itemid, info)
i.modified = datetime.fromtimestamp(float(timestamp))
i.users.append(user) i.users.append(user)
i.update() i.update()
return True return True
@ -163,6 +167,8 @@ class Changelog(db.Model):
elif meta[key] and (i.meta.get('mainid') != key or meta[key] != i.meta.get(key)): elif meta[key] and (i.meta.get('mainid') != key or meta[key] != i.meta.get(key)):
logger.debug('new mapping %s %s currently %s %s', key, meta[key], i.meta.get('mainid'), i.meta.get(i.meta.get('mainid'))) logger.debug('new mapping %s %s currently %s %s', key, meta[key], i.meta.get('mainid'), i.meta.get(i.meta.get('mainid')))
i.update_mainid(key, meta[key]) i.update_mainid(key, meta[key])
i.modified = datetime.fromtimestamp(float(timestamp))
i.save()
return True return True
def action_removeitem(self, user, timestamp, itemid): def action_removeitem(self, user, timestamp, itemid):

View file

@ -259,7 +259,7 @@ class Item(db.Model):
self.update_sort() self.update_sort()
self.update_find() self.update_find()
self.update_lists() self.update_lists()
self.modified = datetime.now() #self.modified = datetime.now()
self.save() self.save()
def save(self): def save(self):
@ -289,6 +289,7 @@ class Item(db.Model):
self.scrape() self.scrape()
self.update() self.update()
self.update_cover() self.update_cover()
self.modified = datetime.now()
db.session.add(self) db.session.add(self)
db.session.commit() db.session.commit()
user = User.get_or_create(settings.USER_ID) user = User.get_or_create(settings.USER_ID)

View file

@ -31,7 +31,10 @@ def metadata(f):
elif ext == 'txt': elif ext == 'txt':
info = txt.info(f) info = txt.info(f)
for key in ('title', 'author', 'date', 'publisher', 'isbn'): for key in (
'title', 'author', 'date', 'publisher', 'isbn',
'textsize', 'pages'
):
if key in info: if key in info:
value = info[key] value = info[key]
if isinstance(value, str): if isinstance(value, str):

View file

@ -75,7 +75,6 @@ def info(pdf):
info = pdfreader.getDocumentInfo() info = pdfreader.getDocumentInfo()
if info: if info:
for key in info: for key in info:
print key, info
if info[key]: if info[key]:
data[key[1:].lower()] = info[key] data[key[1:].lower()] = info[key]
xmp =pdfreader.getXmpMetadata() xmp =pdfreader.getXmpMetadata()

View file

@ -55,7 +55,7 @@ def api_requestPeering(app, user_id, username, message):
user.info['username'] = username user.info['username'] = username
user.info['message'] = message user.info['message'] = message
user.save() user.save()
trigger_event('peering', user.json()) trigger_event('peering.request', user.json())
return True return True
return False return False
@ -70,7 +70,7 @@ def api_acceptPeering(app, user_id, username, message):
user.info['username'] = username user.info['username'] = username
user.info['message'] = message user.info['message'] = message
user.update_peering(True, username) user.update_peering(True, username)
trigger_event('peering', user.json()) trigger_event('peering.accept', user.json())
state.nodes.queue('add', user.id) state.nodes.queue('add', user.id)
return True return True
return False return False
@ -82,7 +82,7 @@ def api_rejectPeering(app, user_id, message):
user.info = {} user.info = {}
user.info['message'] = message user.info['message'] = message
user.update_peering(False) user.update_peering(False)
trigger_event('peering', user.json()) trigger_event('peering.reject', user.json())
return True return True
return False return False
@ -91,7 +91,7 @@ def api_removePeering(app, user_id, message):
if user: if user:
user.info['message'] = message user.info['message'] = message
user.update_peering(False) user.update_peering(False)
trigger_event('peering', user.json()) trigger_event('peering.remove', user.json())
return True return True
return False return False
@ -100,6 +100,6 @@ def api_cancelPeering(app, user_id, message):
if user: if user:
user.info['message'] = message user.info['message'] = message
user.update_peering(False) user.update_peering(False)
trigger_event('peering', user.json()) trigger_event('peering.cancel', user.json())
return True return True
return False return False

View file

@ -315,6 +315,12 @@ oml.ui.folders = function() {
if (data.activity == 'import') { if (data.activity == 'import') {
that.updateItems(); that.updateItems();
} }
},
'peering.accept': function(data) {
that.updateElement();
},
'peering.remove': function(data) {
that.updateElement();
} }
}); });