From 6378d181c620ddf36ebd04e3c24dc1ec80cebf46 Mon Sep 17 00:00:00 2001 From: Klara Peskova Date: Mon, 7 Apr 2014 09:02:27 +0200 Subject: [PATCH] Cardinality of an element can be marked in metadata, fieldsare added dynamically; fixes issue #161. --- .../etc/static/css/simplestore-style.css | 19 +++++++++ simplestore/etc/static/img/minus.png | Bin 0 -> 1235 bytes simplestore/etc/static/img/plus.png | Bin 0 -> 1446 bytes .../templates/simplestore-addmeta-table.html | 36 ++++++++++++++++++ simplestore/lib/simplestore_marc_handler.py | 31 +++++++++------ .../simplestore_model/HTML5ModelConverter.py | 32 +++++++++++++++- simplestore/lib/simplestore_model/model.py | 25 ++++++++---- 7 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 simplestore/etc/static/img/minus.png create mode 100644 simplestore/etc/static/img/plus.png 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 0000000000000000000000000000000000000000..896824ca94048bd602aa0c0d0f2cc047ba488b2d GIT binary patch literal 1235 zcmV;^1T6cBP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf02y>eSaefwW^{L9 za%BKPWN%_+AW3auXJt}lVPtu6$z?nM00cuxL_t(YOT|`QY!p=#{_gzjcDvh>Ee!(yxAptQr2iDpG_4XbpcisVQ-Ca=EtN}EwZa%(%jdQ=CaO^l(It`_B zEsQhgAd*QiT?b^Rh?M;hpwfE}nx1*)#h^fkm-|^h>+IS|ZT_~R1Pa5Jonzk{E@0H{7SN#xPhf!4$Cf`y!! zdjjVUz6T>Q14eyfQ$K^BnuI78z@%sbfx5zRETERCTL%$2K#A1!+(q3Yz~UEQ0jpO* zeEuc)_>cArcCQ)*l?*~nFi*r`OinrYI5Q?u{Qc^FSQC?S&H%%pvZ{?`=(So3F4m0| zhu&Er@5tDiy$0)tF)#^eSxW;diBO9K&AmC3T%hFuHcp=@&!y}IW93C85RuO}{6MO@ z#*G;XvNZnF0_&2zf zGqd>J_dqID-j6iHYbM0e z`5lPt-|Gf8Nmw^F^+S;_EOCfz7OkHRBkronCNFJCs`e*oyE_WA5!nuGuV002ovPDHLkV1m80Jx2fl literal 0 HcmV?d00001 diff --git a/simplestore/etc/static/img/plus.png b/simplestore/etc/static/img/plus.png new file mode 100644 index 0000000000000000000000000000000000000000..267ea64b53ef0df29f9f50cccb5f9ae581fa4a4c GIT binary patch literal 1446 zcmV;X1zGxuP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf02y>eSaefwW^{L9 za%BKPWN%_+AW3auXJt}lVPtu6$z?nM00kCFL_t(YOT|}dXk1kk{^re+$=0mR(#c|J zn$>8!m>NWyRHSK)4@4(pdr~$^Qu0ukun|#)@D=k}5!eeK>c_h9Rp&+M z2qZhsgxcY2xG~WWy`&QW9Uqp26AFC+Fa!ofSw8j|&ODWRIt1I}ZF>iBao4 zY)jgVgz$Butmpfi;Ghz7nYkKv*$JrjyIjcm~8^NaT%x|xlW|&qteRINm`LzZfrV!*>_^z(aW`;;9P$LA_!!$ zIb;{MuHTIB_8b!&30P36yQfESp|?>uIn#Xwt(I;97_JKwWMbghut=5v4Uq||aw}hQ z*&B(RHA8KxJt|<%_GHWVu*wenHqe4``xJ~?Lr@mVo(fjaF?uNqbI|WJehnv8Eo8

$ z!h!5EMO!qOaL%A{v`ZX0okmLnBjYFH%xferY${flo_!s4)Z2I>OQhb2LwV(RtN6tr zkyvf{tGjA&y!jMW!Y=p{9~KSE;UC0y6}j%sPSJlPOgN@6Jaw1U>cM{v%FcJ19)`s> z2{Ro{<_%{bl3Xc~@l;V-Lg&p(46N?DNDAd%ZGu7TPT#75)iFuQ_({qo516XdZ!}cl z{Xf41^mDfhffgiY&Gp#7#YbezPuL`MIAEW4oTL6-hNKXX`_$v6v76jY7IaEiMoDTR z>Yw}AAA~Z@lGFlP;J;;rY4zwF{|lXFb}(mj#w`x3DmzxTOWk#VK_M)xQY0P%m`!%0 zEPc!TK2?t&rTY{@Fcd=xKXU~X9~K0qg;9Wu*FdaMXg9TR-=>n#z{$oK?9VBq=$tCY z|M`K+Y$Dy?LTw9}Dr1iCy~hp{u%g@{Q2BaPnwCz&vgWemvnO7KK|!vd9a-yAadgK) zk}T?@`j+$irp;saNut6+a6Oa5;v@talZwvpuJjU=XKYu!4tXE*bn)crS5P-fH%bH% zX7M0OY(G@+6rRs66*Jh0=4!|yNJXR!>T)1i6N_6F-ylXwJYKofu*X`vr}_x4jI;yM z1TK*yRfD@p;n@h5!Hn07*qoM6N<$f}*pO Ap8x;= literal 0 HcmV?d00001 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)