From a3f811a6e8589fc4b47c9f3036ac1cf0c8b0e200 Mon Sep 17 00:00:00 2001
From: Christopher Allan Webber
Date: Mon, 28 Jan 2013 11:58:38 -0600
Subject: [PATCH] Geolocation stuff, including including templates seems to be
working-ish
- I'm having trouble seeing if the geolocation stuff actually works,
but plugins are included
- including a list of template hooks works, however the macro to
include them does not, so it's kinda verbose
---
mediagoblin/plugins/geolocation/__init__.py | 35 +++++++++++++++++++
.../plugins/geolocation/map_js_head.html | 25 +++++++++++++
.../mediagoblin/media_displays/image.html | 12 +++++--
.../mediagoblin/user_pages/media.html | 6 ++--
.../mediagoblin/utils/templatehooks.html | 22 ++++++++++++
mediagoblin/tools/pluginapi.py | 9 ++++-
mediagoblin/tools/template.py | 4 +++
7 files changed, 105 insertions(+), 8 deletions(-)
create mode 100644 mediagoblin/plugins/geolocation/__init__.py
create mode 100644 mediagoblin/plugins/geolocation/templates/mediagoblin/plugins/geolocation/map_js_head.html
create mode 100644 mediagoblin/templates/mediagoblin/utils/templatehooks.html
diff --git a/mediagoblin/plugins/geolocation/__init__.py b/mediagoblin/plugins/geolocation/__init__.py
new file mode 100644
index 00000000..c55e1e6a
--- /dev/null
+++ b/mediagoblin/plugins/geolocation/__init__.py
@@ -0,0 +1,35 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+from mediagoblin.tools import pluginapi
+import os
+
+PLUGIN_DIR = os.path.dirname(__file__)
+
+def setup_plugin():
+ config = pluginapi.get_config('mediagoblin.plugins.geolocation')
+
+ # Register the template path.
+ pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
+
+ pluginapi.register_template_hooks(
+ {"image_sideinfo": "mediagoblin/plugins/geolocation/map.html",
+ "image_extrahead": "mediagoblin/plugins/geolocation/map_js_head.html"})
+
+
+hooks = {
+ 'setup': setup_plugin
+ }
diff --git a/mediagoblin/plugins/geolocation/templates/mediagoblin/plugins/geolocation/map_js_head.html b/mediagoblin/plugins/geolocation/templates/mediagoblin/plugins/geolocation/map_js_head.html
new file mode 100644
index 00000000..aca0f730
--- /dev/null
+++ b/mediagoblin/plugins/geolocation/templates/mediagoblin/plugins/geolocation/map_js_head.html
@@ -0,0 +1,25 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#}
+
+
+
+
+
diff --git a/mediagoblin/templates/mediagoblin/media_displays/image.html b/mediagoblin/templates/mediagoblin/media_displays/image.html
index b03cfc78..f27433bd 100644
--- a/mediagoblin/templates/mediagoblin/media_displays/image.html
+++ b/mediagoblin/templates/mediagoblin/media_displays/image.html
@@ -18,13 +18,19 @@
{% extends 'mediagoblin/user_pages/media.html' %}
-{% from "/mediagoblin/utils/templatehooks.html" import template_hook %}
+{% from "/mediagoblin/utils/templatehooks.html" import template_hook with context %}
{% block mediagoblin_head %}
{{ super() }}
- {% template_hook "image_extrahead" %}
+ {% for template in get_hook_templates("image_extrahead") %}
+ {% include template %}
+ {% endfor %}
+ {# {{ template_hook("image_extrahead") }} #}
{% endblock mediagoblin_head %}
{% block mediagoblin_sidebar %}
- {% template_hook "image_sideinfo" %}
+ {% for template in get_hook_templates("image_sideinfo") %}
+ {% include template %}
+ {% endfor %}
+ {# {{ template_hook("image_sideinfo") }} #}
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
index b18e0828..2e159be4 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media.html
@@ -31,7 +31,7 @@
- {% template_hook "media_extrahead" %}
+ {{ template_hook("media_extrahead") }}
{% endblock mediagoblin_head %}
{% block mediagoblin_content %}
@@ -156,8 +156,6 @@
{% include "mediagoblin/utils/license.html" %}
- {% include "mediagoblin/utils/geolocation_map.html" %}
-
{% include "mediagoblin/utils/exif.html" %}
{% if media.attachment_files|count %}
@@ -199,7 +197,7 @@
{% endif %}
- {% template_hook "media_sideinfo" %}
+ {{ template_hook("media_sideinfo") }}
{% block mediagoblin_sidebar %}
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/utils/templatehooks.html b/mediagoblin/templates/mediagoblin/utils/templatehooks.html
new file mode 100644
index 00000000..615ea635
--- /dev/null
+++ b/mediagoblin/templates/mediagoblin/utils/templatehooks.html
@@ -0,0 +1,22 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#}
+{% macro template_hook(hook_name) %}
+ {% for template in get_hook_templates(hook_name) %}
+ {% include template %}
+ {% endfor %}
+{% endmacro %}
diff --git a/mediagoblin/tools/pluginapi.py b/mediagoblin/tools/pluginapi.py
index 2b8e95f4..99b13ac7 100644
--- a/mediagoblin/tools/pluginapi.py
+++ b/mediagoblin/tools/pluginapi.py
@@ -154,7 +154,10 @@ class PluginManager(object):
else:
# In this case, it's actually a single callable---not a
# list of callables.
- self.hooks.setdefault(hook, []).append(templates)
+ self.template_hooks.setdefault(hook, []).append(templates)
+
+ def get_template_hooks(self, hook_name):
+ return self.template_hooks.get(hook_name, [])
def register_routes(routes):
@@ -235,3 +238,7 @@ def get_config(key):
def register_template_hooks(template_hooks):
PluginManager().register_template_hooks(template_hooks)
+
+
+def get_hook_templates(hook_name):
+ return PluginManager().get_template_hooks(hook_name)
diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py
index 6e01a7dd..c76ce639 100644
--- a/mediagoblin/tools/template.py
+++ b/mediagoblin/tools/template.py
@@ -23,6 +23,7 @@ from mediagoblin import mg_globals
from mediagoblin import messages
from mediagoblin.tools import common
from mediagoblin.tools.translate import get_gettext_translation
+from mediagoblin.tools.pluginapi import get_hook_templates
from mediagoblin.meddleware.csrf import render_csrf_form_token
@@ -64,6 +65,9 @@ def get_jinja_env(template_loader, locale):
template_env.filters['urlencode'] = url_quote_plus
+ # allow for hooking up plugin templates
+ template_env.globals['get_hook_templates'] = get_hook_templates
+
if exists(locale):
SETUP_JINJA_ENVS[locale] = template_env
--
2.25.1