aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-09-17 19:37:09 +0300
committerJohn Nduli Kilyungi2024-09-18 08:32:34 +0300
commit32be08bebb6d43c6e446dec12526cd912727c6fb (patch)
tree82788005b66fc8d58d65d2e2b51dbbde7a7f3d36
parent1a289eca7d770487d3f87c612a3c76e7fd247f6e (diff)
downloadgenenetwork3-32be08bebb6d43c6e446dec12526cd912727c6fb.tar.gz
Pass in the createtime as an arg when inserting into RDF graph.
* gn3/api/metadata_api/wiki.py (edit_wiki): Pass in the createtime as an arg. * gn3/db/rdf/wiki.py: Remove un-used imports. (update_wiki_comment): Use passed in "created" arg in the createtime field. This makes sure that the SQL/RDF timestamps match. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/metadata_api/wiki.py9
-rw-r--r--gn3/db/rdf/wiki.py7
2 files changed, 7 insertions, 9 deletions
diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py
index bb7d2d2..8aa0b37 100644
--- a/gn3/api/metadata_api/wiki.py
+++ b/gn3/api/metadata_api/wiki.py
@@ -25,16 +25,16 @@ def edit_wiki(comment_id: int):
# FIXME: attempt to check and fix for types here with relevant errors
payload: Dict[str, Any] = request.json # type: ignore
pubmed_ids = [str(x) for x in payload.get("pubmed_ids", [])]
-
+ created = datetime.datetime.now(datetime.timezone.utc).strftime(
+ "%Y-%m-%d %H:%M:%S"
+ )
insert_dict = {
"Id": comment_id,
"symbol": payload["symbol"],
"PubMed_ID": " ".join(pubmed_ids),
"comment": payload["comment"],
"email": payload["email"],
- "createtime": datetime.datetime.now(datetime.timezone.utc).strftime(
- "%Y-%m-%d %H:%M"
- ),
+ "createtime": created,
"user_ip": request.environ.get("HTTP_X_REAL_IP", request.remote_addr),
"weburl": payload.get("web_url"),
"initial": payload.get("initial"),
@@ -78,6 +78,7 @@ def edit_wiki(comment_id: int):
comment_id=comment_id,
payload=payload,
next_version=next_version,
+ created=created,
sparql_conf={
"sparql_user": current_app.config["SPARQL_USER"],
"sparql_password": current_app.config["SPARQL_PASSWORD"],
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index 55f4162..f19670a 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -9,17 +9,13 @@ NOTE: In the CONSTRUCT queries below, we manually sort the arrays from
<https://stackoverflow.com/questions/78186393>
<https://www.w3.org/TR/rdf-sparql-query/#modOrderBy>
"""
-import datetime
-
from string import Template
from gn3.db.rdf import (
BASE_CONTEXT,
RDF_PREFIXES,
query_frame_and_compact,
- sparql_query,
update_rdf,
)
-from gn3.db.wiki import MissingDBDataException
WIKI_CONTEXT = BASE_CONTEXT | {
@@ -192,6 +188,7 @@ CONSTRUCT {
def update_wiki_comment(
comment_id: int,
payload: dict,
+ created: str,
next_version: int,
sparql_conf: dict,
graph: str = "<http://genenetwork.org>",
@@ -234,7 +231,7 @@ dct:created "$created"^^xsd:datetime .
comment=payload["comment"],
name=name, symbol=payload['symbol'],
comment_id=comment_id, next_version=next_version,
- created=datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S'))
+ created=created)
using = ""
if payload["email"]:
comment_triple += f"{name} foaf:mbox <{payload['email']}> .\n"