Skip to content

Commit 2de14c5

Browse files
committed
Clean up
1 parent 471024c commit 2de14c5

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

main.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TypedDict, Literal, Optional, Dict, List, Callable
66

77
from session import Session, extract_id_from_uri, construct_api_link
8-
from taxon_helpers import TAXON_TABLE_ID, RANK_NAME, Discipline_Record, Taxon_Record, TaxonTreeDefItem_Record, get_defitem, get_taxon, update_author
8+
from taxon_helpers import TAXON_TABLE_ID, RANK_NAME, Discipline_Record, Taxon_Record, TaxonTreeDefItem_Record, get_defitem, get_taxon, update_author, create_accepted_taxon
99

1010
LOG_FILE_NAME = "importlog.txt"
1111

@@ -140,24 +140,6 @@ def proccess_row(session: Session, row: Row) -> int:
140140
return taxon['id']
141141

142142

143-
def create_accepted_taxon(session: Session, def_item: TaxonTreeDefItem_Record, name: str, parent: Taxon_Record, author: Optional[str] = None) -> Taxon_Record:
144-
taxon_data = {
145-
# fullname generated by backend when saved
146-
"name": name,
147-
"author": author,
148-
"isaccepted": True,
149-
"ishybrid": False,
150-
"rankid": def_item["rankid"],
151-
"version": 0,
152-
"remarks": "Generated in Demo",
153-
"definition": def_item["treedef"],
154-
"definitionitem": def_item["resource_uri"],
155-
"parent": parent["resource_uri"]
156-
}
157-
new_taxon = session.create_resource('taxon', taxon_data)
158-
return new_taxon
159-
160-
161143
@tree_info_fetched
162144
def get_accepted(session: Session, row: Row) -> Optional[str]:
163145
"""Return the resource_uri for the accepted taxon

session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def construct_api_link(table: str, id: int):
6161

6262
def ensure_login(func):
6363
"""Decorator which ensures a function which accepts a Session as the first
64-
parameter is logged in before the fucntion is called
64+
parameter is logged in before the function is called
6565
"""
6666
@wraps(func)
6767
def wrapped(session: "Session", *args: Tuple, **kwargs: Dict[str, Any]):

taxon_helpers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ def get_taxon(session: Session, name: str, tree_def_item_id: int, parent_name: O
5151
return taxons[0]
5252

5353

54+
def create_accepted_taxon(session: Session, def_item: TaxonTreeDefItem_Record, name: str, parent: Taxon_Record, author: Optional[str] = None) -> Taxon_Record:
55+
"""Creates a new Taxon record with taxontreedefitem <def_item>, name <name>, parent <parent>, and author <author>
56+
"""
57+
taxon_data = {
58+
# fullname generated by backend when saved
59+
"name": name,
60+
"author": author,
61+
"isaccepted": True,
62+
"ishybrid": False,
63+
"rankid": def_item["rankid"],
64+
"version": 0,
65+
"remarks": "Generated in Demo",
66+
"definition": def_item["treedef"],
67+
"definitionitem": def_item["resource_uri"],
68+
"parent": parent["resource_uri"]
69+
}
70+
new_taxon = session.create_resource('taxon', taxon_data)
71+
return new_taxon
72+
73+
5474
def update_author(session: Session, taxon: Taxon_Record, author: str) -> Taxon_Record:
5575
"""Given a serialized Taxon record <taxon>, and a string representing an
5676
author, update the <taxon> record to have author <author>

0 commit comments

Comments
 (0)