diff --git a/oml/gtkwebkit.py b/oml/gtkwebkit.py index bc4e97b..88d6648 100755 --- a/oml/gtkwebkit.py +++ b/oml/gtkwebkit.py @@ -2,6 +2,7 @@ import os from os.path import dirname, abspath import subprocess +import webbrowser import gi gi.require_version('WebKit2', '4.0') @@ -21,6 +22,14 @@ def on_key_press_event(widget, event): if event.state & Gdk.ModifierType.CONTROL_MASK and event.keyval == 113: Gtk.main_quit() +def on_decide_policy(view, decision, dtype): + uri = decision.get_request().get_uri() + if uri.startswith("http") and not '127.0.0.1' in uri: + decision.ignore() + webbrowser.open_new(uri) + return True + return False + wnd = Gtk.Window() wnd.set_icon_from_file(icon) @@ -35,6 +44,8 @@ wnd.connect('key_press_event', on_key_press_event) wnd.add(web) wnd.show_all() +web.connect("decide-policy", on_decide_policy) + url = 'file://' + base + '/openmedialibrary/static/html/load.html' web.load_uri(url) diff --git a/oml/item/models.py b/oml/item/models.py index 8145bd6..1cb672a 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -531,6 +531,9 @@ class File(db.Model): j = self.item.json() current_path = self.fullpath() + if not os.path.exists(current_path): + logger.debug('file is missing. %s', current_path) + return author = '; '.join([ox.canonical_name(a) for a in j.get('author', [])]) if not author: author = 'Unknown Author'