from datetime import datetime
from itsdangerous import BadSignature
+from pyld import jsonld
from werkzeug.exceptions import Forbidden
from werkzeug.utils import secure_filename
@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
$('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 %}