get_parent_pksk_from_path utils function
This commit is contained in:
parent
4f14965ba1
commit
010d54bc87
3 changed files with 18 additions and 15 deletions
1
utils/__init__.py
Normal file
1
utils/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .get_parent_pksk_from_path import get_parent_pksk_from_path
|
||||
14
utils/get_parent_pksk_from_path.py
Normal file
14
utils/get_parent_pksk_from_path.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def get_parent_pksk_from_path(parent_path):
|
||||
if parent_path == '/':
|
||||
return 'maintrunk#maintrunk'
|
||||
|
||||
entity, slug = parent_path.strip('/').split('/')
|
||||
if entity == 'branch':
|
||||
entity = 'subwiki'
|
||||
elif entity != 'user':
|
||||
entity = 'userprofile'
|
||||
|
||||
if entity not in ['userprofile', 'subwiki']:
|
||||
raise ValueError(f"Invalid parent entity: {entity}. Must be 'userprofile' or 'branch'.")
|
||||
|
||||
return f"{entity}#{slug}"
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
from utils.get_parent_pksk_from_path import get_parent_pksk_from_path
|
||||
|
||||
def create_post(post_text, parent_path='/', blur_label=None, card_url=None, collaborative=False):
|
||||
"""
|
||||
Creates a new post.
|
||||
|
|
@ -14,21 +16,7 @@ def create_post(post_text, parent_path='/', blur_label=None, card_url=None, coll
|
|||
that will be processed by the API client wrapper function.
|
||||
"""
|
||||
|
||||
parent_pksk = None
|
||||
|
||||
if parent_path == '/':
|
||||
parent_pksk = 'maintrunk#maintrunk'
|
||||
else:
|
||||
parent_path = parent_path.strip('/')
|
||||
entity, slug = parent_path.split('/')
|
||||
if entity == 'branch':
|
||||
entity = 'subwiki'
|
||||
|
||||
if entity not in ['userprofile', 'subwiki']:
|
||||
raise ValueError(f"Invalid parent entity: {entity}. Must be 'userprofile' or 'branch'.")
|
||||
|
||||
parent_pksk = f"{entity}#{slug}"
|
||||
|
||||
parent_pksk = get_parent_pksk_from_path(parent_path)
|
||||
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue