Made it so the metadata editting page is only one step away from functioning
authortilly-Q <nattilypigeonfowl@gmail.com>
Tue, 6 May 2014 21:19:30 +0000 (17:19 -0400)
committertilly-Q <nattilypigeonfowl@gmail.com>
Tue, 6 May 2014 21:19:30 +0000 (17:19 -0400)
correctly.

mediagoblin/edit/views.py
mediagoblin/templates/mediagoblin/edit/metadata.html

index e3dd82abb5316c6565c2e9a40051b880a314a5df..496df6b97267ea9233baa774dccd91811ea2c223 100644 (file)
@@ -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
index cbf74106af399e3ac7c7a363999f2430ff9162ed..364cad0de94a74f95e2fc9af9fb252d7412b9c92 100644 (file)
@@ -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();
             }
         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;
       <td><input type=button value="{% trans %}Add new Row{% endtrans %}"
         class="button_action" id="add_new_metadata_row" />
       </td>
-      <td><input type=submit value="{% trans %}Update Metadata{% endtrans %}" 
+      <td><input type=submit value="{% trans %}Update Metadata{% endtrans %}"
         class="button_action_highlight" /></td>
     </tr>
     <tr>
   </table>
   {{ csrf_token }}
   </form>
-  
+
 {% endblock mediagoblin_content %}