Skip to content

Commit

Permalink
global: fixes to record versioning on new ES and to sandbox
Browse files Browse the repository at this point in the history
* FIX Fixes addition of new record version. ElasticSearch upgrade requires the specification of the parent.
* FIX Allows for deletion of sandbox items by users.
* FIX Simplifies date output for sandbox items.

Signed-off-by: Eamonn Maguire <eamonnmag@gmail.com>
  • Loading branch information
eamonnmag committed Apr 21, 2016
1 parent c86104c commit 240dd24
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 37 deletions.
7 changes: 5 additions & 2 deletions hepdata/ext/elasticsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,18 @@ def get_records_matching_field(field, id, index=None, doc_type=None):


@default_index
def delete_item_from_index(id, index, doc_type):
def delete_item_from_index(id, index, doc_type, parent=None):
"""
Given an id, deletes an item from the index.
:param id:
:param index:
:param doc_type:
:return:
"""
es.delete(index=index, doc_type=doc_type, id=id)
if parent:
es.delete(index=index, doc_type=doc_type, id=id, parent=parent)
else:
es.delete(index=index, doc_type=doc_type, id=id)


@default_index
Expand Down
5 changes: 5 additions & 0 deletions hepdata/modules/converter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def download_submission(recid, version, file_format):
if version > submission.latest_version or version == -1:
version = submission.latest_version

if version == 0:
version += 1

path = os.path.join(current_app.config['CFG_DATADIR'], str(recid))
data_filename = SUBMISSION_FILE_NAME_PATTERN.format(recid, version)

Expand All @@ -140,6 +143,8 @@ def download_submission(recid, version, file_format):
}

data_filepath = os.path.join(path, data_filename)


converted_file = convert_zip_archive(data_filepath,
output_path,
converter_options)
Expand Down
22 changes: 17 additions & 5 deletions hepdata/modules/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def stats():
ctx = {'user_is_admin': has_role(current_user, 'admin'), 'user_profile': user_profile}

records_summary = db.session.query(func.sum(DailyAccessStatistic.count),
DailyAccessStatistic.publication_recid,
DailyAccessStatistic.day).group_by(
DailyAccessStatistic.publication_recid,
DailyAccessStatistic.day).group_by(
DailyAccessStatistic.publication_recid, DailyAccessStatistic.day).order_by().limit(1000).all()

record_overview = {}
Expand All @@ -319,7 +319,7 @@ def stats():
except NotFoundError:
# skip this record. Was probably accessed then deleted.
continue
record_overview[record[1]] = {"title": title,"recid": record[1], "count": 0, "accesses": []}
record_overview[record[1]] = {"title": title, "recid": record[1], "count": 0, "accesses": []}

record_overview[record[1]]['count'] += record[0]
record_overview[record[1]]["accesses"].append({"day": record[2].strftime("%Y-%m-%d"), "count": record[0]})
Expand Down Expand Up @@ -435,6 +435,16 @@ def assign_role(cookie):
return redirect(url_for('.dashboard'))


def check_is_sandbox_record(recid):
try:
submission = HEPSubmission.query.filter_by(publication_recid=recid).first()
print(submission.overall_status)
return submission.overall_status == 'sandbox'
except Exception as e:
print(e)
return False


@blueprint.route('/delete/<int:recid>')
@login_required
def delete_submission(recid):
Expand All @@ -444,7 +454,9 @@ def delete_submission(recid):
:param recid:
:return:
"""
if has_role(current_user, 'admin') or has_role(current_user, 'coordinator'):
print('Is sandbox {0} == {1} '.format(recid, check_is_sandbox_record(recid)))
if has_role(current_user, 'admin') or has_role(current_user, 'coordinator') \
or check_is_sandbox_record(recid):
unload_submission(recid)
return json.dumps({"success": True,
"recid": recid,
Expand Down Expand Up @@ -524,7 +536,7 @@ def do_finalise(recid, publication_record=None, force_finalise=False,
existing_submissions[record["_source"]["title"]] = \
record["_source"]["recid"]
delete_item_from_index(record["_id"],
doc_type=CFG_DATA_TYPE)
doc_type=CFG_DATA_TYPE, parent=record["_source"]["related_publication"])

current_time = "{:%Y-%m-%d %H:%M:%S}".format(datetime.now())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
<div id="hepdata_tables">
<div align="center">

{% if ctx.show_upload_widget and ctx.status != 'finished' %}
<button type="button" class="btn btn-success btn-md" data-toggle="modal" style="width: 100%" data-target="#uploadDialog"><span
{% if ctx.show_upload_widget and ctx.status != 'finished' %}
<button type="button" class="btn btn-success btn-md" data-toggle="modal" style="width: 100%"
data-target="#uploadDialog"><span
class="fa fa-upload"></span> Upload New Files
</button>
{% endif %}


{% if ctx.status == 'finished' and (ctx.is_submission_coordinator_or_admin or ctx.show_upload_widget) %}
<button type="button" class="btn btn-danger btn-md" data-toggle="modal" style="width: 100%" data-target="#uploadDialog"><span
class="fa fa-upload" ></span> Revise Submission
<button type="button" class="btn btn-danger btn-md" data-toggle="modal" style="width: 100%"
data-target="#uploadDialog"><span
class="fa fa-upload"></span> Revise Submission
</button>
{% endif %}


<div class="dropdown">
<button id="dLabel" type="button"
class="btn btn-md btn-primary"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" style="width: 100%">
<i class="fa fa-download"></i> Download All
<span class="caret"></span>
</button>
{% set download_base_url = "/download/submission/" + ctx.record.recid|string + "/" +
{% if ctx.mode != 'sandbox' %}
<div class="dropdown">
<button id="dLabel" type="button"
class="btn btn-md btn-primary"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" style="width: 100%">
<i class="fa fa-download"></i> Download All
<span class="caret"></span>
</button>
{% set download_base_url = "/download/submission/" + ctx.record.recid|string + "/" +
ctx.version|string %}
<ul class="dropdown-menu" aria-labelledby="dLabel"
style="height: auto;">

<li><a href="{{ download_base_url }}/yaml"
id="download_yaml">YAML</a></li>
<li><a href="{{ download_base_url }}/yoda"
id="download_yoda">YODA</a></li>
<li><a href="{{ download_base_url }}/root"
id="download_root">ROOT</a></li>
<li><a href="{{ download_base_url }}/csv"
id="download_csv">CSV</a></li>
</ul>
</div>
<ul class="dropdown-menu" aria-labelledby="dLabel"
style="height: auto;">

<li><a href="{{ download_base_url }}/yaml"
id="download_yaml">YAML</a></li>
<li><a href="{{ download_base_url }}/yoda"
id="download_yoda">YODA</a></li>
<li><a href="{{ download_base_url }}/root"
id="download_root">ROOT</a></li>
<li><a href="{{ download_base_url }}/csv"
id="download_csv">CSV</a></li>
</ul>
</div>
{% endif %}

{% if ctx.version_count and ctx.version_count > 1 %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
</li>
</a>

{% if ctx.data_tables|length != 0 %}
{% if ctx.data_tables|length != 0%}
<li class="pull-right">


<div class="dropdown"
style="float: right; margin-left: 15px; margin-top: -4px;">
<button id="dLabel" type="button"
Expand Down Expand Up @@ -119,7 +120,7 @@ <h4 style="font-size: 1em">
style="text-align: left">
<div class="truncated-record-abstract">{{ submission.data_abstract }}</div>
</a>
<p style="font-weight: bolder; color: #a1aec7; font-size: .7em; text-align: left">{{ submission.created }}</p>
<p style="font-weight: bolder; color: #a1aec7; font-size: .7em; text-align: left">{{ submission.created.strftime('%Y-%m-%d %H:%M%p') }}</p>
</div>
<div class="col-md-3">
<button class="btn btn-sm btn-danger delete_button"
Expand Down
5 changes: 3 additions & 2 deletions hepdata/modules/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"todo": "to be reviewed"
}


@login_required
@blueprint.route('/sandbox/<int:id>', methods=['GET'])
def sandbox_display(id):
hepdata_submission = HEPSubmission.query.filter_by(
Expand Down Expand Up @@ -662,8 +662,9 @@ def consume_data_payload(recid):
return redirect('/record/' + str(recid))


@login_required

@blueprint.route('/sandbox', methods=['GET'])
@login_required
def sandbox():
current_id = current_user.get_id()
submissions = HEPSubmission.query.filter_by(coordinator=current_id,
Expand Down

0 comments on commit 240dd24

Please sign in to comment.