Move the metadata display table over to being contained in a plugin

This commit is contained in:
Christopher Allan Webber 2014-05-12 14:50:58 -05:00
parent fbea284aeb
commit acfcaf6366
5 changed files with 23 additions and 30 deletions

View File

@ -16,22 +16,19 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#} #}
{%- macro render_table(request, media_entry, format_predicate) %} {%- set metadata=media.media_metadata %}
{%- set metadata=media_entry.media_metadata %} {%- set metadata_context=metadata['@context'] %}
{%- set metadata_context=metadata['@context'] %} {%- if metadata %}
{%- if metadata %} {#- NOTE: In some smart future where the context is more extensible,
{#- NOTE: In some smart future where the context is more extensible, we will need to add to the prefix here-#}
we will need to add to the prefix here-#} <table>
<table> {%- for key, value in metadata.iteritems() if not key=='@context' %}
{%- for key, value_dict in metadata.iteritems() if not key=='@context' %} {% if value -%}
{% if value_dict['@value'] -%} <tr>
<tr> <td>{{ rdfa_to_readable(key) }}</td>
<td>{{ format_predicate(key) }}</td> <td property="{{ key }}">{{ value }}</td>
<td property="{{ key }}" typeof="{{ value_dict['@type'] }}"> </tr>
{{ value_dict['@value'] }}</td> {%- endif -%}
</tr> {%- endfor %}
{%- endif -%} </table>
{%- endfor %} {% endif %}
</table>
{% endif %}
{%- endmacro %}

View File

@ -18,7 +18,6 @@
{%- extends "mediagoblin/base.html" %} {%- extends "mediagoblin/base.html" %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% 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 %} {% from "mediagoblin/utils/pagination.html" import render_pagination %}
{% block title %}{{ media.title }} &mdash; {{ super() }}{% endblock %} {% block title %}{{ media.title }} &mdash; {{ super() }}{% endblock %}
@ -231,10 +230,6 @@
{% template_hook("media_sideinfo") %} {% template_hook("media_sideinfo") %}
{% block mediagoblin_sidebar %}
{{ metadata_util.render_table(request, media, rdfa_to_readable) }}
{% endblock %}
</div><!--end media_sidebar--> </div><!--end media_sidebar-->
<div class="clear"></div> <div class="clear"></div>

View File

@ -211,3 +211,8 @@ def expand_json(metadata, context=DEFAULT_CONTEXT):
if context is not None: if context is not None:
options["expandContext"] = context options["expandContext"] = context
return jsonld.expand(metadata, options=options) return jsonld.expand(metadata, options=options)
def rdfa_to_readable(rdfa_predicate):
readable = rdfa_predicate.split(u":")[1].capitalize()
return readable

View File

@ -116,6 +116,3 @@ def build_report_object(report_form, media_entry=None, comment=None):
report_object.reporter_id = report_form.reporter_id.data report_object.reporter_id = report_form.reporter_id.data
return report_object return report_object
def rdfa_to_readable(rdfa_predicate):
readable = rdfa_predicate.split(u":")[1].capitalize()
return readable

View File

@ -28,7 +28,7 @@ from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.pagination import Pagination
from mediagoblin.user_pages import forms as user_forms from mediagoblin.user_pages import forms as user_forms
from mediagoblin.user_pages.lib import (send_comment_email, 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, \ from mediagoblin.notifications import trigger_notification, \
add_comment_subscription, mark_comment_notification_seen add_comment_subscription, mark_comment_notification_seen
from mediagoblin.tools.pluginapi import hook_transform from mediagoblin.tools.pluginapi import hook_transform
@ -152,8 +152,7 @@ def media_home(request, media, page, **kwargs):
'comments': comments, 'comments': comments,
'pagination': pagination, 'pagination': pagination,
'comment_form': comment_form, 'comment_form': comment_form,
'app_config': mg_globals.app_config, 'app_config': mg_globals.app_config}
'rdfa_to_readable':rdfa_to_readable}
# Since the media template name gets swapped out for each media # Since the media template name gets swapped out for each media
# type, normal context hooks don't work if you want to affect all # type, normal context hooks don't work if you want to affect all