diff options
author | BonfaceKilz | 2021-06-07 18:37:59 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-06-07 18:43:44 +0300 |
commit | d8fa6d066d9c37d65bf6e3388b5bb9583b6a9436 (patch) | |
tree | 8bb28d463a6438269dc9e6b7d7267b5b437ffc5f /wqflask | |
parent | bc0871f1e37b1483dd820df50e77afde1449934c (diff) | |
download | genenetwork2-d8fa6d066d9c37d65bf6e3388b5bb9583b6a9436.tar.gz |
wqflask: views: Pass diffs to template for further processing
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/views.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 933dc507..ebe5303a 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -4,9 +4,11 @@ import MySQLdb import array import base64 import csv +import difflib import datetime import flask import io # Todo: Use cStringIO? + import json import numpy as np import os @@ -18,12 +20,15 @@ import traceback import uuid import xlsxwriter +from itertools import groupby +from collections import namedtuple from zipfile import ZipFile from zipfile import ZIP_DEFLATED from wqflask import app from gn3.db import diff_from_dict +from gn3.db import fetchall from gn3.db import fetchone from gn3.db import insert from gn3.db import update @@ -449,12 +454,41 @@ def edit_trait(name, inbred_set_id): 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")], + [data_.get("new")]))), + timestamp=timestamp)) + diff_data_ = None + if len(diff_data) > 0: + diff_data_ = groupby(diff_data, lambda x: x.timestamp) return render_template( "edit_trait.html", + diff=diff_data_, publish_xref=publish_xref, phenotype=phenotype_, publication=publication_, - version=GN_VERSION) + version=GN_VERSION, + ) @app.route("/trait/update", methods=["POST"]) |