diff --git a/simplestore/etc/static/css/simplestore-style.css b/simplestore/etc/static/css/simplestore-style.css index 6568dc6208..2caa65df5e 100755 --- a/simplestore/etc/static/css/simplestore-style.css +++ b/simplestore/etc/static/css/simplestore-style.css @@ -298,3 +298,22 @@ a.description:hover span { border:10px solid #666; background-color:#666; color:#fff } + +.plus, .minus { + width:30px; + height:30px; + overflow:hidden; +} + +.plus { + background: url(/img/plus.png); +} + +.minus { + background: url(/img/minus.png); +} + +.add_field { + float:left; + width:240px; +} diff --git a/simplestore/etc/static/img/minus.png b/simplestore/etc/static/img/minus.png new file mode 100644 index 0000000000..896824ca94 Binary files /dev/null and b/simplestore/etc/static/img/minus.png differ diff --git a/simplestore/etc/static/img/plus.png b/simplestore/etc/static/img/plus.png new file mode 100644 index 0000000000..267ea64b53 Binary files /dev/null and b/simplestore/etc/static/img/plus.png differ diff --git a/simplestore/etc/templates/simplestore-addmeta-table.html b/simplestore/etc/templates/simplestore-addmeta-table.html index d2753e7a43..53de3a18a0 100755 --- a/simplestore/etc/templates/simplestore-addmeta-table.html +++ b/simplestore/etc/templates/simplestore-addmeta-table.html @@ -104,3 +104,39 @@ }); }); + + diff --git a/simplestore/lib/simplestore_marc_handler.py b/simplestore/lib/simplestore_marc_handler.py index a8e56337f6..636169adc9 100644 --- a/simplestore/lib/simplestore_marc_handler.py +++ b/simplestore/lib/simplestore_marc_handler.py @@ -42,10 +42,12 @@ def add_basic_fields(rec, form, email): if form['title']: record_add_field(rec, '245', subfields=[('a', remove_html_markup(form['title']))]) - if form['creator']: - for kw in form['creator'].split(';'): - if kw and not kw.isspace(): - record_add_field(rec, '100', subfields=[('a', remove_html_markup(kw.strip()))]) + if form['creator']: + fields = form.getlist('creator') + for f in fields: + if f and not f.isspace(): + record_add_field(rec, '100', subfields=[('a', remove_html_markup(f.strip()))]) + if form['domain']: record_add_field(rec, '980', subfields=[('a', remove_html_markup(form['domain']))]) @@ -67,16 +69,18 @@ def add_basic_fields(rec, form, email): record_add_field(rec, '540', subfields=[('a', remove_html_markup(form['licence']))]) record_add_field(rec, '520', subfields=[('a', remove_html_markup(form['description']))]) - if form['keywords']: - for kw in form['keywords'].split(','): + if form['tags']: + for kw in form['tags'].split(','): if kw and not kw.isspace(): record_add_field(rec, '653', ind1='1', subfields=[('a', remove_html_markup(kw.strip()))]) if form['contributors']: - for kw in form['contributors'].split(';'): - record_add_field(rec, '700', subfields=[('a', remove_html_markup(kw.strip()))]) + fields = form.getlist('contributors') + for f in fields: + if f and not f.isspace(): + record_add_field(rec, '700', subfields=[('a', remove_html_markup(f.strip()))]) record_add_field(rec, '546', subfields=[('a', remove_html_markup(form['language']))]) @@ -164,11 +168,14 @@ def add_domain_fields(rec, form): for fs in meta.fieldsets: if fs.name != 'Generic': # TODO: this is brittle; get from somewhere - for k in (fs.optional_fields + fs.basic_fields): + for k in (fs.optional_fields + fs.basic_fields): if form[k]: - record_add_field(rec, '690', - subfields=[('a', k), ('b', form[k])]) - + fields = form.getlist(k) + for f in fields: + if f and not f.isspace(): + record_add_field(rec, '690', + subfields=[('a', k), ('b', f)]) + def add_epic_pid(rec, recid, checksum): """ Adds EPIC PID to the record. If registration fails, can diff --git a/simplestore/lib/simplestore_model/HTML5ModelConverter.py b/simplestore/lib/simplestore_model/HTML5ModelConverter.py index e7e2687f00..9355d12a70 100644 --- a/simplestore/lib/simplestore_model/HTML5ModelConverter.py +++ b/simplestore/lib/simplestore_model/HTML5ModelConverter.py @@ -186,7 +186,7 @@ def __call__(self, field, **kwargs): html.append('') html.append('' .format(html_params(name=field.name+"_input"), - html_params(id=field.name+"_input"))) + html_params(id=field.name+"_input"))) return HTMLString(''.join(html)) @@ -202,6 +202,33 @@ def __init__(self, other="", **field_args): super(SelectFieldWithInput, self).__init__(**field_args) +class AddFieldInput(Input): + input_type = "text" + + def __call__(self, field, **kwargs): + kwargs.setdefault('id', field.id) + html = ['
'] + html.append('
') + html.append('' + .format(field.placeholder, self.html_params(name=field.name, **kwargs))) + html.append('
' + .format(field.placeholder, field.cardinality, field.name)) + html.append('
') + html.append('
') + return HTMLString(''.join(html)) + +class AddField(StringField): + widget = AddFieldInput() + placeholder = "" + cardinality = "n" + + def __init__(self, cardinality="n", placeholder="", **field_args): + self.field_args = field_args + self.placeholder = placeholder + self.cardinality = cardinality + super(AddField, self).__init__(**field_args) + + class HiddenInput(Input): input_type = "hidden" @@ -269,6 +296,9 @@ def conv_String(self, field_args, **extra): if hidden: return hidden + if 'cardinality' in field_args: + return AddField(**field_args) + if 'placeholder' in field_args: return PlaceholderStringField(**field_args) diff --git a/simplestore/lib/simplestore_model/model.py b/simplestore/lib/simplestore_model/model.py index 82d19823f9..e9f909d68a 100644 --- a/simplestore/lib/simplestore_model/model.py +++ b/simplestore/lib/simplestore_model/model.py @@ -44,7 +44,7 @@ class SubmissionMetadata(db.Model): id = db.Column(db.Integer, primary_key=True) description = db.Column(db.Text(), nullable=False) - creator = db.Column(db.String(256)) # split on ; + creator = db.Column(db.String(256)) title = db.Column(db.String(256), nullable=False) open_access = db.Column(db.Boolean(), default=True) @@ -52,10 +52,10 @@ class SubmissionMetadata(db.Model): publisher = db.Column(db.String(128), default=publisher_default) publication_date = db.Column('publication_year', db.Date(), default=publication_date_now) - keywords = db.Column(db.String(256)) # split on , + tags = db.Column(db.String(256)) # split on , # optional - contributors = db.Column(db.String(256)) # split on ; + contributors = db.Column(db.String(256)) #language = db.Column(db.Enum(*babel.core.LOCALE_ALIASES.keys())) language = db.Column(db.String(128), default=language_default) resource_type = db.Column(db.String(256)) # XXX should be extracted to a separate class @@ -63,7 +63,7 @@ class SubmissionMetadata(db.Model): version = db.Column(db.String(128)) basic_fields = ['title', 'description', 'creator', 'open_access', - 'licence', 'publisher', 'publication_date','language', 'keywords'] + 'licence', 'publisher', 'publication_date','language', 'tags'] optional_fields = ['contributors', 'resource_type', 'alternate_identifier', 'version'] @@ -124,10 +124,10 @@ def __init__(self): 'Apache v2 or Commercial); if no licence applies ' +\ 'leave this field blank.' } - self.field_args['keywords'] = { + self.field_args['tags'] = { 'placeholder': "keyword1, keyword2, ...", 'description': - 'A comma separated list of keywords that ' +\ + 'A comma separated list of tags (keywords) that ' +\ 'characterize the content.' } self.field_args['open_access'] = { @@ -137,7 +137,8 @@ def __init__(self): 'will not be public, however the metadata will be.' } self.field_args['contributors'] = { - 'placeholder': 'contributor 1; contributor 2; ...', + 'placeholder': 'contributor', + 'cardinality': 'n', 'description': 'A semicolon separated list of all other ' +\ 'contributors. Mention all ' +\ @@ -161,7 +162,8 @@ def __init__(self): 'Any kind of other reference such as a URN, URI or an ISBN number.' } self.field_args['creator'] = { - 'placeholder': 'author 1; author 2; ... ', + 'placeholder': 'author', + 'cardinality': 'n', 'description': 'A semicolon separated list of authors of the resource.' } @@ -244,4 +246,11 @@ def is_external_attr(n): args['field_args'][f['name']]['placeholder'] = f.get('placeholder') if 'value' in f: args['field_args'][f['name']]['value'] = f.get('value') + if 'choices' in f: + args['field_args'][f['name']]['choices'] = f.get('choices') + if 'other' in f: + args['field_args'][f['name']]['other'] = f.get('other') + if 'cardinality' in f: + args['field_args'][f['name']]['cardinality'] = f.get('cardinality') + return type(clsname, (SubmissionMetadata,), args)