Skip to content

Commit

Permalink
Cardinality of an element can be marked in metadata, fieldsare added …
Browse files Browse the repository at this point in the history
…dynamically; fixes issue EUDAT-B2SHARE#161.
  • Loading branch information
peskk3am committed Apr 7, 2014
1 parent eaa0887 commit c2767f7
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 53 deletions.
19 changes: 19 additions & 0 deletions simplestore/etc/static/css/simplestore-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Binary file added simplestore/etc/static/img/minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simplestore/etc/static/img/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions simplestore/etc/templates/simplestore-addmeta-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,39 @@
});
});
</script>

<script type="text/javascript">
var rowNum = 0;

$('form .plus').click(function(){
rowNum ++;
var name = $(this).attr('name');
var placeholder = $(this).attr('data-placeholder');
var cardinality = $(this).attr('data-cardinality');

var row = '<div id="rowNum'+rowNum+'">'
row += '<input class="add_field" id="inputRowNum'+rowNum+'" type="text" name="'+name+'" placeholder="'+placeholder+'">';
row += '<div class="minus" data-name="'+name+'" data-cardinality="'+cardinality+'" data-row="'+rowNum+'"></div>';
row += '</div>';
$('#'+name+"_div").append(row);

var rowCount = $('#'+name+"_div > div").length;
if (cardinality <= rowCount){
$("#"+name+"_add").css("visibility", "hidden");
}
});

$('form').on('click', '.minus', function() {
var row = $(this).attr('data-row');
var name = $(this).attr('data-name');
var cardinality = $(this).attr('data-cardinality');

$('#rowNum'+row).remove();

var rowCount = $('#'+name+"_div > div").length;
if (cardinality > rowCount){
$("#"+name+"_add").css("visibility", "visible");
}
});

</script>
2 changes: 1 addition & 1 deletion simplestore/etc/templates/simplestore-deposit.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ <h2 style="margin-top:30px">
// replace select value with text field value
otherOption.val($("#"+select_list[i]+"_input").val());
}
}
}
});
</script>

Expand Down
29 changes: 0 additions & 29 deletions simplestore/lib/b2share_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

"""Utility functions for b2share"""
from invenio.search_engine import perform_request_search
from invenio.search_engine_utils import get_fieldvalues
from invenio.bibformat_engine import BibFormatObject
from invenio.bibformat_elements import bfe_authors, bfe_title, bfe_abstract, bfe_creation_date

Expand Down Expand Up @@ -54,31 +53,3 @@ def get_latest_deposits():
"category": bfo.field("980__a"),
} for bfo in bfo_list]
return recs


def check_fresh_record(user_info, recid):
"""
Check if the record is just submitted (has a record id) but not yet fully in the database.
The check_user_can_view_record function is doing the same thing, but returns the
same error code for both cases where the user doesn't have the right to view
the record and the case when the record is not yet fully submitted.
@param user_info: the user_info dictionary that describe the user.
@type user_info: user_info dictionary
@param recid: the record identifier.
@type recid: positive integer
@return: True if the record is fresh, False otherwise
@rtype: bool
"""

if isinstance(recid, str):
recid = int(recid)

if get_fieldvalues(recid, '8560_f'):
# The email field is set
return False
if get_fieldvalues(recid, '245__a'):
# It has a title
return False

return True
3 changes: 1 addition & 2 deletions simplestore/lib/simplestore_deposit_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def addmeta(request, sub_id):
recid, marc = mh.create_marc(
request.form, sub_id, current_user['email'])
tmp_file = write_marc_to_temp_file(marc)
# all usual tasks have priority 0; we want the bibuploads to run first
task_low_level_submission('bibupload', 'webdeposit', '--priority', '1', '-r', tmp_file)
task_low_level_submission('bibupload', 'webdeposit', '-r', tmp_file)
return jsonify(valid=True,
html=render_template('simplestore-finalize.html',
recid=recid, marc=marc))
Expand Down
31 changes: 19 additions & 12 deletions simplestore/lib/simplestore_marc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))])
Expand All @@ -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']))])

Expand Down Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion simplestore/lib/simplestore_model/HTML5ModelConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __call__(self, field, **kwargs):
html.append('</select>')
html.append('<input type=text style="display: none" {0} {1} >'
.format(html_params(name=field.name+"_input"),
html_params(id=field.name+"_input")))
html_params(id=field.name+"_input")))
return HTMLString(''.join(html))


Expand All @@ -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 = ['<div id="'+field.name+'_div">']
html.append('<div id="rowNum0">')
html.append('<input class="add_field" type="text" id="inputRowNum0" placeholder="{0}" {1}>'
.format(field.placeholder, self.html_params(name=field.name, **kwargs)))
html.append('<div class="plus" id="{2}_add" data-placeholder="{0}" data-cardinality="{1}" name="{2}"></div>'
.format(field.placeholder, field.cardinality, field.name))
html.append('</div>')
html.append('</div>')
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"

Expand Down Expand Up @@ -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)

Expand Down
25 changes: 17 additions & 8 deletions simplestore/lib/simplestore_model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ 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)

licence = db.Column(db.String(128)) # note we set licences in __init__
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
alternate_identifier = db.Column(db.String(256))
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']

Expand Down Expand Up @@ -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'] = {
Expand All @@ -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 ' +\
Expand 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.'
}
Expand Down Expand Up @@ -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)

0 comments on commit c2767f7

Please sign in to comment.