From: tilly-Q Date: Mon, 12 May 2014 22:07:31 +0000 (-0400) Subject: Made the metadata table functional within the new metadata_display plugin and X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b5dd2459893fd1e7ae1376a7573a36bf15c983f7;p=mediagoblin.git Made the metadata table functional within the new metadata_display plugin and removed all traces of it from core. --- diff --git a/mediagoblin/plugins/metadata_display/__init__.py b/mediagoblin/plugins/metadata_display/__init__.py new file mode 100644 index 00000000..4a4c898f --- /dev/null +++ b/mediagoblin/plugins/metadata_display/__init__.py @@ -0,0 +1,41 @@ +# 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 . +import os +from pkg_resources import resource_filename + +from mediagoblin.plugins.metadata_display.lib import add_rdfa_to_readable_to_media_home +from mediagoblin.tools import pluginapi +from mediagoblin.tools.staticdirect import PluginStatic + +PLUGIN_DIR = os.path.dirname(__file__) + +def setup_plugin(): + # Register the template path. + pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) + + pluginapi.register_template_hooks( + {"media_sideinfo": "mediagoblin/plugins/metadata_display/metadata_table.html", + "head": "mediagoblin/plugins/metadata_display/bits/metadata_extra_head.html"}) + + +hooks = { + 'setup': setup_plugin, + 'static_setup': lambda: PluginStatic( + 'metadata_display', + resource_filename('mediagoblin.plugins.metadata_display', 'static') + ), + 'media_home_context':add_rdfa_to_readable_to_media_home + } diff --git a/mediagoblin/plugins/metadata_display/lib.py b/mediagoblin/plugins/metadata_display/lib.py new file mode 100644 index 00000000..0985208c --- /dev/null +++ b/mediagoblin/plugins/metadata_display/lib.py @@ -0,0 +1,31 @@ +# 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 . + +def rdfa_to_readable(rdfa_predicate): + """ + A simple script to convert rdfa resource descriptors into a form more + accessible for humans. + """ + readable = rdfa_predicate.split(u":")[1].capitalize() + return readable + +def add_rdfa_to_readable_to_media_home(context): + """ + A context hook which adds the 'rdfa_to_readable' filter to + the media home page. + """ + context['rdfa_to_readable'] = rdfa_to_readable + return context diff --git a/mediagoblin/plugins/metadata_display/static/css/metadata_display.css b/mediagoblin/plugins/metadata_display/static/css/metadata_display.css new file mode 100644 index 00000000..e4612b02 --- /dev/null +++ b/mediagoblin/plugins/metadata_display/static/css/metadata_display.css @@ -0,0 +1,14 @@ +table.metadata_info { + font-size:85%; + margin-left:10px; +} + +table.metadata_info th { + font-weight: bold; + border-spacing: 10px; + text-align: left; +} +table.metadata_info td { + padding: 4px 8px; +} + diff --git a/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/bits/metadata_extra_head.html b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/bits/metadata_extra_head.html new file mode 100644 index 00000000..84eedf18 --- /dev/null +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/bits/metadata_extra_head.html @@ -0,0 +1,3 @@ + diff --git a/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html index 73b5ec52..3a9d872c 100644 --- a/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html @@ -15,17 +15,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . #} - +{% block metadata_information_table %} {%- set metadata=media.media_metadata %} {%- set metadata_context=metadata['@context'] %} {%- if metadata %} +

{% trans %}Metadata{% endtrans %}

{#- NOTE: In some smart future where the context is more extensible, we will need to add to the prefix here-#} - +
{%- for key, value in metadata.iteritems() if not key=='@context' %} {% if value -%} - + {%- endif -%} @@ -34,7 +35,8 @@ {% endif %} {% if request.user and request.user.has_privilege('admin') %} + user=media.get_uploader.username, + media_id=media.id) }}"> {% trans %}Edit Metadata{% endtrans %} {% endif %} +{% endblock %} diff --git a/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html.orig b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html.orig new file mode 100644 index 00000000..2bd1a14c --- /dev/null +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html.orig @@ -0,0 +1,60 @@ +{# +# 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 . +#} + +<<<<<<< HEAD:mediagoblin/templates/mediagoblin/utils/metadata_table.html +{%- macro render_table(request, media_entry, format_predicate) %} + {%- set metadata=media_entry.media_metadata %} + {%- set metadata_context=metadata['@context'] %} + {%- if metadata %} +

{% trans %}Metadata Information{% endtrans %}

+
+ {%- for key, value in metadata.iteritems() if ( + not key=='@context' and value) %} + + + + + {%- endfor %} + + {% endif %} + {% if request.user and request.user.has_privilege('admin') %} + + {% trans %}Edit Metadata{% endtrans %} + {% endif %} +{%- endmacro %} +======= +{%- set metadata=media.media_metadata %} +{%- set metadata_context=metadata['@context'] %} +{%- if metadata %} + {#- NOTE: In some smart future where the context is more extensible, + we will need to add to the prefix here-#} + + {%- for key, value in metadata.iteritems() if not key=='@context' %} + {% if value -%} + + + + + {%- endif -%} + {%- endfor %} +
{{ rdfa_to_readable(key) }}{{ value }}
+{% endif %} +>>>>>>> acfcaf6366bd4695c1c37c7aa8ff5a176b412e2a:mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css index df0e850b..a3b564ea 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -609,25 +609,6 @@ a img.media_image { cursor: -moz-zoom-in; cursor: zoom-in; } - -table.metadata_info { - font-size:85%; - margin-left:10px; -} - -table.metadata_info tr.highlight { - color:#f7f7f7; -} - -table.metadata_info th { - font-weight: bold; - border-spacing: 10px; - text-align: left; -} -table.metadata_info td { - padding: 4px 8px; -} - /* icons */ img.media_icon {