From: tilly-Q Date: Tue, 6 May 2014 21:19:30 +0000 (-0400) Subject: Made it so the metadata editting page is only one step away from functioning X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9919fb08a4d56f5976a6fef0fc70b2ee6c751759;p=mediagoblin.git Made it so the metadata editting page is only one step away from functioning correctly. --- diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index e3dd82ab..496df6b9 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -17,6 +17,7 @@ from datetime import datetime from itsdangerous import BadSignature +from pyld import jsonld from werkzeug.exceptions import Forbidden from werkzeug.utils import secure_filename @@ -438,7 +439,20 @@ def change_email(request): @require_active_login @get_media_entry_by_id def edit_metadata(request, media): - form = forms.EditMetaDataForm() + 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() + return redirect_obj(request, media) + if media.media_metadata: for row in media.media_metadata.iteritems(): if row[0] == "@context": continue diff --git a/mediagoblin/templates/mediagoblin/edit/metadata.html b/mediagoblin/templates/mediagoblin/edit/metadata.html index cbf74106..364cad0d 100644 --- a/mediagoblin/templates/mediagoblin/edit/metadata.html +++ b/mediagoblin/templates/mediagoblin/edit/metadata.html @@ -41,7 +41,7 @@ $('table'+list_id+' tr').each(function(row){ id_input = $(this).find('td').find('input'); value_input = $(this).find('td').next().find('input'); - if ((value_input.attr('value') == "") && + if ((value_input.attr('value') == "") && (id_input.attr('value') == "")) { $(this).remove(); } @@ -52,13 +52,13 @@ var context_lines = {{ form.context | length }}; var metadata_lines = {{ form.media_metadata | length }}; $("#add_new_metadata_row").click(function(){ - add_new_row("#metadata_list", + add_new_row("#metadata_list", metadata_lines, 'media_metadata-'); metadata_lines += 1; }) $("#add_new_context_row").click(function(){ - add_new_row("#context_list", + add_new_row("#context_list", context_lines, 'context-'); context_lines += 1; @@ -115,7 +115,7 @@ - @@ -125,5 +125,5 @@ {{ csrf_token }} - + {% endblock mediagoblin_content %}