From fffc5dcfe031d30551a91e668b377d443d9267db Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 6 May 2014 12:39:23 -0400 Subject: Created the media metadata editor page --- mediagoblin/edit/forms.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 2c9b5e99..cff3a53f 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -122,3 +122,8 @@ class ChangeEmailForm(wtforms.Form): [wtforms.validators.Required()], description=_( "Enter your password to prove you own this account.")) + +class EditMetaDataForm(wtforms.Form): + media_metadata = wtforms.FieldList( + wtforms.TextField( + _(u'Value'))) -- cgit v1.2.3 From f0cfd3396e2bcfd6a0b3eead1875efd0d29f0ff5 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 6 May 2014 12:54:08 -0400 Subject: Set up the metadata editor forms --- mediagoblin/edit/forms.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index cff3a53f..6cc7a9cb 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -123,7 +123,13 @@ class ChangeEmailForm(wtforms.Form): description=_( "Enter your password to prove you own this account.")) +class MetaDataForm(wtforms.Form): + identifier = wtforms.TextField( + _(u'Id')) + value = wtforms.TextField( + _(u'Value')) + class EditMetaDataForm(wtforms.Form): media_metadata = wtforms.FieldList( - wtforms.TextField( - _(u'Value'))) + wtforms.FormField(MetaDataForm) + ) -- cgit v1.2.3 From e80596c80eb06e6d199795e59dcc37b27d77fe55 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 6 May 2014 17:00:25 -0400 Subject: Created a UI for editting a media's metadata. Had to add a new macro to wtforms.html in the process. --- mediagoblin/edit/forms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 6cc7a9cb..ce66526f 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -124,12 +124,13 @@ class ChangeEmailForm(wtforms.Form): "Enter your password to prove you own this account.")) class MetaDataForm(wtforms.Form): - identifier = wtforms.TextField( - _(u'Id')) - value = wtforms.TextField( - _(u'Value')) + identifier = wtforms.TextField('') + value = wtforms.TextField('') class EditMetaDataForm(wtforms.Form): media_metadata = wtforms.FieldList( - wtforms.FormField(MetaDataForm) + wtforms.FormField(MetaDataForm, label="") + ) + context = wtforms.FieldList( + wtforms.FormField(MetaDataForm, label="") ) -- cgit v1.2.3 From 494bce47f92165f322347003baac22731e0ee7aa Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Mon, 12 May 2014 12:20:03 -0400 Subject: Changed the format of the wtforms table slightly --- mediagoblin/edit/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index ce66526f..7ddf603e 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -124,8 +124,8 @@ class ChangeEmailForm(wtforms.Form): "Enter your password to prove you own this account.")) class MetaDataForm(wtforms.Form): - identifier = wtforms.TextField('') - value = wtforms.TextField('') + identifier = wtforms.TextField(_(u'Identifier')) + value = wtforms.TextField(_(u'Value')) class EditMetaDataForm(wtforms.Form): media_metadata = wtforms.FieldList( -- cgit v1.2.3 From 6b6b1b076bf0f2104dacdfa0f351555bcb6c98d6 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Mon, 12 May 2014 13:07:11 -0400 Subject: Made some changes so that the metadata editing page works well with the updated metadata tools. --- mediagoblin/edit/forms.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 7ddf603e..c2355980 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -131,6 +131,3 @@ class EditMetaDataForm(wtforms.Form): media_metadata = wtforms.FieldList( wtforms.FormField(MetaDataForm, label="") ) - context = wtforms.FieldList( - wtforms.FormField(MetaDataForm, label="") - ) -- cgit v1.2.3 From 0d6550fb05c25e230706c719e3a476d1b1e670b9 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Wed, 14 May 2014 11:51:13 -0400 Subject: Tweaked the metadata edit screen to run jsonschema validators against the data. --- mediagoblin/edit/forms.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'mediagoblin/edit/forms.py') diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index c2355980..7c390a3f 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -15,10 +15,12 @@ # along with this program. If not, see . import wtforms +from jsonschema import Draft4Validator from mediagoblin.tools.text import tag_length_validator from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ from mediagoblin.tools.licenses import licenses_as_choices +from mediagoblin.tools.metadata import DEFAULT_SCHEMA, DEFAULT_CHECKER from mediagoblin.auth.tools import normalize_user_or_email_field @@ -123,11 +125,37 @@ class ChangeEmailForm(wtforms.Form): description=_( "Enter your password to prove you own this account.")) +class MetaDataValidator(object): + """ + Custom validator which runs form data in a MetaDataForm through a jsonschema + validator and passes errors recieved in jsonschema to wtforms. + + :param schema The json schema to validate the data against. By + default this uses the DEFAULT_SCHEMA from + mediagoblin.tools.metadata. + :param format_checker The FormatChecker object that limits which types + jsonschema can recognize. By default this uses + DEFAULT_CHECKER from mediagoblin.tools.metadata. + """ + def __init__(self, schema=DEFAULT_SCHEMA, format_checker=DEFAULT_CHECKER): + self.schema = schema + self.format_checker = format_checker + + def __call__(self, form, field): + metadata_dict = {field.data:form.value.data} + validator = Draft4Validator(self.schema, + format_checker=self.format_checker) + errors = [e.message + for e in validator.iter_errors(metadata_dict)] + if len(errors) >= 1: + raise wtforms.validators.ValidationError( + errors.pop()) + class MetaDataForm(wtforms.Form): - identifier = wtforms.TextField(_(u'Identifier')) + identifier = wtforms.TextField(_(u'Identifier'),[MetaDataValidator()]) value = wtforms.TextField(_(u'Value')) class EditMetaDataForm(wtforms.Form): media_metadata = wtforms.FieldList( - wtforms.FormField(MetaDataForm, label="") + wtforms.FormField(MetaDataForm, ""), ) -- cgit v1.2.3