Made some changes so that the metadata editing page works well with the updated
metadata tools.
This commit is contained in:
parent
7bcb3e100c
commit
6b6b1b076b
@ -131,6 +131,3 @@ class EditMetaDataForm(wtforms.Form):
|
||||
media_metadata = wtforms.FieldList(
|
||||
wtforms.FormField(MetaDataForm, label="")
|
||||
)
|
||||
context = wtforms.FieldList(
|
||||
wtforms.FormField(MetaDataForm, label="")
|
||||
)
|
||||
|
@ -33,6 +33,7 @@ from mediagoblin.decorators import (require_active_login, active_user_from_url,
|
||||
get_user_collection, user_has_privilege,
|
||||
user_not_banned)
|
||||
from mediagoblin.tools.crypto import get_timed_signer_url
|
||||
from mediagoblin.tools.metadata import compact_and_validate
|
||||
from mediagoblin.tools.mail import email_debug_message
|
||||
from mediagoblin.tools.response import (render_to_response,
|
||||
redirect, redirect_obj, render_404)
|
||||
@ -441,32 +442,19 @@ def change_email(request):
|
||||
def edit_metadata(request, media):
|
||||
form = forms.EditMetaDataForm(request.form)
|
||||
if request.method == "POST" and form.validate():
|
||||
context = dict([(row['identifier'],row['value'])
|
||||
for row in form.context.data])
|
||||
metadata_dict = dict([(row['identifier'],row['value'])
|
||||
for row in form.media_metadata.data])
|
||||
# TODO VALIDATE THIS BEFORE WE ENTER IT
|
||||
# validate(metadata_dict)
|
||||
# validate(context)
|
||||
json_ld_metadata = jsonld.compact(metadata_dict, context)
|
||||
# media.media_metadata = json_ld_metadata
|
||||
# media.save()
|
||||
json_ld_metadata = compact_and_validate(metadata_dict)
|
||||
media.media_metadata = json_ld_metadata
|
||||
media.save()
|
||||
return redirect_obj(request, media)
|
||||
|
||||
if media.media_metadata:
|
||||
for row in media.media_metadata.iteritems():
|
||||
if row[0] == "@context": continue
|
||||
identifier = row[0]
|
||||
# TODO Will change when we revert the metadata branch
|
||||
value = row[1]['@value']
|
||||
for identifier, value in media.media_metadata.iteritems():
|
||||
if identifier == "@context": continue
|
||||
form.media_metadata.append_entry({
|
||||
'identifier':identifier,
|
||||
'value':value})
|
||||
for row in media.media_metadata['@context'].iteritems():
|
||||
identifier, value = row[0:2]
|
||||
form.context.append_entry({
|
||||
'identifier':identifier,
|
||||
'value':value})
|
||||
else:
|
||||
form.media_metadata.append_entry({
|
||||
'identifier':"",
|
||||
@ -474,9 +462,6 @@ def edit_metadata(request, media):
|
||||
form.media_metadata.append_entry({
|
||||
'identifier':"",
|
||||
'value':""})
|
||||
form.context.append_entry({
|
||||
'identifier':"",
|
||||
'value':""})
|
||||
return render_to_response(
|
||||
request,
|
||||
'mediagoblin/edit/metadata.html',
|
||||
|
@ -49,7 +49,6 @@
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
var context_lines = {{ form.context | length }};
|
||||
var metadata_lines = {{ form.media_metadata | length }};
|
||||
$("#add_new_metadata_row").click(function(){
|
||||
add_new_row("#metadata_list",
|
||||
@ -57,14 +56,8 @@
|
||||
'media_metadata-');
|
||||
metadata_lines += 1;
|
||||
})
|
||||
$("#add_new_context_row").click(function(){
|
||||
add_new_row("#context_list",
|
||||
context_lines,
|
||||
'context-');
|
||||
context_lines += 1;
|
||||
})
|
||||
$("#clear_empty_rows").click(function(){
|
||||
clear_empty_rows("#context_list");
|
||||
clear_empty_rows("#metadata_list");
|
||||
})
|
||||
})
|
||||
@ -74,22 +67,6 @@
|
||||
<h2>{% trans media_name=media.title -%}
|
||||
Metadata for "{{ media_name }}"{% endtrans %}</h2>
|
||||
<form action="" method="POST" id="metadata_form">
|
||||
<!-- This table holds all the information about the metadata's context.
|
||||
visit http:/wwww.json-ld.org for more information. -->
|
||||
<h3>{% trans %}Context{% endtrans %}</h3>
|
||||
<table class="metadata_editor" id="context_list">
|
||||
{{ wtforms_util.render_fieldlist_as_table_rows(form.context) }}
|
||||
</table>
|
||||
|
||||
<table class="metadata_editor" id="buttons_top">
|
||||
<tr>
|
||||
<th></th>
|
||||
<td><input type=button value="{% trans %}Add new Row{% endtrans %}"
|
||||
class="button_action" id="add_new_context_row" /></td>
|
||||
<th></th>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- This table holds all the information about the media entry's metadata -->
|
||||
<h3>{% trans %}Data{% endtrans %}</h3>
|
||||
|
@ -20,16 +20,13 @@
|
||||
{%- set metadata=media_entry.media_metadata %}
|
||||
{%- set metadata_context=metadata['@context'] %}
|
||||
{%- if metadata %}
|
||||
<table prefix="{% for p in metadata_context %}{% if not loop.first %}
|
||||
{% endif %}{{ p }} {{ metadata_context[p] }}{% endfor -%}">
|
||||
{%- for key, value_dict in metadata.iteritems() if not key=='@context' %}
|
||||
{% if value_dict['@value'] -%}
|
||||
<table context="{{ metadata_context }}">
|
||||
{%- for key, value in metadata.iteritems() if not key=='@context' %}
|
||||
<tr>
|
||||
<td>{{ format_predicate(key) }}</td>
|
||||
<td property="{{ key }}" typeof="{{ value_dict['@type'] }}">
|
||||
{{ value_dict['@value'] }}</td>
|
||||
<td property="{{ key }}" typeof="{{ value }}">
|
||||
{{ value }}</td>
|
||||
</tr>
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user