about summary refs log tree commit diff
path: root/uploader/population/models.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-13 14:30:27 -0500
committerFrederick Muriuki Muriithi2024-09-13 14:30:27 -0500
commit1ff6fb43ceb22f55b94f15a6d875cdadd9d70244 (patch)
treecbdf4b3cca6175b9e0bc75d28ace798c1d54461d /uploader/population/models.py
parent319d4bf99a67aa7183c5cf5ee4f60e56a558d624 (diff)
downloadgn-uploader-1ff6fb43ceb22f55b94f15a6d875cdadd9d70244.tar.gz
Populations: Hook population creation to auth system.
Diffstat (limited to 'uploader/population/models.py')
-rw-r--r--uploader/population/models.py57
1 files changed, 28 insertions, 29 deletions
diff --git a/uploader/population/models.py b/uploader/population/models.py
index 782bc9f..c6c77ae 100644
--- a/uploader/population/models.py
+++ b/uploader/population/models.py
@@ -44,33 +44,32 @@ def population_genetic_types(conn) -> tuple:
         return tuple(row["GeneticType"] for row in cursor.fetchall())
 
 
-def save_population(conn: mdb.Connection, population_details: dict) -> dict:
+def save_population(cursor: mdb.cursors.Cursor, population_details: dict) -> dict:
     """Save the population details to the db."""
-    with conn.cursor(cursorclass=DictCursor) as cursor:
-        #TODO: Handle FamilyOrder here
-        cursor.execute(
-            "INSERT INTO InbredSet("
-            "InbredSetId, InbredSetName, Name, SpeciesId, FullName, "
-            "public, MappingMethodId, GeneticType, Family, MenuOrderId, "
-            "InbredSetCode, Description"
-            ") "
-            "VALUES ("
-            "%(InbredSetId)s, %(InbredSetName)s, %(Name)s, %(SpeciesId)s, "
-            "%(FullName)s, %(public)s, %(MappingMethodId)s, %(GeneticType)s, "
-            "%(Family)s, %(MenuOrderId)s, %(InbredSetCode)s, %(Description)s"
-            ")",
-            {
-                "MenuOrderId": 0,
-                "InbredSetId": 0,
-                "public": 2,
-                **population_details
-            })
-        new_id = cursor.lastrowid
-        cursor.execute("UPDATE InbredSet SET InbredSetId=%s WHERE Id=%s",
-                       (new_id, new_id))
-        return {
-            **population_details,
-            "Id": new_id,
-            "InbredSetId": new_id,
-            "population_id": new_id
-        }
+    #TODO: Handle FamilyOrder here
+    cursor.execute(
+        "INSERT INTO InbredSet("
+        "InbredSetId, InbredSetName, Name, SpeciesId, FullName, "
+        "public, MappingMethodId, GeneticType, Family, MenuOrderId, "
+        "InbredSetCode, Description"
+        ") "
+        "VALUES ("
+        "%(InbredSetId)s, %(InbredSetName)s, %(Name)s, %(SpeciesId)s, "
+        "%(FullName)s, %(public)s, %(MappingMethodId)s, %(GeneticType)s, "
+        "%(Family)s, %(MenuOrderId)s, %(InbredSetCode)s, %(Description)s"
+        ")",
+        {
+            "MenuOrderId": 0,
+            "InbredSetId": 0,
+            "public": 2,
+            **population_details
+        })
+    new_id = cursor.lastrowid
+    cursor.execute("UPDATE InbredSet SET InbredSetId=%s WHERE Id=%s",
+                   (new_id, new_id))
+    return {
+        **population_details,
+        "Id": new_id,
+        "InbredSetId": new_id,
+        "population_id": new_id
+    }