aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/metadata_edits.py109
-rw-r--r--wqflask/wqflask/templates/edit_history.html67
-rw-r--r--wqflask/wqflask/templates/edit_phenotype.html1
3 files changed, 129 insertions, 48 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 10022ae1..00e289eb 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -96,55 +96,18 @@ def edit_phenotype(conn, name, dataset_id):
table="PublishXRef",
where=PublishXRef(id_=name, inbred_set_id=dataset_id),
)
- phenotype_ = fetchone(
- conn=conn,
- table="Phenotype",
- where=Phenotype(id_=publish_xref.phenotype_id),
- )
- publication_ = fetchone(
- conn=conn,
- table="Publication",
- where=Publication(id_=publish_xref.publication_id),
- )
- json_data = fetchall(
- conn,
- "metadata_audit",
- where=MetadataAudit(dataset_id=publish_xref.id_),
- )
- Edit = namedtuple("Edit", ["field", "old", "new", "diff"])
- Diff = namedtuple("Diff", ["author", "diff", "timestamp"])
- diff_data = []
- for data in json_data:
- json_ = json.loads(data.json_data)
- timestamp = json_.get("timestamp")
- author = json_.get("author")
- for key, value in json_.items():
- if isinstance(value, dict):
- for field, data_ in value.items():
- diff_data.append(
- Diff(
- author=author,
- diff=Edit(
- field,
- data_.get("old"),
- data_.get("new"),
- "\n".join(
- difflib.ndiff(
- [data_.get("old") or ""], [data_.get("new")]
- )
- ),
- ),
- timestamp=timestamp,
- )
- )
- diff_data_ = None
- if len(diff_data) > 0:
- diff_data_ = groupby(diff_data, lambda x: x.timestamp)
return {
- "diff": diff_data_,
"publish_xref": publish_xref,
- "phenotype": phenotype_,
- "publication": publication_,
+ "phenotype": fetchone(
+ conn=conn,
+ table="Phenotype",
+ where=Phenotype(id_=publish_xref.phenotype_id),
+ ),
+ "publication": fetchone(
+ conn=conn,
+ table="Publication",
+ where=Publication(id_=publish_xref.publication_id),
+ ),
}
@@ -201,11 +164,11 @@ def display_phenotype_metadata(dataset_id: str, name: str):
_d = edit_phenotype(conn=conn, name=name, dataset_id=dataset_id)
return render_template(
"edit_phenotype.html",
- diff=_d.get("diff"),
publish_xref=_d.get("publish_xref"),
phenotype=_d.get("phenotype"),
publication=_d.get("publication"),
dataset_id=dataset_id,
+ name=name,
resource_id=request.args.get("resource-id"),
headers=get_case_attributes(conn).keys(),
version=os.environ.get("GN_VERSION"),
@@ -567,6 +530,56 @@ def show_diff(name):
return render_template("display_diffs.html", diff=content)
+@metadata_edit.route("/<dataset_id>/traits/<name>/history")
+def show_history(dataset_id: str, name: str):
+ diff_data_ = None
+ with database_connection() as conn:
+ publish_xref = fetchone(
+ conn=conn,
+ table="PublishXRef",
+ where=PublishXRef(id_=name, inbred_set_id=dataset_id))
+
+ json_data = fetchall(
+ conn,
+ "metadata_audit",
+ where=MetadataAudit(dataset_id=publish_xref.id_),
+ )
+
+ Edit = namedtuple("Edit", ["field", "old", "new", "diff"])
+ Diff = namedtuple("Diff", ["author", "diff", "timestamp"])
+ diff_data = []
+ for data in json_data:
+ json_ = json.loads(data.json_data)
+ timestamp = json_.get("timestamp")
+ author = json_.get("author")
+ for key, value in json_.items():
+ if isinstance(value, dict):
+ for field, data_ in value.items():
+ diff_data.append(
+ Diff(
+ author=author,
+ diff=Edit(
+ field,
+ data_.get("old"),
+ data_.get("new"),
+ "\n".join(
+ difflib.ndiff(
+ [data_.get("old") or ""],
+ [data_.get("new")]
+ )
+ ),
+ ),
+ timestamp=timestamp,
+ )
+ )
+ if len(diff_data) > 0:
+ diff_data_ = groupby(diff_data, lambda x: x.timestamp)
+ return render_template(
+ "edit_history.html",
+ diff=diff_data_,
+ version=os.environ.get("GN_VERSION"))
+
+
@metadata_edit.route("<resource_id>/diffs/<file_name>/reject")
@edit_admins_access_required
@login_required
diff --git a/wqflask/wqflask/templates/edit_history.html b/wqflask/wqflask/templates/edit_history.html
new file mode 100644
index 00000000..f181fd87
--- /dev/null
+++ b/wqflask/wqflask/templates/edit_history.html
@@ -0,0 +1,67 @@
+{% extends "base.html" %}
+{% block title %}Trait Submission{% endblock %}
+
+{% block css %}
+<link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='DataTables/css/jquery.dataTables.css') }}" />
+{% endblock %}
+
+{% block content %}
+<!-- Start of body -->
+<div class="container">
+
+ <h1>Edit history: {{}}</h1>
+ {% if diff %}
+ <div class="row">
+ <table id="history" class="table-responsive table-hover table-striped cell-border">
+ <tbody>
+ <tr>
+ <th>Timestamp</th>
+ <th>Editor</th>
+ <th>Field</th>
+ <th>Diff</th>
+ </tr>
+ {% set ns = namespace(display_cell=True) %}
+
+ {% for timestamp, group in diff %}
+ {% set ns.display_cell = True %}
+ {% for i in group %}
+ <tr>
+ {% if ns.display_cell and i.timestamp == timestamp %}
+
+ {% set author = i.author %}
+ {% set timestamp_ = i.timestamp %}
+
+ {% else %}
+
+ {% set author = "" %}
+ {% set timestamp_ = "" %}
+
+ {% endif %}
+ <td>{{ timestamp_ }}</td>
+ <td>{{ author }}</td>
+ <td>{{ i.diff.field }}</td>
+ <td><pre>{{ i.diff.diff }}</pre></td>
+ {% set ns.display_cell = False %}
+ </tr>
+ {% endfor %}
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+
+ {% endif %}
+
+</div>
+{%endblock%}
+
+{% block js %}
+<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.js') }}"></script>
+<script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.dataTables.min.js') }}"></script>
+<script language="javascript" type="text/javascript">
+ gn_server_url = "{{ gn_server_url }}";
+
+ $(document).ready( function() {
+ $('#history').dataTable();
+ });
+</script>
+{% endblock %}
diff --git a/wqflask/wqflask/templates/edit_phenotype.html b/wqflask/wqflask/templates/edit_phenotype.html
index e7a44bd9..3c4bbf71 100644
--- a/wqflask/wqflask/templates/edit_phenotype.html
+++ b/wqflask/wqflask/templates/edit_phenotype.html
@@ -14,6 +14,7 @@
<div class="container">
<div class="page-header text-left">
<h1>Trait Metadata and Data Editing Form</h1>
+ <small><a href="{{url_for('metadata_edit.show_history', dataset_id=dataset_id, name=name)}}" target="_blank">[View History]</a></small>
</div>
{% if diff %}