diff options
Diffstat (limited to 'mediagoblin/plugins/metadata_display')
6 files changed, 191 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. +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 <http://www.gnu.org/licenses/>. + +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..4a380299 --- /dev/null +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/bits/metadata_extra_head.html @@ -0,0 +1,3 @@ + <link rel="stylesheet" type="text/css" + href="{{ request.staticdirect('css/metadata_display.css', + 'metadata_display') }}"/> 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 new file mode 100644 index 00000000..3a9d872c --- /dev/null +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html @@ -0,0 +1,42 @@ +{# +# 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 <http://www.gnu.org/licenses/>. +#} +{% block metadata_information_table %} +{%- set metadata=media.media_metadata %} +{%- set metadata_context=metadata['@context'] %} +{%- if metadata %} + <h3>{% trans %}Metadata{% endtrans %}</h3> + {#- NOTE: In some smart future where the context is more extensible, + we will need to add to the prefix here-#} + <table class="metadata_info"> + {%- for key, value in metadata.iteritems() if not key=='@context' %} + {% if value -%} + <tr> + <th>{{ rdfa_to_readable(key) }}</th> + <td property="{{ key }}">{{ value }}</td> + </tr> + {%- endif -%} + {%- endfor %} + </table> +{% endif %} +{% if request.user and request.user.has_privilege('admin') %} + <a href="{{ request.urlgen('mediagoblin.edit.metadata', + user=media.get_uploader.username, + media_id=media.id) }}"> + {% trans %}Edit Metadata{% endtrans %}</a> +{% 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 <http://www.gnu.org/licenses/>. +#} + +<<<<<<< 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 %} + <h3>{% trans %}Metadata Information{% endtrans %}</h3> + <table class="metadata_info"> + {%- for key, value in metadata.iteritems() if ( + not key=='@context' and value) %} + <tr {% if loop.index%2 == 1 %}class="highlight"{% endif %}> + <th>{{ format_predicate(key) }}</th> + <td property="{{ key }}"> + {{ value }}</td> + </tr> + {%- endfor %} + </table> + {% endif %} + {% if request.user and request.user.has_privilege('admin') %} + <a href="{{ request.urlgen('mediagoblin.edit.metadata', + user=media_entry.get_uploader.username, + media_id=media_entry.id) }}"> + {% trans %}Edit Metadata{% endtrans %}</a> + {% 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-#} + <table> + {%- for key, value in metadata.iteritems() if not key=='@context' %} + {% if value -%} + <tr> + <td>{{ rdfa_to_readable(key) }}</td> + <td property="{{ key }}">{{ value }}</td> + </tr> + {%- endif -%} + {%- endfor %} + </table> +{% endif %} +>>>>>>> acfcaf6366bd4695c1c37c7aa8ff5a176b412e2a:mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html |