mirror of https://gitlab.com/bashrc2/epicyon
Move occupation functions to a separate module
parent
fd7300b657
commit
4f7e589a4a
|
@ -17,10 +17,10 @@ from status import actor_status_expired
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
from utils import get_json_content_from_accept
|
from utils import get_json_content_from_accept
|
||||||
from utils import get_occupation_skills
|
|
||||||
from utils import get_instance_url
|
from utils import get_instance_url
|
||||||
from utils import acct_dir
|
from utils import acct_dir
|
||||||
from utils import convert_domains
|
from utils import convert_domains
|
||||||
|
from occupation import get_occupation_skills
|
||||||
from httpcodes import write2
|
from httpcodes import write2
|
||||||
from httpcodes import http_404
|
from httpcodes import http_404
|
||||||
from person import person_lookup
|
from person import person_lookup
|
||||||
|
|
|
@ -42,7 +42,7 @@ from utils import acct_dir
|
||||||
from utils import get_config_param
|
from utils import get_config_param
|
||||||
from utils import get_instance_url
|
from utils import get_instance_url
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
from utils import get_occupation_name
|
from occupation import get_occupation_name
|
||||||
from auth import store_basic_credentials
|
from auth import store_basic_credentials
|
||||||
from filters import is_filtered
|
from filters import is_filtered
|
||||||
from content import add_name_emojis_to_tags
|
from content import add_name_emojis_to_tags
|
||||||
|
@ -103,7 +103,7 @@ from matrix import get_matrix_address
|
||||||
from matrix import set_matrix_address
|
from matrix import set_matrix_address
|
||||||
from ssb import get_ssb_address
|
from ssb import get_ssb_address
|
||||||
from ssb import set_ssb_address
|
from ssb import set_ssb_address
|
||||||
from utils import set_occupation_name
|
from occupation import set_occupation_name
|
||||||
from blog import get_blog_address
|
from blog import get_blog_address
|
||||||
from webapp_utils import set_blog_address
|
from webapp_utils import set_blog_address
|
||||||
from session import site_is_verified
|
from session import site_is_verified
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
__filename__ = "occupation.py"
|
||||||
|
__author__ = "Bob Mottram"
|
||||||
|
__license__ = "AGPL3+"
|
||||||
|
__version__ = "1.6.0"
|
||||||
|
__maintainer__ = "Bob Mottram"
|
||||||
|
__email__ = "bob@libreserver.org"
|
||||||
|
__status__ = "Production"
|
||||||
|
__module_group__ = "Core"
|
||||||
|
|
||||||
|
|
||||||
|
def get_occupation_skills(actor_json: {}) -> []:
|
||||||
|
"""Returns the list of skills for an actor
|
||||||
|
"""
|
||||||
|
if 'hasOccupation' not in actor_json:
|
||||||
|
return []
|
||||||
|
if not isinstance(actor_json['hasOccupation'], list):
|
||||||
|
return []
|
||||||
|
for occupation_item in actor_json['hasOccupation']:
|
||||||
|
if not isinstance(occupation_item, dict):
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('@type'):
|
||||||
|
continue
|
||||||
|
if not occupation_item['@type'] == 'Occupation':
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('skills'):
|
||||||
|
continue
|
||||||
|
if isinstance(occupation_item['skills'], list):
|
||||||
|
return occupation_item['skills']
|
||||||
|
if isinstance(occupation_item['skills'], str):
|
||||||
|
return [occupation_item['skills']]
|
||||||
|
break
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def get_occupation_name(actor_json: {}) -> str:
|
||||||
|
"""Returns the occupation name an actor
|
||||||
|
"""
|
||||||
|
if not actor_json.get('hasOccupation'):
|
||||||
|
return ""
|
||||||
|
if not isinstance(actor_json['hasOccupation'], list):
|
||||||
|
return ""
|
||||||
|
for occupation_item in actor_json['hasOccupation']:
|
||||||
|
if not isinstance(occupation_item, dict):
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('@type'):
|
||||||
|
continue
|
||||||
|
if occupation_item['@type'] != 'Occupation':
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('name'):
|
||||||
|
continue
|
||||||
|
if isinstance(occupation_item['name'], str):
|
||||||
|
return occupation_item['name']
|
||||||
|
break
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def set_occupation_name(actor_json: {}, name: str) -> bool:
|
||||||
|
"""Sets the occupation name of an actor
|
||||||
|
"""
|
||||||
|
if not actor_json.get('hasOccupation'):
|
||||||
|
return False
|
||||||
|
if not isinstance(actor_json['hasOccupation'], list):
|
||||||
|
return False
|
||||||
|
for index, _ in enumerate(actor_json['hasOccupation']):
|
||||||
|
occupation_item = actor_json['hasOccupation'][index]
|
||||||
|
if not isinstance(occupation_item, dict):
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('@type'):
|
||||||
|
continue
|
||||||
|
if occupation_item['@type'] != 'Occupation':
|
||||||
|
continue
|
||||||
|
occupation_item['name'] = name
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def set_occupation_skills_list(actor_json: {}, skills_list: []) -> bool:
|
||||||
|
"""Sets the occupation skills for an actor
|
||||||
|
"""
|
||||||
|
if 'hasOccupation' not in actor_json:
|
||||||
|
return False
|
||||||
|
if not isinstance(actor_json['hasOccupation'], list):
|
||||||
|
return False
|
||||||
|
for index, _ in enumerate(actor_json['hasOccupation']):
|
||||||
|
occupation_item = actor_json['hasOccupation'][index]
|
||||||
|
if not isinstance(occupation_item, dict):
|
||||||
|
continue
|
||||||
|
if not occupation_item.get('@type'):
|
||||||
|
continue
|
||||||
|
if occupation_item['@type'] != 'Occupation':
|
||||||
|
continue
|
||||||
|
occupation_item['skills'] = skills_list
|
||||||
|
return True
|
||||||
|
return False
|
2
pgp.py
2
pgp.py
|
@ -14,7 +14,7 @@ from pathlib import Path
|
||||||
from person import get_actor_json
|
from person import get_actor_json
|
||||||
from flags import is_pgp_encrypted
|
from flags import is_pgp_encrypted
|
||||||
from flags import contains_pgp_public_key
|
from flags import contains_pgp_public_key
|
||||||
from utils import get_occupation_skills
|
from occupation import get_occupation_skills
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import safe_system_string
|
from utils import safe_system_string
|
||||||
from utils import get_full_domain
|
from utils import get_full_domain
|
||||||
|
|
|
@ -12,13 +12,13 @@ from webfinger import webfinger_handle
|
||||||
from auth import create_basic_auth_header
|
from auth import create_basic_auth_header
|
||||||
from posts import get_person_box
|
from posts import get_person_box
|
||||||
from session import post_json
|
from session import post_json
|
||||||
|
from occupation import get_occupation_skills
|
||||||
|
from occupation import set_occupation_skills_list
|
||||||
from utils import has_object_string
|
from utils import has_object_string
|
||||||
from utils import get_full_domain
|
from utils import get_full_domain
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
from utils import get_domain_from_actor
|
from utils import get_domain_from_actor
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
from utils import get_occupation_skills
|
|
||||||
from utils import set_occupation_skills_list
|
|
||||||
from utils import acct_dir
|
from utils import acct_dir
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
from utils import has_actor
|
from utils import has_actor
|
||||||
|
|
86
utils.py
86
utils.py
|
@ -2773,92 +2773,6 @@ def dm_allowed_from_domain(base_dir: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_occupation_skills(actor_json: {}) -> []:
|
|
||||||
"""Returns the list of skills for an actor
|
|
||||||
"""
|
|
||||||
if 'hasOccupation' not in actor_json:
|
|
||||||
return []
|
|
||||||
if not isinstance(actor_json['hasOccupation'], list):
|
|
||||||
return []
|
|
||||||
for occupation_item in actor_json['hasOccupation']:
|
|
||||||
if not isinstance(occupation_item, dict):
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('@type'):
|
|
||||||
continue
|
|
||||||
if not occupation_item['@type'] == 'Occupation':
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('skills'):
|
|
||||||
continue
|
|
||||||
if isinstance(occupation_item['skills'], list):
|
|
||||||
return occupation_item['skills']
|
|
||||||
if isinstance(occupation_item['skills'], str):
|
|
||||||
return [occupation_item['skills']]
|
|
||||||
break
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def get_occupation_name(actor_json: {}) -> str:
|
|
||||||
"""Returns the occupation name an actor
|
|
||||||
"""
|
|
||||||
if not actor_json.get('hasOccupation'):
|
|
||||||
return ""
|
|
||||||
if not isinstance(actor_json['hasOccupation'], list):
|
|
||||||
return ""
|
|
||||||
for occupation_item in actor_json['hasOccupation']:
|
|
||||||
if not isinstance(occupation_item, dict):
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('@type'):
|
|
||||||
continue
|
|
||||||
if occupation_item['@type'] != 'Occupation':
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('name'):
|
|
||||||
continue
|
|
||||||
if isinstance(occupation_item['name'], str):
|
|
||||||
return occupation_item['name']
|
|
||||||
break
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def set_occupation_name(actor_json: {}, name: str) -> bool:
|
|
||||||
"""Sets the occupation name of an actor
|
|
||||||
"""
|
|
||||||
if not actor_json.get('hasOccupation'):
|
|
||||||
return False
|
|
||||||
if not isinstance(actor_json['hasOccupation'], list):
|
|
||||||
return False
|
|
||||||
for index, _ in enumerate(actor_json['hasOccupation']):
|
|
||||||
occupation_item = actor_json['hasOccupation'][index]
|
|
||||||
if not isinstance(occupation_item, dict):
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('@type'):
|
|
||||||
continue
|
|
||||||
if occupation_item['@type'] != 'Occupation':
|
|
||||||
continue
|
|
||||||
occupation_item['name'] = name
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def set_occupation_skills_list(actor_json: {}, skills_list: []) -> bool:
|
|
||||||
"""Sets the occupation skills for an actor
|
|
||||||
"""
|
|
||||||
if 'hasOccupation' not in actor_json:
|
|
||||||
return False
|
|
||||||
if not isinstance(actor_json['hasOccupation'], list):
|
|
||||||
return False
|
|
||||||
for index, _ in enumerate(actor_json['hasOccupation']):
|
|
||||||
occupation_item = actor_json['hasOccupation'][index]
|
|
||||||
if not isinstance(occupation_item, dict):
|
|
||||||
continue
|
|
||||||
if not occupation_item.get('@type'):
|
|
||||||
continue
|
|
||||||
if occupation_item['@type'] != 'Occupation':
|
|
||||||
continue
|
|
||||||
occupation_item['skills'] = skills_list
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def permitted_dir(path: str) -> bool:
|
def permitted_dir(path: str) -> bool:
|
||||||
"""These are special paths which should not be accessible
|
"""These are special paths which should not be accessible
|
||||||
directly via GET or POST
|
directly via GET or POST
|
||||||
|
|
|
@ -21,6 +21,7 @@ from status import get_actor_status
|
||||||
from textmode import text_mode_removals
|
from textmode import text_mode_removals
|
||||||
from unicodetext import uninvert_text
|
from unicodetext import uninvert_text
|
||||||
from unicodetext import standardize_text
|
from unicodetext import standardize_text
|
||||||
|
from occupation import get_occupation_name
|
||||||
from utils import get_person_icon
|
from utils import get_person_icon
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
|
@ -33,7 +34,6 @@ from utils import ap_proxy_type
|
||||||
from utils import remove_id_ending
|
from utils import remove_id_ending
|
||||||
from utils import get_display_name
|
from utils import get_display_name
|
||||||
from utils import has_object_dict
|
from utils import has_object_dict
|
||||||
from utils import get_occupation_name
|
|
||||||
from utils import get_locked_account
|
from utils import get_locked_account
|
||||||
from utils import get_full_domain
|
from utils import get_full_domain
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
|
|
Loading…
Reference in New Issue