From acfcaf6366bd4695c1c37c7aa8ff5a176b412e2a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 12 May 2014 14:50:58 -0500 Subject: Move the metadata display table over to being contained in a plugin --- .../plugins/metadata_display/metadata_table.html | 34 ++++++++++++++++++++ .../templates/mediagoblin/user_pages/media.html | 5 --- .../mediagoblin/utils/metadata_table.html | 37 ---------------------- mediagoblin/tools/metadata.py | 5 +++ mediagoblin/user_pages/lib.py | 3 -- mediagoblin/user_pages/views.py | 5 ++- 6 files changed, 41 insertions(+), 48 deletions(-) create mode 100644 mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html delete mode 100644 mediagoblin/templates/mediagoblin/utils/metadata_table.html 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..db12f149 --- /dev/null +++ b/mediagoblin/plugins/metadata_display/templates/mediagoblin/plugins/metadata_display/metadata_table.html @@ -0,0 +1,34 @@ +{# +# 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 . +#} + +{%- 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 %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 22971fec..949cbcde 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -18,7 +18,6 @@ {%- extends "mediagoblin/base.html" %} {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} -{% import "/mediagoblin/utils/metadata_table.html" as metadata_util %} {% from "mediagoblin/utils/pagination.html" import render_pagination %} {% block title %}{{ media.title }} — {{ super() }}{% endblock %} @@ -231,10 +230,6 @@ {% template_hook("media_sideinfo") %} - {% block mediagoblin_sidebar %} - {{ metadata_util.render_table(request, media, rdfa_to_readable) }} - {% endblock %} -
diff --git a/mediagoblin/templates/mediagoblin/utils/metadata_table.html b/mediagoblin/templates/mediagoblin/utils/metadata_table.html deleted file mode 100644 index 3281c81c..00000000 --- a/mediagoblin/templates/mediagoblin/utils/metadata_table.html +++ /dev/null @@ -1,37 +0,0 @@ -{# -# 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 render_table(request, media_entry, format_predicate) %} - {%- set metadata=media_entry.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_dict in metadata.iteritems() if not key=='@context' %} - {% if value_dict['@value'] -%} - - - - - {%- endif -%} - {%- endfor %} -
{{ format_predicate(key) }} - {{ value_dict['@value'] }}
- {% endif %} -{%- endmacro %} diff --git a/mediagoblin/tools/metadata.py b/mediagoblin/tools/metadata.py index 7de5a514..3f10e9d1 100644 --- a/mediagoblin/tools/metadata.py +++ b/mediagoblin/tools/metadata.py @@ -211,3 +211,8 @@ def expand_json(metadata, context=DEFAULT_CONTEXT): if context is not None: options["expandContext"] = context return jsonld.expand(metadata, options=options) + + +def rdfa_to_readable(rdfa_predicate): + readable = rdfa_predicate.split(u":")[1].capitalize() + return readable diff --git a/mediagoblin/user_pages/lib.py b/mediagoblin/user_pages/lib.py index 83a99cee..e5c8defc 100644 --- a/mediagoblin/user_pages/lib.py +++ b/mediagoblin/user_pages/lib.py @@ -116,6 +116,3 @@ def build_report_object(report_form, media_entry=None, comment=None): report_object.reporter_id = report_form.reporter_id.data return report_object -def rdfa_to_readable(rdfa_predicate): - readable = rdfa_predicate.split(u":")[1].capitalize() - return readable diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index f42eae1f..78751a28 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -28,7 +28,7 @@ from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.pagination import Pagination from mediagoblin.user_pages import forms as user_forms from mediagoblin.user_pages.lib import (send_comment_email, - add_media_to_collection, build_report_object, rdfa_to_readable) + add_media_to_collection, build_report_object) from mediagoblin.notifications import trigger_notification, \ add_comment_subscription, mark_comment_notification_seen from mediagoblin.tools.pluginapi import hook_transform @@ -152,8 +152,7 @@ def media_home(request, media, page, **kwargs): 'comments': comments, 'pagination': pagination, 'comment_form': comment_form, - 'app_config': mg_globals.app_config, - 'rdfa_to_readable':rdfa_to_readable} + 'app_config': mg_globals.app_config} # Since the media template name gets swapped out for each media # type, normal context hooks don't work if you want to affect all -- cgit v1.2.3