From 9aef3616ba7ee4e6975b71e9c6b12484aacbc2e8 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 19 May 2014 11:38:41 +0200 Subject: [PATCH] extract textsize, take timestamp for changelog entries update peers on peering events --- oml/changelog.py | 8 +++++++- oml/item/models.py | 3 ++- oml/media/__init__.py | 5 ++++- oml/media/pdf.py | 1 - oml/node/nodeapi.py | 10 +++++----- static/js/folders.js | 6 ++++++ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/oml/changelog.py b/oml/changelog.py index b623e11..f2df8e6 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -82,7 +82,7 @@ class Changelog(db.Model): sig = settings.sk.sign(_data, encoding='base64') if valid(user.id, _data, sig): c = cls() - c.created = datetime.now() + c.created = datetime.fromtimestamp(float(timestamp)) c.user_id = user.id c.revision = revision c.data = data @@ -144,9 +144,13 @@ class Changelog(db.Model): from item.models import Item i = Item.get(itemid) if i and i.timestamp > timestamp: + if user not in i.users: + i.users.append(user) + i.update() return True if not i: i = Item.get_or_create(itemid, info) + i.modified = datetime.fromtimestamp(float(timestamp)) i.users.append(user) i.update() 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)): 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.modified = datetime.fromtimestamp(float(timestamp)) + i.save() return True def action_removeitem(self, user, timestamp, itemid): diff --git a/oml/item/models.py b/oml/item/models.py index fbcf914..ce0446a 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -259,7 +259,7 @@ class Item(db.Model): self.update_sort() self.update_find() self.update_lists() - self.modified = datetime.now() + #self.modified = datetime.now() self.save() def save(self): @@ -289,6 +289,7 @@ class Item(db.Model): self.scrape() self.update() self.update_cover() + self.modified = datetime.now() db.session.add(self) db.session.commit() user = User.get_or_create(settings.USER_ID) diff --git a/oml/media/__init__.py b/oml/media/__init__.py index 0bb6f6c..eea589b 100644 --- a/oml/media/__init__.py +++ b/oml/media/__init__.py @@ -31,7 +31,10 @@ def metadata(f): elif ext == 'txt': 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: value = info[key] if isinstance(value, str): diff --git a/oml/media/pdf.py b/oml/media/pdf.py index dfac951..2ed915d 100644 --- a/oml/media/pdf.py +++ b/oml/media/pdf.py @@ -75,7 +75,6 @@ def info(pdf): info = pdfreader.getDocumentInfo() if info: for key in info: - print key, info if info[key]: data[key[1:].lower()] = info[key] xmp =pdfreader.getXmpMetadata() diff --git a/oml/node/nodeapi.py b/oml/node/nodeapi.py index 4405b5d..9cd70d7 100644 --- a/oml/node/nodeapi.py +++ b/oml/node/nodeapi.py @@ -55,7 +55,7 @@ def api_requestPeering(app, user_id, username, message): user.info['username'] = username user.info['message'] = message user.save() - trigger_event('peering', user.json()) + trigger_event('peering.request', user.json()) return True return False @@ -70,7 +70,7 @@ def api_acceptPeering(app, user_id, username, message): user.info['username'] = username user.info['message'] = message user.update_peering(True, username) - trigger_event('peering', user.json()) + trigger_event('peering.accept', user.json()) state.nodes.queue('add', user.id) return True return False @@ -82,7 +82,7 @@ def api_rejectPeering(app, user_id, message): user.info = {} user.info['message'] = message user.update_peering(False) - trigger_event('peering', user.json()) + trigger_event('peering.reject', user.json()) return True return False @@ -91,7 +91,7 @@ def api_removePeering(app, user_id, message): if user: user.info['message'] = message user.update_peering(False) - trigger_event('peering', user.json()) + trigger_event('peering.remove', user.json()) return True return False @@ -100,6 +100,6 @@ def api_cancelPeering(app, user_id, message): if user: user.info['message'] = message user.update_peering(False) - trigger_event('peering', user.json()) + trigger_event('peering.cancel', user.json()) return True return False diff --git a/static/js/folders.js b/static/js/folders.js index 5cf94f2..499ec5c 100644 --- a/static/js/folders.js +++ b/static/js/folders.js @@ -315,6 +315,12 @@ oml.ui.folders = function() { if (data.activity == 'import') { that.updateItems(); } + }, + 'peering.accept': function(data) { + that.updateElement(); + }, + 'peering.remove': function(data) { + that.updateElement(); } });